i have an unusual issue with terraform.
i create two VPCs and within the same terraform script i want to add a private hosted zone.
i do the following:
data "aws_vpcs" "foo" {}
this is getting me the VPCs that are created in the region.
normally i can output the IDs of the VPCs like:
output "test" {
value = data.aws_vpcs.foo.ids
}
this is giving me a list like:
[ "vpc-0c8446a2164b7d0af", "vpc-0e7c63c3f383d115d", ]
now, from this list i would like to get the 1st VPC id: "vpc-0c8446a2164b7d0af"
the problem is that it does not work.
i try using the element function like:
element(data.aws_vpcs.foo.ids, 0)
element([data.aws_vpcs.foo.ids], 0)
i also try to assign this to a value like: data.aws_vpcs.foo.ids[0]
it does not work and i cannot find any other options on terraform to help me solve this.
i want to use the 1st VPC id to create a resource:
resource "aws_route53_zone" "private" {
name = "example.com"
vpc {
vpc_id = data.aws_vpcs.foo.ids[0]
}
}
so i can get the 1st VPC (it does not matter the order) from the List of VPCs i get in the region.
when i run terraform plan i get the error:
Error: Invalid index
on main.tf line 25, in resource "aws_route53_zone" "private":
25: vpc_id = data.aws_vpcs.foo.ids[0]
This value does not have any indices.
aws_vpcs
data source as well please? – ydaetskcoR