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

Use compact AZ codes in tags #100

Merged
merged 3 commits into from
Sep 11, 2020
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ Available targets:

| Name | Version |
|------|---------|
| terraform | >= 0.12.0, < 0.14.0 |
| aws | >= 2.0, < 4.0 |
| terraform | >= 0.12.0 |
| aws | >= 2.0 |
| local | ~> 1.2 |
| null | ~> 2.0 |
| template | ~> 2.0 |
Expand All @@ -188,14 +188,15 @@ Available targets:

| Name | Version |
|------|---------|
| aws | >= 2.0, < 4.0 |
| aws | >= 2.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| availability\_zone\_attribute\_style | The style of Availability Zone code to use in tags and names. One of `full`, `short`, or `fixed`. | `string` | `"short"` | no |
| availability\_zones | List of Availability Zones where subnets will be created | `list(string)` | n/a | yes |
| aws\_route\_create\_timeout | Time to wait for AWS route creation specifed as a Go Duration, e.g. `2m` | `string` | `"2m"` | no |
| aws\_route\_delete\_timeout | Time to wait for AWS route deletion specifed as a Go Duration, e.g. `5m` | `string` | `"5m"` | no |
Expand Down
63 changes: 29 additions & 34 deletions context.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
# All other instances of this file should be a copy of that one
#
#
# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
# and then place it in your Terraform module to automatically get
# Cloud Posse's standard configuration inputs suitable for passing
Expand All @@ -13,11 +17,28 @@
# For example, when using defaults, `module.this.context.delimiter`
# will be null, and `module.this.delimiter` will be `-` (hyphen).
#
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
# All other instances of this file should be a copy of that one
#

module "this" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2"

enabled = var.enabled
namespace = var.namespace
environment = var.environment
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
additional_tag_map = var.additional_tag_map
label_order = var.label_order
regex_replace_chars = var.regex_replace_chars
id_length_limit = var.id_length_limit

context = var.context
}

# Copy contents of cloudposse/terraform-null-label/variables.tf here

variable "context" {
type = object({
enabled = bool
Expand Down Expand Up @@ -53,7 +74,7 @@ variable "context" {
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
EOT
EOT
}

variable "enabled" {
Expand Down Expand Up @@ -92,7 +113,7 @@ variable "delimiter" {
description = <<-EOT
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
EOT
EOT
}

variable "attributes" {
Expand Down Expand Up @@ -120,7 +141,7 @@ variable "label_order" {
The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present.
EOT
EOT
}

variable "regex_replace_chars" {
Expand All @@ -129,7 +150,7 @@ variable "regex_replace_chars" {
description = <<-EOT
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
EOT
EOT
}

variable "id_length_limit" {
Expand All @@ -140,33 +161,7 @@ variable "id_length_limit" {
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`.
EOT
EOT
}

#### End of copy of cloudposse/terraform-null-label/variables.tf

#
# Ensure all variables above are includes in input to module "this" below
#
# Modules should access the whole context as `module.this.context`
# and access individual variables as `module.this.context.<var>`,
# for example, `module.this.context.enabled`
#
module "this" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1"

enabled = var.enabled
namespace = var.namespace
environment = var.environment
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
additional_tag_map = var.additional_tag_map
label_order = var.label_order
regex_replace_chars = var.regex_replace_chars
id_length_limit = var.id_length_limit

context = var.context
}
7 changes: 4 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

| Name | Version |
|------|---------|
| terraform | >= 0.12.0, < 0.14.0 |
| aws | >= 2.0, < 4.0 |
| terraform | >= 0.12.0 |
| aws | >= 2.0 |
| local | ~> 1.2 |
| null | ~> 2.0 |
| template | ~> 2.0 |
Expand All @@ -13,14 +13,15 @@

| Name | Version |
|------|---------|
| aws | >= 2.0, < 4.0 |
| aws | >= 2.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| additional\_tag\_map | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
| attributes | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
| availability\_zone\_attribute\_style | The style of Availability Zone code to use in tags and names. One of `full`, `short`, or `fixed`. | `string` | `"short"` | no |
| availability\_zones | List of Availability Zones where subnets will be created | `list(string)` | n/a | yes |
| aws\_route\_create\_timeout | Time to wait for AWS route creation specifed as a Go Duration, e.g. `2m` | `string` | `"2m"` | no |
| aws\_route\_delete\_timeout | Time to wait for AWS route deletion specifed as a Go Duration, e.g. `5m` | `string` | `"5m"` | no |
Expand Down
63 changes: 29 additions & 34 deletions examples/complete/context.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
# All other instances of this file should be a copy of that one
#
#
# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
# and then place it in your Terraform module to automatically get
# Cloud Posse's standard configuration inputs suitable for passing
Expand All @@ -13,11 +17,28 @@
# For example, when using defaults, `module.this.context.delimiter`
# will be null, and `module.this.delimiter` will be `-` (hyphen).
#
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
# All other instances of this file should be a copy of that one
#

module "this" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2"

enabled = var.enabled
namespace = var.namespace
environment = var.environment
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
additional_tag_map = var.additional_tag_map
label_order = var.label_order
regex_replace_chars = var.regex_replace_chars
id_length_limit = var.id_length_limit

context = var.context
}

# Copy contents of cloudposse/terraform-null-label/variables.tf here

variable "context" {
type = object({
enabled = bool
Expand Down Expand Up @@ -53,7 +74,7 @@ variable "context" {
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.
EOT
EOT
}

variable "enabled" {
Expand Down Expand Up @@ -92,7 +113,7 @@ variable "delimiter" {
description = <<-EOT
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
EOT
EOT
}

variable "attributes" {
Expand Down Expand Up @@ -120,7 +141,7 @@ variable "label_order" {
The naming order of the id output and Name tag.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 5 elements, but at least one must be present.
EOT
EOT
}

variable "regex_replace_chars" {
Expand All @@ -129,7 +150,7 @@ variable "regex_replace_chars" {
description = <<-EOT
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
EOT
EOT
}

variable "id_length_limit" {
Expand All @@ -140,33 +161,7 @@ variable "id_length_limit" {
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`.
EOT
EOT
}

#### End of copy of cloudposse/terraform-null-label/variables.tf

#
# Ensure all variables above are includes in input to module "this" below
#
# Modules should access the whole context as `module.this.context`
# and access individual variables as `module.this.context.<var>`,
# for example, `module.this.context.enabled`
#
module "this" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1"

enabled = var.enabled
namespace = var.namespace
environment = var.environment
stage = var.stage
name = var.name
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
additional_tag_map = var.additional_tag_map
label_order = var.label_order
regex_replace_chars = var.regex_replace_chars
id_length_limit = var.id_length_limit

context = var.context
}
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ data "aws_eip" "nat_ips" {

locals {
use_existing_eips = length(var.existing_nat_ips) > 0
map_map = {
Copy link
Member

Choose a reason for hiding this comment

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

looks like this map_map will be included in all modules.
Maybe we should move it to terraform-aws-utils?

Copy link
Member

Choose a reason for hiding this comment

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

map_map is not my first choice, but whatevs. ;)

short = "to_short"
fixed = "to_fixed"
full = "identity"
}
az_map = module.utils.region_az_alt_code_maps[local.map_map[var.availability_zone_attribute_style]]
}

module "utils" {
source = "git::https://github.com/cloudposse/terraform-aws-utils.git?ref=tags/0.1.0"
}
24 changes: 3 additions & 21 deletions nat-gateway.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "nat_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2"

attributes = ["nat"]

Expand All @@ -20,16 +20,7 @@ resource "aws_eip" "default" {
tags = merge(
module.private_label.tags,
{
"Name" = format(
"%s%s%s",
module.private_label.id,
local.delimiter,
replace(
element(var.availability_zones, count.index),
"-",
local.delimiter
)
)
"Name" = format("%s%s%s", module.private_label.id, local.delimiter, local.az_map[element(var.availability_zones, count.index)])
}
)

Expand All @@ -46,16 +37,7 @@ resource "aws_nat_gateway" "default" {
tags = merge(
module.nat_label.tags,
{
"Name" = format(
"%s%s%s",
module.nat_label.id,
local.delimiter,
replace(
element(var.availability_zones, count.index),
"-",
local.delimiter
)
)
"Name" = format("%s%s%s", module.nat_label.id, local.delimiter, local.az_map[element(var.availability_zones, count.index)])
}
)

Expand Down
24 changes: 3 additions & 21 deletions nat-instance.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "nat_instance_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.2"

attributes = ["nat", "instance"]

Expand Down Expand Up @@ -75,16 +75,7 @@ resource "aws_instance" "nat_instance" {
tags = merge(
module.nat_instance_label.tags,
{
"Name" = format(
"%s%s%s",
module.nat_label.id,
local.delimiter,
replace(
element(var.availability_zones, count.index),
"-",
local.delimiter
)
)
"Name" = format("%s%s%s", module.nat_instance_label.id, local.delimiter, local.az_map[element(var.availability_zones, count.index)])
}
)

Expand All @@ -105,16 +96,7 @@ resource "aws_eip" "nat_instance" {
tags = merge(
module.nat_instance_label.tags,
{
"Name" = format(
"%s%s%s",
module.nat_label.id,
local.delimiter,
replace(
element(var.availability_zones, count.index),
"-",
local.delimiter
)
)
"Name" = format("%s%s%s", module.nat_instance_label.id, local.delimiter, local.az_map[element(var.availability_zones, count.index)])
}
)

Expand Down
Loading