【问题标题】:Terraform cannot create AWS private hosted route53 zoneTerraform 无法创建 AWS 私有托管 route53 区域
【发布时间】:2017-07-25 05:59:07
【问题描述】:

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 关联

有人知道我该如何进一步解决这个问题吗?

【问题讨论】:

  • 什么是 terraform 版本?看来您使用的是旧版本。

标签: amazon-web-services amazon-route53 amazon-vpc terraform


【解决方案1】:

有时,当提供程序配置中配置的 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 脚本在多个区域进行部署时,上述 sn-p 非常有用。

【讨论】:

    【解决方案2】:

    检查 terraform 版本是否以最新版本运行。

    其次,如果与sample比较,您的代码是错误的

    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"]
    }
    

    【讨论】:

    • 我使用的是 Terraform v0.8.2,看起来我的版本和最新版本之间的文档有很大的不同:
    • 仅仅因为示例不同并不意味着OP的代码是错误的。事实上,这应该可以正常工作。我猜可能是 VPC ID 错误,或者用户/角色没有必要的 VPC 相关权限。
    • 我有同样的问题。下面是代码resource "aws_route53_zone" "kubetest" { name = "kubetest.com." data "aws_route53_zone" "selected" { name = "kubetest.com" },我收到以下错误* data.aws_route53_zone.selected: 1 error(s) occurred: * data.aws_route53_zone.selected: data.aws_route53_zone.selected: no matching Route53Zone found
    【解决方案3】:

    您收到的error code 是因为您的用户/角色没有必要的 VPC 相关权限,或者您使用了错误的 VPC ID。

    我建议您仔细检查您正在使用的 VPC id,可能使用 VPC data source 来获取它:

    # 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 相关权限。为此,您可能需要docs 中列出的所有权限:

    【讨论】:

    • 我在使用 AWS 提供商的个人资料时遇到了问题。无论我做了什么(v 0.8.7),它总是默认为我在环境中设置的帐户访问权限。一旦我更改了环境变量以访问我想在其中进行工作的帐户,它就可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2015-12-06
    • 2018-07-09
    • 2019-11-22
    • 2018-03-08
    相关资源
    最近更新 更多