Terraform 0.11从数据源获取VPC CIDR并传递给安全组入口规则资源
我的要求是我需要获取专有网络foo和专有网络条的CIDR地址,并将其传递给资源“aws\u安全性\u组规则”“入口” 我尝试了以下代码:Terraform 0.11从数据源获取VPC CIDR并传递给安全组入口规则资源,terraform,terraform-provider-aws,aws-security-group,terraform0.11,Terraform,Terraform Provider Aws,Aws Security Group,Terraform0.11,我的要求是我需要获取专有网络foo和专有网络条的CIDR地址,并将其传递给资源“aws\u安全性\u组规则”“入口” 我尝试了以下代码: 数据“aws_VPC”->获取给定VPC的ID 数据“aws_vpc”->列出vpc ID 资源“aws\U安全\U组\U规则”“入口”->将VPC CIRD作为入口传递 有人能帮忙吗?那么代码有什么问题?有错误消息吗?我收到了这个错误:error reading config for aws_vpc[get_vpc_ids]:在1:33解析错误:应该是“
- 数据“aws_VPC”->获取给定VPC的ID
- 数据“aws_vpc”->列出vpc ID
- 资源“aws\U安全\U组\U规则”“入口”->将VPC CIRD作为入口传递
有人能帮忙吗?那么代码有什么问题?有错误消息吗?我收到了这个错误:
error reading config for aws_vpc[get_vpc_ids]:在1:33解析错误:应该是“}”,但发现“[”
看起来它在抱怨一些语法错误。那么代码有什么问题吗?有错误消息吗?我收到了这个错误:error reading config for aws_vpc[get_vpc_ids]:1:33解析错误:应为“}”,但发现“[”
似乎在抱怨某些语法错误。
variable "list_of_vps"{
type = "list"
default = ["vpc-foo", "vpc-bar"]
}
variable "sg_name" {
default = "sg-test"
}
data "aws_vpcs" "get_vpc"{
count = "$length(var.list_of_vps)"
filter {
name = "tag:Name"
values = ["vpc-${element(var.list_of_vps, count.index)}"]
}
}
data "aws_vpc" "get_vpc_ids" {
count = "${length(data.aws_vpcs.get_vpc.ids)}"
id = "${tolist(data.aws_vpcs.prod.ids)[count.index]}"
}
resource "aws_security_group_rule" "ingress" {
count = "${length(var.list_of_vps)}"
type = "ingress"
from_port = 22
to_port = 22
protocol = "TCP"
cidr_blocks = ["${element(data.aws_vpc.get_vpc_ids.*.cidr_block, count.index)}"]
security_group_id = "${var.sg_name}
}