Skip to content

Commit f5cefb4

Browse files
Jamie-BitFlightaknysh
authored andcommitted
Feature/update label (#53)
* Updated label module to 0.11.1, allowed use of context * formatted and readme * Update label_variables.tf Co-Authored-By: Andriy Knysh <[email protected]> * Updated label to be in one file for portability. Updated some variable descriptions. * updated readme * Added an identifier to the descriptions of all label module variables. Added all variables that the Label module uses. * Updated readme * Updated readme
1 parent 29628fe commit f5cefb4

File tree

8 files changed

+118
-94
lines changed

8 files changed

+118
-94
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,25 +155,30 @@ Available targets:
155155

156156
| Name | Description | Type | Default | Required |
157157
|------|-------------|:----:|:-----:|:-----:|
158-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
158+
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
159+
| attributes | Any extra attributes for naming these resources | list | `<list>` | no |
159160
| availability_zones | List of Availability Zones where subnets will be created | list | - | yes |
160161
| cidr_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | string | - | yes |
161-
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
162+
| context | The context output from an external label module to pass to the label modules within this module | map | `<map>` | no |
163+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
164+
| environment | The environment name if not using stage | string | `` | no |
162165
| igw_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | string | - | yes |
166+
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
163167
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | string | `true` | no |
164168
| max_subnet_count | Sets the maximum amount of subnets to deploy. 0 will deploy a subnet for every provided availablility zone (in `availability_zones` variable) within the region | string | `0` | no |
165-
| name | Name (e.g. `app`) | string | - | yes |
166-
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
169+
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
170+
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
167171
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | string | `true` | no |
168172
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | string | `false` | no |
169173
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
170174
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
171175
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
176+
| regex_replace_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed | string | `/[^a-zA-Z0-9-]/` | no |
172177
| region | AWS Region (e.g. `us-east-1`) | string | - | yes |
173-
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
178+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
174179
| subnet_type_tag_key | Key for subnet type tag to provide information about the type of subnets, e.g. `cpco.io/subnet/type=private` or `cpco.io/subnet/type=public` | string | `cpco.io/subnet/type` | no |
175180
| subnet_type_tag_value_format | This is using the format interpolation symbols to allow the value of the subnet_type_tag_key to be modified. | string | `%s` | no |
176-
| tags | Additional tags (e.g. map(`Cluster`,`XYZ`) | map | `<map>` | no |
181+
| tags | Additional tags to apply to all resources that use this label module | map | `<map>` | no |
177182
| vpc_default_route_table_id | Default route table for public subnets. If not set, will be created. (e.g. `rtb-f4f0ce12`) | string | `` | no |
178183
| vpc_id | VPC ID where subnets will be created (e.g. `vpc-aceb2723`) | string | - | yes |
179184

docs/terraform.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
5+
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
6+
| attributes | Any extra attributes for naming these resources | list | `<list>` | no |
67
| availability_zones | List of Availability Zones where subnets will be created | list | - | yes |
78
| cidr_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | string | - | yes |
8-
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
9+
| context | The context output from an external label module to pass to the label modules within this module | map | `<map>` | no |
10+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
11+
| environment | The environment name if not using stage | string | `` | no |
912
| igw_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | string | - | yes |
13+
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
1014
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | string | `true` | no |
1115
| max_subnet_count | Sets the maximum amount of subnets to deploy. 0 will deploy a subnet for every provided availablility zone (in `availability_zones` variable) within the region | string | `0` | no |
12-
| name | Name (e.g. `app`) | string | - | yes |
13-
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
16+
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
17+
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
1418
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | string | `true` | no |
1519
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | string | `false` | no |
1620
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
1721
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
1822
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
23+
| regex_replace_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed | string | `/[^a-zA-Z0-9-]/` | no |
1924
| region | AWS Region (e.g. `us-east-1`) | string | - | yes |
20-
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
25+
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
2126
| subnet_type_tag_key | Key for subnet type tag to provide information about the type of subnets, e.g. `cpco.io/subnet/type=private` or `cpco.io/subnet/type=public` | string | `cpco.io/subnet/type` | no |
2227
| subnet_type_tag_value_format | This is using the format interpolation symbols to allow the value of the subnet_type_tag_key to be modified. | string | `%s` | no |
23-
| tags | Additional tags (e.g. map(`Cluster`,`XYZ`) | map | `<map>` | no |
28+
| tags | Additional tags to apply to all resources that use this label module | map | `<map>` | no |
2429
| vpc_default_route_table_id | Default route table for public subnets. If not set, will be created. (e.g. `rtb-f4f0ce12`) | string | `` | no |
2530
| vpc_id | VPC ID where subnets will be created (e.g. `vpc-aceb2723`) | string | - | yes |
2631

label.tf

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
module "label" {
2+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
3+
attributes = ["${var.attributes}"]
4+
namespace = "${var.namespace}"
5+
environment = "${var.environment}"
6+
stage = "${var.stage}"
7+
delimiter = "${var.delimiter}"
8+
name = "${var.name}"
9+
tags = "${var.tags}"
10+
additional_tag_map = "${var.additional_tag_map}"
11+
regex_replace_chars = "${var.regex_replace_chars}"
12+
label_order = "${var.label_order}"
13+
context = "${var.context}"
14+
}
15+
16+
variable "additional_tag_map" {
17+
type = "map"
18+
default = {}
19+
description = "Additional tags for appending to each tag map"
20+
}
21+
22+
variable "label_order" {
23+
type = "list"
24+
default = []
25+
description = "The naming order of the id output and Name tag"
26+
}
27+
28+
variable "regex_replace_chars" {
29+
type = "string"
30+
default = "/[^a-zA-Z0-9-]/"
31+
description = "Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed"
32+
}
33+
34+
variable "tags" {
35+
description = "Additional tags to apply to all resources that use this label module"
36+
type = "map"
37+
default = {}
38+
}
39+
40+
variable "namespace" {
41+
type = "string"
42+
default = ""
43+
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
44+
}
45+
46+
variable "stage" {
47+
type = "string"
48+
default = ""
49+
description = "Stage, e.g. 'prod', 'staging', 'dev', or 'test'"
50+
}
51+
52+
variable "name" {
53+
type = "string"
54+
default = ""
55+
description = "Solution name, e.g. 'app' or 'jenkins'"
56+
}
57+
58+
variable "environment" {
59+
description = "The environment name if not using stage"
60+
default = ""
61+
}
62+
63+
variable "attributes" {
64+
type = "list"
65+
description = "Any extra attributes for naming these resources"
66+
default = []
67+
}
68+
69+
variable "delimiter" {
70+
type = "string"
71+
default = "-"
72+
description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`"
73+
}
74+
75+
variable "context" {
76+
type = "map"
77+
description = "The context output from an external label module to pass to the label modules within this module"
78+
default = {}
79+
}

nat-gateway.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
module "nat_label" {
2-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
3-
namespace = "${var.namespace}"
4-
stage = "${var.stage}"
5-
name = "${var.name}"
6-
delimiter = "${var.delimiter}"
7-
attributes = "${compact(concat(var.attributes,list("nat")))}"
8-
tags = "${var.tags}"
2+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
3+
context = "${module.label.context}"
4+
attributes = "${distinct(compact(concat(module.label.attributes,list("nat"))))}"
95
}
106

117
locals {

nat-instance.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
module "nat_instance_label" {
2-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
3-
namespace = "${var.namespace}"
4-
stage = "${var.stage}"
5-
name = "${var.name}"
6-
delimiter = "${var.delimiter}"
7-
attributes = "${compact(concat(var.attributes,list("nat", "instance")))}"
8-
tags = "${var.tags}"
2+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
3+
context = "${module.label.context}"
4+
attributes = "${distinct(compact(concat(module.label.attributes,list("nat", "instance"))))}"
95
}
106

117
locals {

private.tf

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
module "private_label" {
2-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
3-
namespace = "${var.namespace}"
4-
stage = "${var.stage}"
5-
name = "${var.name}"
6-
delimiter = "${var.delimiter}"
7-
attributes = "${compact(concat(var.attributes,list("private")))}"
8-
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
9-
}
10-
11-
module "private_subnet_label" {
12-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
13-
namespace = "${var.namespace}"
14-
stage = "${var.stage}"
15-
name = "${var.name}"
16-
attributes = "${compact(concat(var.attributes,list("private")))}"
17-
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
2+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
3+
context = "${module.label.context}"
4+
attributes = "${compact(concat(module.label.attributes,list("private")))}"
5+
tags = "${merge(module.label.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
186
}
197

208
locals {
@@ -27,7 +15,7 @@ resource "aws_subnet" "private" {
2715
availability_zone = "${element(var.availability_zones, count.index)}"
2816
cidr_block = "${cidrsubnet(signum(length(var.cidr_block)) == 1 ? var.cidr_block : data.aws_vpc.default.cidr_block, ceil(log(local.private_subnet_count * 2, 2)), count.index)}"
2917

30-
tags = "${merge(module.private_subnet_label.tags, map("Name",format("%s%s%s", module.private_subnet_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
18+
tags = "${merge(module.private_label.tags, map("Name",format("%s%s%s", module.private_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
3119

3220
lifecycle {
3321
# Ignore tags added by kops or kubernetes
@@ -39,7 +27,7 @@ resource "aws_route_table" "private" {
3927
count = "${length(var.availability_zones)}"
4028
vpc_id = "${data.aws_vpc.default.id}"
4129

42-
tags = "${merge(module.private_subnet_label.tags, map("Name",format("%s%s%s", module.private_subnet_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
30+
tags = "${merge(module.private_label.tags, map("Name",format("%s%s%s", module.private_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
4331
}
4432

4533
resource "aws_route_table_association" "private" {

public.tf

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
module "public_label" {
2-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
3-
namespace = "${var.namespace}"
4-
stage = "${var.stage}"
5-
name = "${var.name}"
6-
delimiter = "${var.delimiter}"
7-
attributes = "${compact(concat(var.attributes,list("public")))}"
8-
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
9-
}
10-
11-
module "public_subnet_label" {
12-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
13-
namespace = "${var.namespace}"
14-
stage = "${var.stage}"
15-
name = "${var.name}"
16-
attributes = "${compact(concat(var.attributes,list("public")))}"
17-
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
2+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
3+
context = "${module.label.context}"
4+
attributes = "${compact(concat(module.label.attributes,list("public")))}"
5+
tags = "${merge(module.label.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
186
}
197

208
locals {
@@ -28,7 +16,7 @@ resource "aws_subnet" "public" {
2816
availability_zone = "${element(var.availability_zones, count.index)}"
2917
cidr_block = "${cidrsubnet(signum(length(var.cidr_block)) == 1 ? var.cidr_block : data.aws_vpc.default.cidr_block, ceil(log(local.public_subnet_count * 2, 2)), local.public_subnet_count + count.index)}"
3018
map_public_ip_on_launch = "${local.map_public_ip_on_launch}"
31-
tags = "${merge(module.public_subnet_label.tags, map("Name",format("%s%s%s", module.public_subnet_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
19+
tags = "${merge(module.public_label.tags, map("Name",format("%s%s%s", module.public_label.id, var.delimiter, replace(element(var.availability_zones, count.index),"-",var.delimiter))))}"
3220

3321
lifecycle {
3422
# Ignore tags added by kops or kubernetes

variables.tf

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
1-
variable "namespace" {
2-
type = "string"
3-
description = "Namespace (e.g. `cp` or `cloudposse`)"
4-
}
5-
6-
variable "stage" {
7-
type = "string"
8-
description = "Stage (e.g. `prod`, `dev`, `staging`)"
9-
}
10-
11-
variable "name" {
12-
type = "string"
13-
description = "Name (e.g. `app`)"
14-
}
15-
16-
variable "delimiter" {
17-
type = "string"
18-
default = "-"
19-
description = "Delimiter to be used between `namespace`, `stage`, `name`, and `attributes`"
20-
}
21-
22-
variable "attributes" {
23-
type = "list"
24-
default = []
25-
description = "Additional attributes (e.g. `policy` or `role`)"
26-
}
27-
28-
variable "tags" {
29-
type = "map"
30-
default = {}
31-
description = "Additional tags (e.g. map(`Cluster`,`XYZ`)"
32-
}
33-
341
variable "subnet_type_tag_key" {
352
default = "cpco.io/subnet/type"
363
description = "Key for subnet type tag to provide information about the type of subnets, e.g. `cpco.io/subnet/type=private` or `cpco.io/subnet/type=public`"

0 commit comments

Comments
 (0)