Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the default vpc id with terraform

I am trying to get the vpc_id of default vpc in my aws account using terraform

This is what I tried but it gives an error

Error: Invalid data source

this is what I tried:

data "aws_default_vpc" "default" {

}


# vpc
resource "aws_vpc" "kubernetes-vpc" {
  cidr_block = "${var.vpc_cidr_block}"
  enable_dns_hostnames = true

  tags = {
    Name = "kubernetes-vpc"
  }
}
like image 692
Jananath Banuka Avatar asked Mar 10 '20 14:03

Jananath Banuka


1 Answers

The aws_default_vpc is indeed not a valid data source. But the aws_vpc data source does have a boolean default you can use to choose the default vpc:

data "aws_vpc" "default" {
  default = true
} 
like image 173
Blokje5 Avatar answered Nov 12 '22 05:11

Blokje5