Skip to content

Instantly share code, notes, and snippets.

@turgay
Created December 14, 2019 00:25
Show Gist options
  • Select an option

  • Save turgay/6aacd4fa50ee2ab6c97b37b36b9f8be2 to your computer and use it in GitHub Desktop.

Select an option

Save turgay/6aacd4fa50ee2ab6c97b37b36b9f8be2 to your computer and use it in GitHub Desktop.
Terraform: Get a VPC by name
//file: provider.tf
provider "aws" {
region = "us-east-1"
}
//file: vpc.tf
variable "vpc_name" {}
data "aws_vpc" "selected" {
tags = {
Name = var.my_vpc_name
}
}
//file: variables.tf
variable "my_vpc_name" {}
//file: output.tf
output "select_vpc_id" {
value = data.aws_vpc.selected.id
}
//file: terraform.tfvars
my_vpc_name = "..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment