I need to extract the subnet ids by passing the subnet names and get the output of the subnet ids.
main.tf
module "data" {
source = "./data"
}
output "subnetid" {
description = "The current bid status of the Spot Instance Request"
value = module.data.subnetid
}
Module data folder.
data.tf
data "aws_vpc" "vpc-id" {
filter {
name = "tag:Name"
values = ["kdt-vpc"]
}
}
data "aws_subnets" "selected" {
filter {
name = "vpc-id"
values = [data.aws_vpc.vpc-id.id]
}
filter {
name = "tag:Name"
values = ["kdt-private-subnet-0","kdt-private-subnet-1"] # insert values here
}
}
outputs.tf
output "subnetid" {
description = "The current bid status of the Spot Instance Request"
value = data.aws_subnets.selected.id
}
When I run the terraform apply I am getting the output as
Changes to Outputs:
- subnetid = "us-east-1"
How Can I get the correct subnet id's by passing the two subnet names