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

Re-adds support for setting tags on the default route table #147

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Terraform version 0.10.3 or newer is required for this module to work.
| database_subnet_group_tags | Additional tags for the database subnet group | string | `<map>` | no |
| database_subnet_tags | Additional tags for the database subnets | string | `<map>` | no |
| database_subnets | A list of database subnets | list | `<list>` | no |
| default_route_table_tags | Additional tags for the default route table | string | `<map>` | no |
| default_vpc_enable_classiclink | Should be true to enable ClassicLink in the Default VPC | string | `false` | no |
| default_vpc_enable_dns_hostnames | Should be true to enable DNS hostnames in the Default VPC | string | `false` | no |
| default_vpc_enable_dns_support | Should be true to enable DNS support in the Default VPC | string | `true` | no |
Expand Down
20 changes: 20 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,23 @@ resource "aws_default_vpc" "this" {

tags = "${merge(map("Name", format("%s", var.default_vpc_name)), var.default_vpc_tags, var.tags)}"
}

data "aws_route_table" "default" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a data source ?
Route table ID is available by concat(aws_vpc.this.*.default_route_table_id, [""])[0] (see outputs)

count = "${var.manage_default_vpc ? 1 : 0}"

vpc_id = "${element(aws_default_vpc.this.*.id, 0)}"

filter {
name = "association.main"
values = ["true"]
}
}

resource "aws_default_route_table" "this" {
count = "${var.manage_default_vpc ? 1 : 0}"

default_route_table_id = "${element(data.aws_route_table.default.*.route_table_id, 0)}"
route = ["${data.aws_route_table.default.*.routes[0]}"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a try outside VPC module, route argument is useless :

Moreover this version is more TF > 0.12 compliant:

resource "aws_default_route_table" "this" {
  count = "${var.manage_default_vpc ? 1 : 0}"

  default_route_table_id = concat(aws_vpc.this.*.default_route_table_id, [""])[0]
  tags = merge({
      Name = var.default_vpc_name
      Createdby = "AWS"
      Taggedby = "terraform"
    },
    var.tags,
    var.default_route_table_tags
  )
}


tags = "${merge(map("Name", format("%s", var.default_vpc_name)), var.default_route_table_tags, var.tags)}"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ variable "private_subnet_tags" {
default = {}
}

variable "default_route_table_tags" {
description = "Additional tags for the default route table"
default = {}
}

variable "public_route_table_tags" {
description = "Additional tags for the public route tables"
default = {}
Expand Down