簡體   English   中英

Terraform 無法創建 AWS 私有托管 route53 區域

[英]Terraform cannot create AWS private hosted route53 zone

Terraform 似乎無法創建 AWS 私有托管 Route53 區域,並且在我嘗試創建與現有 VPC 關聯的新托管私有區域時因以下錯誤而死亡:

Error applying plan:
   1 error(s) occurred:
   aws_route53_zone.analytics: InvalidVPCId: The VPC: vpc-xxxxxxx you    provided is not authorized to make the association.
   status code: 400, request id: b411af23-0187-11e7-82e3-df8a3528194f

這是我的 .tf 文件:

provider "aws" {
  region  = "${var.region}"
  profile = "${var.environment}"
}

variable "vpcid" {
  default = "vpc-xxxxxx"
}

variable "region" {
  default = "eu-west-1"
}

variable "environment" {
  default = "dev"
}

resource "aws_route53_zone" "analytics" {
  vpc_id = "${var.vpcid}"
  name   = "data.int.example.com"
}

我不確定該錯誤是否指的是以下任一錯誤:

  • VPC 需要事先授權以某種方式與區域關聯。
  • 運行 terraform 的 aws 帳戶需要正確的 IAM 權限才能將區域與 vpc 相關聯

有沒有人知道我如何進一步解決這個問題?

有時,當提供者配置中配置的 aws 區域與您部署 VPC 的區域不同時,您也會遇到此類問題。 對於這種情況,我們可以為 aws 提供程序使用別名。 像下面這樣:

provider "aws" {
  region = "us-east-1"
}


provider "aws" {
  region = "ap-southeast-1"
  alias = "singapore"
}

然后我們可以在 terraform 資源中使用它,如下所示:

resource "aws_route53_zone_association" "vpc_two" {
  provider = "aws.singapore"
  zone_id = "${aws_route53_zone.dlos_vpc.zone_id}"
  vpc_id  = "${aws_vpc.vpc_two.id}"
}

當您需要 terraform 腳本在多個區域進行部署時,上面的代碼片段很有用。

如果以最新版本運行,請檢查 terraform 版本。

其次,如果與示例相比,您的代碼是錯誤的

data "aws_route53_zone" "selected" {
  name = "test.com."
  private_zone = true
}

resource "aws_route53_record" "www" {
  zone_id = "${data.aws_route53_zone.selected.zone_id}"
  name = "www.${data.aws_route53_zone.selected.name}"
  type = "A"
  ttl = "300"
  records = ["10.0.0.1"]
}

您收到的錯誤代碼是因為您的用戶/角色沒有必要的 VPC 相關權限,或者您使用了錯誤的 VPC ID。

我建議您仔細檢查您正在使用的 VPC id,可能使用VPC 數據源來獲取它:

# Assuming you use the "Name" tag on the VPC resource to identify your VPCs
variable "vpc_name" {}

data "aws_vpc" "selected" {
  tags {
    Name = "${var.vpc_name}"
  }
}

resource "aws_route53_zone" "analytics" {
  vpc_id = "${data.aws_vpc.selected.id}"
  name   = "data.int.example.com"
}

您還想檢查您的用戶/角色是否具有必要的 VPC 相關權限。 為此,您可能需要文檔中列出的所有權限:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM