I am trying to get the private subnets in my VPC, I'm using an example from the Terraform docs https://www.terraform.io/docs/providers/aws/d/subnet_ids.html but this is giving me errors.
Here is my code (I commented out the filter, so this should get all subnets - my vpc has 3 public and 3 private subnets)
data "aws_subnet_ids" "example" {
vpc_id = var.vpc_id
// filter {
// name = "tag:Tier"
// values = ["private"]
// }
}
data "aws_subnet" "example" {
count = length(data.aws_subnet_ids.example.ids)
id = data.aws_subnet_ids.example.ids[count.index]
}
I get an error on the id = data.aws_subnet_ids... line
I get the following error 6 times, 1 for each index
Error: Invalid index
on modules/global/data.tf line 20, in data "aws_subnet" "example":
12: id = data.aws_subnet_ids.example.ids[count.index]
|----------------
| count.index is 5
| data.aws_subnet_ids.example.ids is set of string with 6 elements
This value does not have any indices.
I'm using HCL2, but just in case I reverted back to previous interpolation ("${data.aws_subnet_ids.example.ids[count.index]}") for all statements with the same results.
help?
Thank you
$ terraform --version
Terraform v0.12.7
+ provider.aws v2.25.0
+ provider.template v2.1.2