INTEGRITY Документация

1. Инициализация Terraform

Это руководство поможет вам начать работу с Terraform. Предположим, вы только что зарегистрировали домен (example.com) в Cloudflare, чтобы управлять всем через Terraform, и теперь вы создадите запись DNS, указывающую www.example.com к веб-серверу по адресу 203.0.113.10.

Прежде чем начать, убедитесь, что у вас есть:

1. Создайте свою конфигурацию

Создайте файл с именем main.tf, указав собственные значения для API-токен, ID зоны, ID аккаунта, а также домен:

terraform {
  required_providers {
    cloudflare = {
      source  = "cloudflare/cloudflare"
      version = "~> 5"
    }
  }
}

provider "cloudflare" {
  api_token = "<YOUR_API_TOKEN>"
}

variable "zone_id" {
  default = "<YOUR_ZONE_ID>"
}

variable "account_id" {
  default = "<YOUR_ACCOUNT_ID>"
}

variable "domain" {
  default = "<YOUR_DOMAIN>"
}

resource "cloudflare_dns_record" "www" {
  zone_id = "<YOUR_ZONE_ID>"
  name    = "www"
  content = "203.0.113.10"
  type    = "A"
  ttl     = 1
  proxied = true
  comment = "Domain verification record"
}

2. Инициализация и планирование

Инициализируйте Terraform, чтобы загрузить провайдер Cloudflare:

terraform init

Просмотрите, что будет создано:

terraform plan

Terraform used the selected providers to generate the following execution plan. Resource actions are
indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # cloudflare_dns_record.www will be created
  + resource "cloudflare_dns_record" "www" {
      + comment             = "Domain verification record"
      + comment_modified_on = (known after apply)
      + content             = "203.0.113.10"
      + created_on          = (known after apply)
      + id                  = (known after apply)
      + meta                = (known after apply)
      + modified_on         = (known after apply)
      + name                = "www"
      + proxiable           = (known after apply)
      + proxied             = true
      + settings            = (known after apply)
      + tags                = (known after apply)
      + tags_modified_on    = (known after apply)
      + ttl                 = 1
      + type                = "A"
      + zone_id             = "<YOUR_ZONE_ID>"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

3. Примените и проверьте

Примените конфигурацию:

terraform apply

Тип yes при появлении запроса.

Terraform used the selected providers to generate the following execution plan. Resource actions are
indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # cloudflare_dns_record.www will be created
  + resource "cloudflare_dns_record" "www" {
      + comment             = "Domain verification record"
      + comment_modified_on = (known after apply)
      + content             = "203.0.113.10"
      + created_on          = (known after apply)
      + id                  = (known after apply)
      + meta                = (known after apply)
      + modified_on         = (known after apply)
      + name                = "www"
      + proxiable           = (known after apply)
      + proxied             = true
      + settings            = (known after apply)
      + tags                = (known after apply)
      + tags_modified_on    = (known after apply)
      + ttl                 = 1
      + type                = "A"
      + zone_id             = "<YOUR_ZONE_ID>"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

cloudflare_dns_record.www: Creating...
cloudflare_dns_record.www: Creation complete after 0s

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

После создания проверьте запись DNS:

dig www.example.com

Проверьте ответ веб-сервера:

curl https://www.example.com
Hello, this is 203.0.113.10!

Чтобы увидеть полный результат вызова API:

terraform show

Также можно открыть панель управления Cloudflare и перейти в раздел DNS > Записи страницу.

Перейдите в Главная страница аккаунта ↗