data "aws_region" "current" {
current = true
}
data "aws_vpc" "vpc" {
count = "${var.has_vpc_id == 0 ? 0 : 1}"
id = "${var.vpc_id}"
}
output "iam" {
value = "${
join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
)),
var.friendly_name
))}"
}
output "vpc" {
value = "${
map(
"none", join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
)),
element(split("-", lookup(data.aws_vpc.vpc.*.tags, "Name")), var.vpc-name-offset),
lookup(var.environments, var.environment),
var.friendly_name
)),
"a", join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
"a"
)),
element(split("-", lookup(data.aws_vpc.vpc.*.tags, "Name")), var.vpc-name-offset),
lookup(var.environments, var.environment),
var.friendly_name
)),
"b", join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
"b"
)),
element(split("-", lookup(data.aws_vpc.vpc.*.tags, "Name")), var.vpc-name-offset),
lookup(var.environments, var.environment),
var.friendly_name
)),
"c", join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
"c"
)),
element(split("-", lookup(data.aws_vpc.vpc.*.tags, "Name")), var.vpc-name-offset),
lookup(var.environments, var.environment),
var.friendly_name
)),
"d", join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
"d"
)),
element(split("-", lookup(data.aws_vpc.vpc.*.tags, "Name")), var.vpc-name-offset),
lookup(var.environments, var.environment),
var.friendly_name
))
)
}"
}
output "no_vpc" {
value = "${
join("-", list(
join("", list(
substr(element(split("-", data.aws_region.current.name), 0), 0, 2),
substr(element(split("-", data.aws_region.current.name), 1), 0, 1),
substr(element(split("-", data.aws_region.current.name), 2), 0, 1),
)),
lookup(var.environments, var.environment),
var.friendly_name
))}"
}
我得到的错误如下: 警告:输出“vpc”:必须使用splat语法访问data.aws_vpc.vpc属性“tags”,因为它有“count”设置;使用data.aws_vpc。*。标签获取所有实例的属性列表