Dear Colleagues,
Sorry for a probable FAQ, but the solutions I’ve been able to find on the Internet don’t work for me.
I want to avoid setting the VPC ID in my Terraform files and just want Terraform to use the only existing VPC in an AWS region. However some resources require the vpc_id, so I’ve tried variants of the following:
data "aws_vpc" "default" {
default = true
}
resource "aws_security_group" "test1" {
name = "test1"
vpc_id = data.aws_vpc.default.id
...
}
This however produces the following error on “terraform apply”:
data.aws_vpc.default: Reading…
Error: no matching EC2 VPC found
with data.aws_vpc.default,
on main.tf line 26, in data “aws_vpc” “default”:
26: data “aws_vpc” “default” {
Do you think I can somehow get the vpc_id of the “current” (default, the only one) vpc?