0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Datadog モニターを Terraform で管理するための import 手順

Posted at

Datadog モニターを Terraform で管理するための import 手順

Terraform ログイン

まず、Terraform Cloud にログインします(Terraform Cloud を使用している場合)

terraform login

main.tfの作成

以下は作成例

terraform {
  required_providers {
    datadog = {
      source  = "DataDog/datadog"
      version = "~> 3.0"
    }
  }
  cloud {
    organization = "${terraform cloudの組織名}"

    workspaces {
      name = "${terraform cloudのワークスペース名}"
    }
  }
}

provider "datadog" {
  api_key = ${DATADOG_API_KEY の値}
  app_key = ${DATADOG_APP_KEY の値}
}

import ブロックの作成

適切な Terraform 設定ファイル(例:import.tf) import ブロックを作成します。

import {
  to = datadog_monitor.url_access_check
  id = "${monitorのID}"
}

Terraform 設定ファイルの生成

以下のコマンドを実行して、既存のリソースに基づいて Terraform 設定ファイルを生成します。

terraform plan -generate-config-out=generated.tf

このコマンドにより、generated.tf ファイルが作成され、インポートされるリソースの設定が含まれます。

生成された設定の確認と調整

generated.tf ファイルの内容を確認し、必要に応じて調整します。リソース名、パラメータ、その他の設定が正しいことを確認。

Terraform plan の実行

変更内容を確認するために、Terraform plan を実行します。

terraform plan

出力を確認し、予期しない変更がないことを確認します。

Terraform apply の実行

問題がなければ、変更を適用します。

terraform apply

確認プロンプトが表示されたら、yes と入力して実行を続行します。

確認

適用が完了したら terraform show コマンドを使用して、Terraform の状態ファイルに正しくリソースが追加されていることを確認できます。

terraform show
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?