Skip to content
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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,30 @@ Available targets:

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
| attributes | Any extra attributes for naming these resources | list | `<list>` | no |
| availability_zones | List of Availability Zones where subnets will be created | list | - | yes |
| cidr_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | string | - | yes |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
| context | The context output from an external label module to pass to the label modules within this module | map | `<map>` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
| environment | The environment name if not using stage | string | `` | no |
| igw_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | string | - | yes |
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | string | `true` | no |
| 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 |
| name | Name (e.g. `app`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | string | `true` | no |
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | string | `false` | no |
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
| 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 |
| region | AWS Region (e.g. `us-east-1`) | string | - | yes |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
| 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 |
| 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 |
| tags | Additional tags (e.g. map(`Cluster`,`XYZ`) | map | `<map>` | no |
| tags | Additional tags to apply to all resources that use this label module | map | `<map>` | no |
| vpc_default_route_table_id | Default route table for public subnets. If not set, will be created. (e.g. `rtb-f4f0ce12`) | string | `` | no |
| vpc_id | VPC ID where subnets will be created (e.g. `vpc-aceb2723`) | string | - | yes |

Expand Down
17 changes: 11 additions & 6 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| additional_tag_map | Additional tags for appending to each tag map | map | `<map>` | no |
| attributes | Any extra attributes for naming these resources | list | `<list>` | no |
| availability_zones | List of Availability Zones where subnets will be created | list | - | yes |
| cidr_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | string | - | yes |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
| context | The context output from an external label module to pass to the label modules within this module | map | `<map>` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
| environment | The environment name if not using stage | string | `` | no |
| igw_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | string | - | yes |
| label_order | The naming order of the id output and Name tag | list | `<list>` | no |
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | string | `true` | no |
| 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 |
| name | Name (e.g. `app`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | string | `true` | no |
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | string | `false` | no |
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
| 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 |
| region | AWS Region (e.g. `us-east-1`) | string | - | yes |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
| 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 |
| 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 |
| tags | Additional tags (e.g. map(`Cluster`,`XYZ`) | map | `<map>` | no |
| tags | Additional tags to apply to all resources that use this label module | map | `<map>` | no |
| vpc_default_route_table_id | Default route table for public subnets. If not set, will be created. (e.g. `rtb-f4f0ce12`) | string | `` | no |
| vpc_id | VPC ID where subnets will be created (e.g. `vpc-aceb2723`) | string | - | yes |

Expand Down
79 changes: 79 additions & 0 deletions label.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
attributes = ["${var.attributes}"]
namespace = "${var.namespace}"
environment = "${var.environment}"
stage = "${var.stage}"
delimiter = "${var.delimiter}"
name = "${var.name}"
tags = "${var.tags}"
additional_tag_map = "${var.additional_tag_map}"
regex_replace_chars = "${var.regex_replace_chars}"
label_order = "${var.label_order}"
context = "${var.context}"
}

variable "additional_tag_map" {
type = "map"
default = {}
description = "Additional tags for appending to each tag map"
}

variable "label_order" {
type = "list"
default = []
description = "The naming order of the id output and Name tag"
}

variable "regex_replace_chars" {
type = "string"
default = "/[^a-zA-Z0-9-]/"
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"
}

variable "tags" {
description = "Additional tags to apply to all resources that use this label module"
type = "map"
default = {}
}

variable "namespace" {
type = "string"
default = ""
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
}

variable "stage" {
type = "string"
default = ""
description = "Stage, e.g. 'prod', 'staging', 'dev', or 'test'"
}

variable "name" {
type = "string"
default = ""
description = "Solution name, e.g. 'app' or 'jenkins'"
}

variable "environment" {
description = "The environment name if not using stage"
default = ""
}

variable "attributes" {
type = "list"
description = "Any extra attributes for naming these resources"
default = []
}

variable "delimiter" {
type = "string"
default = "-"
description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`"
}

variable "context" {
type = "map"
description = "The context output from an external label module to pass to the label modules within this module"
default = {}
}
10 changes: 3 additions & 7 deletions nat-gateway.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
module "nat_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes,list("nat")))}"
tags = "${var.tags}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
context = "${module.label.context}"
attributes = "${distinct(compact(concat(module.label.attributes,list("nat"))))}"
}

locals {
Expand Down
10 changes: 3 additions & 7 deletions nat-instance.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
module "nat_instance_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes,list("nat", "instance")))}"
tags = "${var.tags}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
context = "${module.label.context}"
attributes = "${distinct(compact(concat(module.label.attributes,list("nat", "instance"))))}"
}

locals {
Expand Down
24 changes: 6 additions & 18 deletions private.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
module "private_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes,list("private")))}"
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
}

module "private_subnet_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
attributes = "${compact(concat(var.attributes,list("private")))}"
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
context = "${module.label.context}"
attributes = "${compact(concat(module.label.attributes,list("private")))}"
tags = "${merge(module.label.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"private")))}"
}

locals {
Expand All @@ -27,7 +15,7 @@ resource "aws_subnet" "private" {
availability_zone = "${element(var.availability_zones, count.index)}"
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)}"

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))))}"
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))))}"

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

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))))}"
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))))}"
}

resource "aws_route_table_association" "private" {
Expand Down
22 changes: 5 additions & 17 deletions public.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
module "public_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
delimiter = "${var.delimiter}"
attributes = "${compact(concat(var.attributes,list("public")))}"
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
}

module "public_subnet_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
attributes = "${compact(concat(var.attributes,list("public")))}"
tags = "${merge(var.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
context = "${module.label.context}"
attributes = "${compact(concat(module.label.attributes,list("public")))}"
tags = "${merge(module.label.tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format,"public")))}"
}

locals {
Expand All @@ -28,7 +16,7 @@ resource "aws_subnet" "public" {
availability_zone = "${element(var.availability_zones, count.index)}"
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)}"
map_public_ip_on_launch = "${local.map_public_ip_on_launch}"
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))))}"
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))))}"

lifecycle {
# Ignore tags added by kops or kubernetes
Expand Down
33 changes: 0 additions & 33 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
variable "namespace" {
type = "string"
description = "Namespace (e.g. `cp` or `cloudposse`)"
}

variable "stage" {
type = "string"
description = "Stage (e.g. `prod`, `dev`, `staging`)"
}

variable "name" {
type = "string"
description = "Name (e.g. `app`)"
}

variable "delimiter" {
type = "string"
default = "-"
description = "Delimiter to be used between `namespace`, `stage`, `name`, and `attributes`"
}

variable "attributes" {
type = "list"
default = []
description = "Additional attributes (e.g. `policy` or `role`)"
}

variable "tags" {
type = "map"
default = {}
description = "Additional tags (e.g. map(`Cluster`,`XYZ`)"
}

variable "subnet_type_tag_key" {
default = "cpco.io/subnet/type"
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`"
Expand Down