8
votes

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"
  }
}
1

1 Answers

16
votes

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
}