HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Get a list of remote VPCs on AWS using Terraform?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
vpcsgetusingawsremotelistterraform

Problem

I'd like to get a list of all remote VPCs from AWS with terraform. I've read the documentation and found two data sources:

  • AWS_DEFAULT_VPC



  • AWS_VPC



The first one will give you the default VPC and the second one accepts a VPC id and toss out other information such as subnets...

How can I get a list of all VPCs existing in ceratin AWS region (US-West-2 for instance) ?

Solution

You'll have to use the output of the list in a for loop to get the subnet ids for_each, but it would look something like this:

data "aws_vpcs" "foo" {}

output "vpcs" {
  value = data.aws_vpcs.foo.ids
}

Code Snippets

data "aws_vpcs" "foo" {}

output "vpcs" {
  value = data.aws_vpcs.foo.ids
}

Context

StackExchange DevOps Q#14499, answer score: 1

Revisions (0)

No revisions yet.