Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services aws#U route#U table#U关联不';t适用于所有专用*子网-terraform_Amazon Web Services_Amazon Ec2_Automation_Devops_Terraform - Fatal编程技术网

Amazon web services aws#U route#U table#U关联不';t适用于所有专用*子网-terraform

Amazon web services aws#U route#U table#U关联不';t适用于所有专用*子网-terraform,amazon-web-services,amazon-ec2,automation,devops,terraform,Amazon Web Services,Amazon Ec2,Automation,Devops,Terraform,我使用下面的资源块创建了两个子网 resource "aws_subnet" "private" { count = "${length(var.private_subnet)}" vpc_id = "${aws_vpc.vpcname.id}" cidr_block = "${var.private_subnet[count.index]}" availability_zone

我使用下面的资源块创建了两个子网

resource "aws_subnet" "private" {
  count                   = "${length(var.private_subnet)}"
  vpc_id                  = "${aws_vpc.vpcname.id}"
  cidr_block              = "${var.private_subnet[count.index]}"
  availability_zone       = "${data.aws_availability_zones.available.names[count.index]}"
  map_public_ip_on_launch = false

  tags {
    Name        = "${var.private}-${format("%01d", count.index + 1)}"
    Environment = "${terraform.workspace}"
  }
} 
之后,我创建了eip、nat、专用路由表,将路由添加到专用路由表,最后,当我尝试将专用路由表关联到专用*子网时,terraform部分工作,即在4个子网中,只有2个子网与专用路由表关联

resource "aws_route_table_association" "private-subnet-association" {
  subnet_id      = "${element(aws_subnet.private.*.id, count.index)}"
  route_table_id = "${aws_vpc.vpcname.private_route_table.id}"
}
要将关联应用于所有私有子网,我必须更改什么

subnet_id      = "${element(aws_subnet.private*.?.id, count.index)}"

变量
nat\u gateway\u eip
来自哪里?您需要以
TYPE.NAME.ATTR

应该是这样的<代码>${element(aws_eip.RESOURCE_NAME.*.id,count.index)}

或者,您需要让创建
nat\u网关的任何模块/文件输出
eip\u id
值,并从远程状态引用它

编辑:在问题更改时更新答案

您需要创建多个关联以将此路由表关联到不同的子网


您当前的子网关联块没有迭代任何内容。语法
RESOURCE.NAME.*.ATTR
并不意味着“通配符”,它用于包含
计数的资源变量
nat\u gateway\u eip
来自何处?您需要以
TYPE.NAME.ATTR

应该是这样的<代码>${element(aws_eip.RESOURCE_NAME.*.id,count.index)}

或者,您需要让创建
nat\u网关的任何模块/文件输出
eip\u id
值,并从远程状态引用它

编辑:在问题更改时更新答案

您需要创建多个关联以将此路由表关联到不同的子网


您当前的子网关联块没有迭代任何内容。语法
RESOURCE.NAME.*.ATTR
并不意味着“通配符”,它用于包含
count

nat\u gateway\u eip的资源,eip来自variables.tf和dev.tfvars文件。我修改了资源块并添加了
subnet\u id=“${element(aws\u eip.aws\u subnet.private.*.id,count.index)}”
以下是错误:错误:应用计划时出错:发生1个错误:*aws\u route.private\u route:1个错误发生:*aws_route.private_route:创建路由时出错:InvalidNatGatewayID.NotFound:NatGatewayId'eipalloc-02ee81ff53c730ac0'不存在状态代码:400,请求ID:4692a51b-fbd4-4a02-a0d3-f4745b07bc6aI已删除aws_nat_gateway的计数。现在我们只有1个NAT网关,而像以前一样只有2个。但所有私有/私有数据库子网的路由表关联问题仍然存在<代码>#将子网专用子网与专用路由表资源“aws_route_table_association”专用子网关联“{subnet_id=“${element(aws_subnet.private.*.id,count.index)}”路由表id=“${aws_route_table.private_route_table.id}”
执行资源块后,只有一个专用子网路由表关联发生更改,但另一个仍然保持不变。nat_gateway_eip来自variables.tf和dev.tfvars文件。我修改了资源块并添加了
subnet\u id=“${element(aws\u eip.aws\u subnet.private.*.id,count.index)}”
以下是错误:错误:应用计划时出错:发生1个错误:*aws\u route.private\u route:1个错误发生:*aws_route.private_route:创建路由时出错:InvalidNatGatewayID.NotFound:NatGatewayId'eipalloc-02ee81ff53c730ac0'不存在状态代码:400,请求ID:4692a51b-fbd4-4a02-a0d3-f4745b07bc6aI已删除aws_nat_gateway的计数。现在我们只有1个NAT网关,而像以前一样只有2个。但所有私有/私有数据库子网的路由表关联问题仍然存在<代码>#将子网专用子网与专用路由表资源“aws_route_table_association”专用子网关联“{subnet_id=“${element(aws_subnet.private.*.id,count.index)}”路由表id=“${aws_route_table.private_route_table.id}”
执行资源块后,只有一个专用子网路由表关联更改,但另一个仍保持不变。