Terraform无法创建AW​​S私有托管路由53区域

问题描述:

当我尝试创建与现有VPC关联的新托管私有区域时,Terraform似乎无法创建AW​​S私有托管Route53区域,并死于以下错误:Terraform无法创建AW​​S私有托管路由53区域

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不知何故需要被授权与区域提前联系。
  • 的AWS帐号运行terraform需要正确的IAM权限区域与VPC关联

会有人有线索,我怎么能进一步解决?

+0

有什么terraform版本?似乎你运行旧版本。 – BMW

检查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"] 
} 
+0

我在Terraform v0.8.2上,看起来我的版本和最新版本之间的项目文档有很大差异: –

+0

仅仅因为示例不同并不意味着OP的代码是错误的。事实上,这应该可以正常工作。我猜可能是因为VPC ID错误,或者用户/角色没有必要的VPC相关权限。 – ydaetskcoR

比较你的代码是错误的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列出的权限:

enter image description here

+0

我在AWS提供商中使用配置文件时遇到问题。无论我做了什么(v 0.8.7),它总是默认为我在环境中设置的帐户访问权限。一旦我改变了env变量来访问我想要做的工作的帐户,它工作得很好。 – jpancoast