dumb_coder
dumb_coder

Reputation: 325

Terraform to get all subnet id from vpc id

Currently I have a aws infrastructure that is created manually. I want to import configuration of vpc and subnets. With the

terraform import aws_vpc.example vpc-id

I can get the cidr block of the vpc. Further with the cidr block I also want to get all the subnet ids as well. Is there a way to get all subnet ids with import command or I have to manually enter every id?

I cannot find any document where all subnet values can be imported? If there is please share

Thank you in advance!

Upvotes: 0

Views: 4209

Answers (1)

Marcin
Marcin

Reputation: 238299

If you already have vpc_id, then you can use aws_subnet_ids data to automatically get the ids of its subsets.

Example from docs:

data "aws_subnet_ids" "example" {
  vpc_id = aws_vpc.example.vpc_id
}

Upvotes: 2

Related Questions