Open sagar89jadhav opened 4 years ago
You can use the subnet data source. Basically, you pass the ID of the subnet resource to the subnet data source, the data source then retrieves the info relating to the subnet with the matching ID - you can then get data about the subnet from the data source (including its IPv4 CIDR block). Here's an example:
// This data source gets the data for the subnet that matches the specified subnet ID - e.g. subnet-1234567890abcdefg
data "aws_subnet" "selected" {
id = var.my_subnet_id
}
// You should then be able to get the CIDR block from the data with data.aws_subnet.selected.cidr_block
When you look up a subnet using the ID, it returns all of the arguments that weren't specified (look at the documentation for the subnet data source for an exhaustive list of arguments) in addition to the attributes.
I am trying to pass a variable as a IPv4 CIDR block using aws_subnet resource however, it seems there is no attributes available to fetch CIDR block. Is there a way to fetch IPv4 CIDR block from any of the available terraform resource?
I am referring below article https://www.terraform.io/docs/providers/aws/r/subnet.html
Thanks.