LoginSignup
4
0

Cloudflare のリソースをPulumi で管理するための初期設定

Last updated at Posted at 2021-12-06

はじめに

Cloudflare のリソースを Pulumi で管理したくなり、さっと対応したときのメモから この記事を作成しています。

Pulumi の project は作成済みであることを前提として記載します。
まだ、 project を作成していない方は以下記事や公式ドキュメントを参考に初期設定まで完了させてください。

Project に設定する

今回は、 TypeScript (yarn) を利用する環境なので以下コマンドを実行します。

yarn add @pulumi/cloudflare

Cloudflare のコンソール画面から API Token を発行し Pulumi の config に設定します

pulumi config set cloudflare:apiToken --secret YOUR_TOKEN

API Token の発行は以下 URL から行うことが出来ます。
Pulumi で Cloudflare をどこまで操作するかに応じて適切な権限をもった Token を発行してください。

ここまで設定は完了です。
今まで作成してきたリソースを取り込んで検証してみます

作成済みのリソースを読み込む

今回は、検診のため既に作成されている Zone 情報を取得し出力します。
Cloudflare の console から Zone 名と、 Zone ID を確認してください。
※ ID は xxxxx 文字に置換しています

index.ts
import * as pulumi from "@pulumi/pulumi"
import * as cloudflare from "@pulumi/cloudflare"

export const zoneMziyutCom = cloudflare.Zone.get('xxxxx', 'xxxxxxxxxxxxxxxxxx')

pulumi preview を実行し 指定した Zone 情報が取得できるか確認しましょう。
※ 情報は xxxxx 文字に置換しています

$ pulumi preview
Outputs:
  + zoneMziyutCom: {
      + id               : "xxxxxxxxxxxxxxxxxx"
      + jumpStart        : output<string>
      + meta             : {
          + phishing_detected : xxxxx
          + wildcard_proxiable: xxxxx
        }
      + nameServers      : [
      +     [0]: "xxxxx"
      +     [1]: "xxxxx"
        ]
      + paused           : xxxxx
      + plan             : "xxxxx"
      + status           : "xxxxx"
      + type             : "xxxxx"
      + urn              : "urn:pulumi:xxxxx::xxxxx::cloudflare:index/zone:Zone::xxxxx"
      + zone             : "xxxxx"
    }

最後に

上記設定を行うことで Pulumi を用いて Cloudflare のリソースを管理できるようになりました。
今回は読み取りだけですが、リソースの追加なども簡単に対応できます。

Reference

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0