Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: default_* attributes for aws_vpc data source #10428

Closed
cbarbour opened this issue Nov 30, 2016 · 2 comments
Closed

Feature Request: default_* attributes for aws_vpc data source #10428

cbarbour opened this issue Nov 30, 2016 · 2 comments

Comments

@cbarbour
Copy link

Affected data source

  • aws_vpc

Terraform Configuration Files

data "aws_vpc" "default" {
  default = true
}

resource "aws_default_route_table" "main" {
  default_route_table_id = "${data.aws_vpc.default.default_route_table_id}"

  tags {
    Name = "Main VPC Default table"
  }
}

resource "aws_default_security_group" "main" {
  vpc_id = "${data.aws_vpc.default.id}"

  tags {
    Name = "Main Default security group"
  }
}

resource "aws_default_network_acl" "main" {
  default_network_acl_id = "${data.aws_vpc.default.default_network_acl_id}"
  subnet_ids = [ "${aws_subnet.main.*.id}" ]

  tags {
    Name = "Main VPC Default Network ACL"
  }
}

Expected Behavior

It would be useful if aws_default_network_acl, aws_default_route_table, & aws_default_security_group were available as attributes of the aws_vpc data source so that these resources could be managed without importing the default VPC.

Actual Behavior

The aws_vpc data source doesn't export these attributes, making it impossible to discover their resource IDs.

Important Factoids

The alternative would be to import the default VPC into Terraform, and reference it's attributes. However, if destroyed it's impossible for Terraform to recreate the default VPC.

prevent_destroy could be used, but that would break the blanket terraform destroy command.

References

https://aws.amazon.com/premiumsupport/knowledge-center/deleted-default-vpc/

@ewbankkit
Copy link
Contributor

@cbarbour : With a couple of open PRs

I think this can be achieved without modifying the aws_vpc data source.

You can get the VPC ID from the aws_vpc data source and then use the existing aws_route_table data sources to get the ID you want:

data "aws_vpc" "default" {
  default = true
}

data "aws_route_table" "default" {
  vpc_id = "${data.aws_vpc.default.id}"

  filter {
    name = "association.main"

    values = [
      "true",
    ]
  }
}

resource "aws_default_route_table" "main" {
  default_route_table_id = "${data.aws_route_table.default.id}"

  tags {
    Name = "Main VPC Default table"
  }
}

Once #12709 is merged then you can do the same for the default NACL:

data "aws_network_acl" "default" {
  vpc_id = "${data.aws_vpc.default.id}"
  default = true
}

resource "aws_default_network_acl" "main" {
  default_network_acl_id = "${data.aws_network_acl.default.id}"
  subnet_ids = [ "${aws_subnet.main.*.id}" ]

  tags {
    Name = "Main VPC Default Network ACL"
  }
}

And once #11710 is merged:

resource "aws_default_vpc" "default" {
  tags {
    Name = "Main VPC"
  }
}

resource "aws_default_route_table" "main" {
  default_route_table_id = "${aws_default_vpc.default_route_table_id}"

  tags {
    Name = "Main VPC Default table"
  }
}

resource "aws_default_security_group" "main" {
  vpc_id = "${aws_default_vpc.id}"

  tags {
    Name = "Main Default security group"
  }
}

resource "aws_default_network_acl" "main" {
  default_network_acl_id = "${aws_default_vpc.default_network_acl_id}"
  subnet_ids = [ "${aws_subnet.main.*.id}" ]

  tags {
    Name = "Main VPC Default Network ACL"
  }
}

@ghost
Copy link

ghost commented Apr 10, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants