In this post, we will see how to resolve How to get all CIDR’s of a existing VPC and add them to security group as inbound rules using Terraform?
Question:
I have an existing VPC which has 4 CIDR’s and I need to retrieve those CIDR’s and add them to a security as Inbound rules. Is there any way to do it in Terraform? I didn’t find a way to do that TerraformTerraform Version: v0.14.5
Best Answer:
To get both the default CIDR block and the associated ones you need to use thecidr_block_associations
attribute of the aws_vpc
data source:cidr_block_associations
attribute looks like this:cidr_block
values I used Terraform splat expression in my example.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com