【问题标题】:Error While creating CNAME at Cloudflare through Terraform通过 Terraform 在 Cloudflare 创建 CNAME 时出错
【发布时间】:2021-04-22 15:58:15
【问题描述】:

我做了什么?

  • 创建了一个 terraform 模块,提供者为 cloudflare
provider "cloudflare" {
}
  • 使用变量CLOUDFLARE_API_TOKEN向shell环境提供令牌

  • 令牌可以访问该区域说:example.com

  • 使用以下方法创建一个定位到我的 S3 存储桶的 CNAME 记录:

resource "cloudflare_record" "cname-bucket" {
  zone_id = var.domain
  name    = var.bucket_name
  value   = "${var.bucket_name}.s3-website.${var.region}.amazonaws.com"
  proxied = true
  type    = "CNAME"
}
  • 应用此模块后,出现错误:
Error: failed to create DNS record: error from makeRequest: HTTP status 400: content "{\"success\":false,\"errors\":[{\"code\":7003,\"message\":\"Could not route to \\/zones\\/example.com\\/dns_records, perhaps your object identifier is invalid?\"},{\"code\":7000,\"message\":\"No route for that URI\"}],\"messages\":[],\"result\":null}"
  • 当我尝试使用 cloudflare 和浏览器创建相同的内容时,一切正常,但尝试使用 terraform 进行相同操作时,出现上述错误。

  • 访问我的令牌有:example.com - DNS:Edit

我需要什么?

  • 我在这里做错了什么?
  • 如何使用 terraform 模块创建此 CNAME 记录?

【问题讨论】:

    标签: amazon-s3 terraform cloudflare


    【解决方案1】:

    看起来问题出在您的cloudflare_record 资源中的zone_id = var.domain 行。您使用 example.com 作为 zone_id ,但您应该使用您的 Cloudflare 区域 ID。

    您可以在您的域的 Cloudflare 仪表板中找到您的区域 ID:在 API 部分的右侧列中查看 Overview

    【讨论】:

      【解决方案2】:
      locals {
        domain = "example.com"
        hostname = "example.com" # TODO: Varies by environment
      }
      
      variable "CLOUDFLARE_ACCOUNT_ID" {}
      variable "CLOUDFLARE_API_TOKEN" { sensitive = true }
      
      provider "cloudflare" {
        api_token = var.CLOUDFLARE_API_TOKEN
        account_id = var.CLOUDFLARE_ACCOUNT_ID
      }
      
      resource "cloudflare_zone" "default" {
        zone = local.domain
        plan = "free"
      }
      
      resource "cloudflare_record" "a" {
        zone_id = cloudflare_zone.default.id
        name    = local.hostname
        value   = "192.0.2.1"
        type    = "A"
        ttl     = 1
        proxied = true
      }
      

      来源 https://github.com/kriasoft/terraform-starter-kit

      【讨论】:

        猜你喜欢
        • 2021-09-26
        • 2017-07-27
        • 2021-03-16
        • 1970-01-01
        • 2021-09-05
        • 2021-04-24
        • 2020-11-07
        • 2020-08-29
        • 2021-07-09
        相关资源
        最近更新 更多