diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index bed3c967..07b38d2c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -12,3 +12,6 @@ # Cloud Posse must review any changes to GitHub actions .github/* @cloudposse/engineering + +# Cloud Posse must review any changes to standard context definition +**/context.tf @cloudposse/engineering diff --git a/.github/auto-release.yml b/.github/auto-release.yml new file mode 100644 index 00000000..2836185f --- /dev/null +++ b/.github/auto-release.yml @@ -0,0 +1,40 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' +version-template: '$MAJOR.$MINOR.$PATCH' +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + - 'enhancement' + patch: + labels: + - 'patch' + - 'fix' + - 'bugfix' + - 'bug' + - 'hotfix' + default: 'minor' + +categories: + - title: '🚀 Enhancements' + labels: + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - 'hotfix' + +change-template: | +
+ $TITLE @$AUTHOR (#$NUMBER) + + $BODY +
+ +template: | + $CHANGES diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 00000000..e21fbfe4 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,19 @@ +name: auto-release + +on: + push: + branches: + - master + +jobs: + semver: + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + with: + publish: true + prerelease: false + config-name: auto-release.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/chatops.yml b/.github/workflows/chatops.yml index a6bb11b4..0d943109 100644 --- a/.github/workflows/chatops.yml +++ b/.github/workflows/chatops.yml @@ -9,13 +9,13 @@ jobs: steps: - uses: actions/checkout@v2 - name: "Handle common commands" - uses: cloudposse/actions/github/slash-command-dispatch@0.15.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }} repository: cloudposse/actions commands: rebuild-readme, terraform-fmt - permission: none + permission: triage issue-type: pull-request test: @@ -24,13 +24,13 @@ jobs: - name: "Checkout commit" uses: actions/checkout@v2 - name: "Run tests" - uses: cloudposse/actions/github/slash-command-dispatch@0.15.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }} repository: cloudposse/actions commands: test - permission: none + permission: triage issue-type: pull-request reactions: false diff --git a/README.md b/README.md index 5d4850bb..878993bd 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ Available targets: | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | -| aws | ~> 2.0 | +| aws | >= 2.0, < 4.0 | | local | ~> 1.2 | | null | ~> 2.0 | | template | ~> 2.0 | @@ -187,29 +187,30 @@ Available targets: | Name | Version | |------|---------| -| aws | ~> 2.0 | +| aws | >= 2.0, < 4.0 | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| additional\_tag\_map | Additional tags for appending to each tag map | `map(string)` | `{}` | no | -| attributes | Any extra attributes for naming these resources | `list(string)` | `[]` | no | +| 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\_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 | | cidr\_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | `string` | n/a | yes | -| context | Default context to use for passing state between label invocations |
object({
namespace = string
environment = string
stage = string
name = string
enabled = bool
delimiter = string
attributes = list(string)
label_order = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": "",
"enabled": true,
"environment": "",
"label_order": [],
"name": "",
"namespace": "",
"regex_replace_chars": "",
"stage": "",
"tags": {}
}
| no | -| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no | -| enabled | Set to false to prevent the module from creating any resources | `bool` | `true` | no | -| environment | The environment name if not using stage | `string` | `""` | no | +| context | Single object for setting entire context at once.
See description of individual variables for details.
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. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | +| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | +| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | existing\_nat\_ips | Existing Elastic IPs to attach to the NAT Gateway or Instance instead of creating a new one. | `list(string)` | `[]` | no | +| id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | | igw\_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | `string` | n/a | yes | -| label\_order | The naming order of the ID output and Name tag | `list(string)` | `[]` | no | +| 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. | `list(string)` | `null` | no | | map\_public\_ip\_on\_launch | Instances launched into a public subnet should be assigned a public IP address | `bool` | `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 | `number` | `0` | no | -| name | Solution name, e.g. 'app' or 'cluster' | `string` | `""` | no | -| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `""` | no | +| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | +| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | nat\_gateway\_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | `bool` | `true` | no | | nat\_instance\_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | `bool` | `false` | no | | nat\_instance\_type | NAT Instance type | `string` | `"t3.micro"` | no | @@ -217,11 +218,11 @@ Available targets: | private\_subnets\_additional\_tags | Additional tags to be added to private subnets | `map(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 | | public\_subnets\_additional\_tags | Additional tags to be added to public subnets | `map(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 | -| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | `string` | `""` | no | +| regex\_replace\_chars | 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. | `string` | `null` | no | +| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | 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 to apply to all resources that use this label module | `map(string)` | `{}` | no | +| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | 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` | n/a | yes | diff --git a/context.tf b/context.tf new file mode 100644 index 00000000..2feaa180 --- /dev/null +++ b/context.tf @@ -0,0 +1,172 @@ +# +# 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 +# to Cloud Posse modules. +# +# Modules should access the whole context as `module.this.context` +# to get the input variables with nulls for defaults, +# for example `context = module.this.context`, +# and access individual variables as `module.this.`, +# with final values filled in. +# +# 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 +# + +# Copy contents of cloudposse/terraform-null-label/variables.tf here +variable "context" { + type = object({ + enabled = bool + namespace = string + environment = string + stage = string + name = string + delimiter = string + attributes = list(string) + tags = map(string) + additional_tag_map = map(string) + regex_replace_chars = string + label_order = list(string) + id_length_limit = number + }) + default = { + enabled = true + namespace = null + environment = null + stage = null + name = null + delimiter = null + attributes = [] + tags = {} + additional_tag_map = {} + regex_replace_chars = null + label_order = [] + id_length_limit = null + } + description = <<-EOT + Single object for setting entire context at once. + See description of individual variables for details. + 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 +} + +variable "enabled" { + type = bool + default = null + description = "Set to false to prevent the module from creating any resources" +} + +variable "namespace" { + type = string + default = null + description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'" +} + +variable "environment" { + type = string + default = null + description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'" +} + +variable "stage" { + type = string + default = null + description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'" +} + +variable "name" { + type = string + default = null + description = "Solution name, e.g. 'app' or 'jenkins'" +} + +variable "delimiter" { + type = string + default = null + 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 +} + +variable "attributes" { + type = list(string) + default = [] + description = "Additional attributes (e.g. `1`)" +} + +variable "tags" { + type = map(string) + default = {} + description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`" +} + +variable "additional_tag_map" { + type = map(string) + default = {} + description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`." +} + +variable "label_order" { + type = list(string) + default = null + description = <<-EOT + 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 +} + +variable "regex_replace_chars" { + type = string + default = null + 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 +} + +variable "id_length_limit" { + type = number + default = null + description = <<-EOT + Limit `id` to this many characters. + Set to `0` for unlimited length. + Set to `null` for default, which is `0`. + Does not affect `id_full`. +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.`, +# 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 +} diff --git a/docs/terraform.md b/docs/terraform.md index 0deb2183..e1d7236d 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -3,7 +3,7 @@ | Name | Version | |------|---------| | terraform | >= 0.12.0, < 0.14.0 | -| aws | ~> 2.0 | +| aws | >= 2.0, < 4.0 | | local | ~> 1.2 | | null | ~> 2.0 | | template | ~> 2.0 | @@ -12,29 +12,30 @@ | Name | Version | |------|---------| -| aws | ~> 2.0 | +| aws | >= 2.0, < 4.0 | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| additional\_tag\_map | Additional tags for appending to each tag map | `map(string)` | `{}` | no | -| attributes | Any extra attributes for naming these resources | `list(string)` | `[]` | no | +| 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\_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 | | cidr\_block | Base CIDR block which will be divided into subnet CIDR blocks (e.g. `10.0.0.0/16`) | `string` | n/a | yes | -| context | Default context to use for passing state between label invocations |
object({
namespace = string
environment = string
stage = string
name = string
enabled = bool
delimiter = string
attributes = list(string)
label_order = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": "",
"enabled": true,
"environment": "",
"label_order": [],
"name": "",
"namespace": "",
"regex_replace_chars": "",
"stage": "",
"tags": {}
}
| no | -| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | `string` | `"-"` | no | -| enabled | Set to false to prevent the module from creating any resources | `bool` | `true` | no | -| environment | The environment name if not using stage | `string` | `""` | no | +| context | Single object for setting entire context at once.
See description of individual variables for details.
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. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | +| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | +| enabled | Set to false to prevent the module from creating any resources | `bool` | `null` | no | +| environment | Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | existing\_nat\_ips | Existing Elastic IPs to attach to the NAT Gateway or Instance instead of creating a new one. | `list(string)` | `[]` | no | +| id\_length\_limit | Limit `id` to this many characters.
Set to `0` for unlimited length.
Set to `null` for default, which is `0`.
Does not affect `id_full`. | `number` | `null` | no | | igw\_id | Internet Gateway ID the public route table will point to (e.g. `igw-9c26a123`) | `string` | n/a | yes | -| label\_order | The naming order of the ID output and Name tag | `list(string)` | `[]` | no | +| 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. | `list(string)` | `null` | no | | map\_public\_ip\_on\_launch | Instances launched into a public subnet should be assigned a public IP address | `bool` | `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 | `number` | `0` | no | -| name | Solution name, e.g. 'app' or 'cluster' | `string` | `""` | no | -| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `""` | no | +| name | Solution name, e.g. 'app' or 'jenkins' | `string` | `null` | no | +| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | `string` | `null` | no | | nat\_gateway\_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | `bool` | `true` | no | | nat\_instance\_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | `bool` | `false` | no | | nat\_instance\_type | NAT Instance type | `string` | `"t3.micro"` | no | @@ -42,11 +43,11 @@ | private\_subnets\_additional\_tags | Additional tags to be added to private subnets | `map(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 | | public\_subnets\_additional\_tags | Additional tags to be added to public subnets | `map(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 | -| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | `string` | `""` | no | +| regex\_replace\_chars | 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. | `string` | `null` | no | +| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | 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 to apply to all resources that use this label module | `map(string)` | `{}` | no | +| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | `map(string)` | `{}` | 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` | n/a | yes | diff --git a/examples/complete/context.tf b/examples/complete/context.tf new file mode 100644 index 00000000..2feaa180 --- /dev/null +++ b/examples/complete/context.tf @@ -0,0 +1,172 @@ +# +# 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 +# to Cloud Posse modules. +# +# Modules should access the whole context as `module.this.context` +# to get the input variables with nulls for defaults, +# for example `context = module.this.context`, +# and access individual variables as `module.this.`, +# with final values filled in. +# +# 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 +# + +# Copy contents of cloudposse/terraform-null-label/variables.tf here +variable "context" { + type = object({ + enabled = bool + namespace = string + environment = string + stage = string + name = string + delimiter = string + attributes = list(string) + tags = map(string) + additional_tag_map = map(string) + regex_replace_chars = string + label_order = list(string) + id_length_limit = number + }) + default = { + enabled = true + namespace = null + environment = null + stage = null + name = null + delimiter = null + attributes = [] + tags = {} + additional_tag_map = {} + regex_replace_chars = null + label_order = [] + id_length_limit = null + } + description = <<-EOT + Single object for setting entire context at once. + See description of individual variables for details. + 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 +} + +variable "enabled" { + type = bool + default = null + description = "Set to false to prevent the module from creating any resources" +} + +variable "namespace" { + type = string + default = null + description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'" +} + +variable "environment" { + type = string + default = null + description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'" +} + +variable "stage" { + type = string + default = null + description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'" +} + +variable "name" { + type = string + default = null + description = "Solution name, e.g. 'app' or 'jenkins'" +} + +variable "delimiter" { + type = string + default = null + 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 +} + +variable "attributes" { + type = list(string) + default = [] + description = "Additional attributes (e.g. `1`)" +} + +variable "tags" { + type = map(string) + default = {} + description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`" +} + +variable "additional_tag_map" { + type = map(string) + default = {} + description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`." +} + +variable "label_order" { + type = list(string) + default = null + description = <<-EOT + 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 +} + +variable "regex_replace_chars" { + type = string + default = null + 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 +} + +variable "id_length_limit" { + type = number + default = null + description = <<-EOT + Limit `id` to this many characters. + Set to `0` for unlimited length. + Set to `null` for default, which is `0`. + Does not affect `id_full`. +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.`, +# 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 +} diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 591b1d5c..7ecd4498 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -3,19 +3,19 @@ provider "aws" { } module "vpc" { - source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1" - namespace = var.namespace - stage = var.stage - name = var.name + source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.16.2" cidr_block = "172.16.0.0/16" + + # Obsolete, until VPC module is updated, then use + # context = module.this.context + namespace = module.this.context.namespace + stage = module.this.context.stage + name = module.this.context.name } module "subnets" { source = "../../" availability_zones = var.availability_zones - namespace = var.namespace - stage = var.stage - name = var.name vpc_id = module.vpc.vpc_id igw_id = module.vpc.igw_id cidr_block = module.vpc.vpc_cidr_block @@ -23,4 +23,6 @@ module "subnets" { nat_instance_enabled = false aws_route_create_timeout = "5m" aws_route_delete_timeout = "10m" + + context = module.this.context } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 1d74bb34..42ff5965 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -7,18 +7,3 @@ variable "availability_zones" { type = list(string) description = "List of Availability Zones where subnets will be created" } - -variable "namespace" { - type = string - description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'" -} - -variable "stage" { - type = string - description = "Stage, e.g. 'prod', 'staging', 'dev', or 'test'" -} - -variable "name" { - type = string - description = "Solution/application name, e.g. 'app' or 'cluster'" -} diff --git a/examples/existing-ips/variables.tf b/examples/existing-ips/variables.tf index cd30fefe..e6a91bf0 100644 --- a/examples/existing-ips/variables.tf +++ b/examples/existing-ips/variables.tf @@ -26,5 +26,5 @@ variable "name" { variable "existing_nat_ips" { type = list(string) default = [] - description = "Existing Elastic IPs to attach to the NAT Gateway or Instance instead of creating a new one." + description = "Existing Elastic IPs to attach to the NAT Gateway or Instance instead of creating a new one." } diff --git a/main.tf b/main.tf index e359ff81..7dc88357 100644 --- a/main.tf +++ b/main.tf @@ -1,39 +1,25 @@ # Get object aws_vpc by vpc_id data "aws_vpc" "default" { - count = var.enabled ? 1 : 0 + count = local.enabled ? 1 : 0 id = var.vpc_id } data "aws_availability_zones" "available" { - count = var.enabled ? 1 : 0 + count = local.enabled_count } locals { - availability_zones_count = var.enabled ? length(var.availability_zones) : 0 - enabled = var.enabled ? 1 : 0 + availability_zones_count = local.enabled ? length(var.availability_zones) : 0 + enabled = module.this.enabled + enabled_count = local.enabled ? 1 : 0 + delimiter = module.this.delimiter } data "aws_eip" "nat_ips" { - count = var.enabled ? length(var.existing_nat_ips) : 0 + count = local.enabled ? length(var.existing_nat_ips) : 0 public_ip = element(var.existing_nat_ips, count.index) } locals { use_existing_eips = length(var.existing_nat_ips) > 0 } - -module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - 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 - enabled = var.enabled -} diff --git a/nat-gateway.tf b/nat-gateway.tf index 81988d5c..e04c3378 100644 --- a/nat-gateway.tf +++ b/nat-gateway.tf @@ -1,8 +1,9 @@ module "nat_label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - enabled = var.enabled - context = module.label.context - attributes = distinct(compact(concat(module.label.attributes, ["nat"]))) + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1" + + attributes = ["nat"] + + context = module.this.context } locals { @@ -13,7 +14,7 @@ locals { } resource "aws_eip" "default" { - count = var.enabled ? local.nat_gateway_eip_count : 0 + count = local.enabled ? local.nat_gateway_eip_count : 0 vpc = true tags = merge( @@ -22,11 +23,11 @@ resource "aws_eip" "default" { "Name" = format( "%s%s%s", module.private_label.id, - var.delimiter, + local.delimiter, replace( element(var.availability_zones, count.index), "-", - var.delimiter + local.delimiter ) ) } @@ -38,7 +39,7 @@ resource "aws_eip" "default" { } resource "aws_nat_gateway" "default" { - count = var.enabled ? local.nat_gateways_count : 0 + count = local.enabled ? local.nat_gateways_count : 0 allocation_id = element(local.gateway_eip_allocations, count.index) subnet_id = element(aws_subnet.public.*.id, count.index) @@ -48,11 +49,11 @@ resource "aws_nat_gateway" "default" { "Name" = format( "%s%s%s", module.nat_label.id, - var.delimiter, + local.delimiter, replace( element(var.availability_zones, count.index), "-", - var.delimiter + local.delimiter ) ) } @@ -64,7 +65,7 @@ resource "aws_nat_gateway" "default" { } resource "aws_route" "default" { - count = var.enabled ? local.nat_gateways_count : 0 + count = local.enabled ? local.nat_gateways_count : 0 route_table_id = element(aws_route_table.private.*.id, count.index) nat_gateway_id = element(aws_nat_gateway.default.*.id, count.index) destination_cidr_block = "0.0.0.0/0" diff --git a/nat-instance.tf b/nat-instance.tf index 8c76eb57..35b8af9a 100644 --- a/nat-instance.tf +++ b/nat-instance.tf @@ -1,8 +1,9 @@ module "nat_instance_label" { - enabled = var.enabled - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - context = module.label.context - attributes = distinct(compact(concat(module.label.attributes, ["nat", "instance"]))) + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1" + + attributes = ["nat", "instance"] + + context = module.this.context } locals { @@ -14,7 +15,7 @@ locals { } resource "aws_security_group" "nat_instance" { - count = var.enabled ? local.nat_instance_enabled : 0 + count = local.enabled ? local.nat_instance_enabled : 0 name = module.nat_instance_label.id description = "Security Group for NAT Instance" vpc_id = var.vpc_id @@ -22,7 +23,7 @@ resource "aws_security_group" "nat_instance" { } resource "aws_security_group_rule" "nat_instance_egress" { - count = var.enabled ? local.nat_instance_enabled : 0 + count = local.enabled ? local.nat_instance_enabled : 0 description = "Allow all egress traffic" from_port = 0 to_port = 0 @@ -33,7 +34,7 @@ resource "aws_security_group_rule" "nat_instance_egress" { } resource "aws_security_group_rule" "nat_instance_ingress" { - count = var.enabled ? local.nat_instance_enabled : 0 + count = local.enabled ? local.nat_instance_enabled : 0 description = "Allow ingress traffic from the VPC CIDR block" from_port = 0 to_port = 0 @@ -45,7 +46,7 @@ resource "aws_security_group_rule" "nat_instance_ingress" { // aws --region us-west-2 ec2 describe-images --owners amazon --filters Name="name",Values="amzn-ami-vpc-nat*" Name="virtualization-type",Values="hvm" data "aws_ami" "nat_instance" { - count = var.enabled ? local.nat_instance_enabled : 0 + count = local.enabled ? local.nat_instance_enabled : 0 most_recent = true filter { @@ -65,7 +66,7 @@ data "aws_ami" "nat_instance" { // https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html // https://dzone.com/articles/nat-instance-vs-nat-gateway resource "aws_instance" "nat_instance" { - count = var.enabled ? local.nat_instance_count : 0 + count = local.enabled ? local.nat_instance_count : 0 ami = join("", data.aws_ami.nat_instance.*.id) instance_type = var.nat_instance_type subnet_id = element(aws_subnet.public.*.id, count.index) @@ -99,7 +100,7 @@ resource "aws_instance" "nat_instance" { } resource "aws_eip" "nat_instance" { - count = var.enabled ? local.nat_instance_eip_count : 0 + count = local.enabled ? local.nat_instance_eip_count : 0 vpc = true tags = merge( module.nat_instance_label.tags, @@ -123,13 +124,13 @@ resource "aws_eip" "nat_instance" { } resource "aws_eip_association" "nat_instance" { - count = var.enabled ? local.nat_instance_count : 0 + count = local.enabled ? local.nat_instance_count : 0 instance_id = element(aws_instance.nat_instance.*.id, count.index) allocation_id = element(local.instance_eip_allocations, count.index) } resource "aws_route" "nat_instance" { - count = var.enabled ? local.nat_instance_count : 0 + count = local.enabled ? local.nat_instance_count : 0 route_table_id = element(aws_route_table.private.*.id, count.index) instance_id = element(aws_instance.nat_instance.*.id, count.index) destination_cidr_block = "0.0.0.0/0" diff --git a/private.tf b/private.tf index dbd7573e..7af8775c 100644 --- a/private.tf +++ b/private.tf @@ -1,14 +1,13 @@ module "private_label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - enabled = var.enabled - context = module.label.context - attributes = compact(concat(module.label.attributes, ["private"])) + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1" + attributes = ["private"] tags = merge( - module.label.tags, var.private_subnets_additional_tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format, "private")) ) + + context = module.this.context } locals { @@ -17,7 +16,7 @@ locals { } resource "aws_subnet" "private" { - count = var.enabled ? local.availability_zones_count : 0 + count = local.enabled ? local.availability_zones_count : 0 vpc_id = join("", data.aws_vpc.default.*.id) availability_zone = element(var.availability_zones, count.index) @@ -33,11 +32,11 @@ resource "aws_subnet" "private" { "Name" = format( "%s%s%s", module.private_label.id, - var.delimiter, + local.delimiter, replace( element(var.availability_zones, count.index), "-", - var.delimiter + local.delimiter ) ) } @@ -50,7 +49,7 @@ resource "aws_subnet" "private" { } resource "aws_route_table" "private" { - count = var.enabled ? local.availability_zones_count : 0 + count = local.enabled ? local.availability_zones_count : 0 vpc_id = join("", data.aws_vpc.default.*.id) tags = merge( @@ -59,11 +58,11 @@ resource "aws_route_table" "private" { "Name" = format( "%s%s%s", module.private_label.id, - var.delimiter, + local.delimiter, replace( element(var.availability_zones, count.index), "-", - var.delimiter + local.delimiter ) ) } @@ -71,13 +70,13 @@ resource "aws_route_table" "private" { } resource "aws_route_table_association" "private" { - count = var.enabled ? local.availability_zones_count : 0 + count = local.enabled ? local.availability_zones_count : 0 subnet_id = element(aws_subnet.private.*.id, count.index) route_table_id = element(aws_route_table.private.*.id, count.index) } resource "aws_network_acl" "private" { - count = var.enabled ? local.private_network_acl_enabled : 0 + count = local.enabled ? local.private_network_acl_enabled : 0 vpc_id = var.vpc_id subnet_ids = aws_subnet.private.*.id diff --git a/public.tf b/public.tf index d36d9c32..2cae5470 100644 --- a/public.tf +++ b/public.tf @@ -1,21 +1,20 @@ module "public_label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0" - enabled = var.enabled - context = module.label.context - attributes = compact(concat(module.label.attributes, ["public"])) + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.19.1" + attributes = ["public"] tags = merge( - module.label.tags, var.public_subnets_additional_tags, map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format, "public")) ) + + context = module.this.context } locals { - public_subnet_count = var.enabled && var.max_subnet_count == 0 ? length(flatten(data.aws_availability_zones.available.*.names)) : var.max_subnet_count - public_route_expr_enabled = var.enabled && signum(length(var.vpc_default_route_table_id)) == 1 - public_network_acl_enabled = var.enabled && signum(length(var.public_network_acl_id)) == 0 ? 1 : 0 - vpc_default_route_table_id = var.enabled ? signum(length(var.vpc_default_route_table_id)) : 0 + public_subnet_count = local.enabled && var.max_subnet_count == 0 ? length(flatten(data.aws_availability_zones.available.*.names)) : var.max_subnet_count + public_route_expr_enabled = local.enabled && signum(length(var.vpc_default_route_table_id)) == 1 + public_network_acl_enabled = local.enabled && signum(length(var.public_network_acl_id)) == 0 ? 1 : 0 + vpc_default_route_table_id = local.enabled ? signum(length(var.vpc_default_route_table_id)) : 0 } resource "aws_subnet" "public" { @@ -37,11 +36,11 @@ resource "aws_subnet" "public" { "Name" = format( "%s%s%s", module.public_label.id, - var.delimiter, + local.delimiter, replace( element(var.availability_zones, count.index), "-", - var.delimiter + local.delimiter ) ) } @@ -53,14 +52,14 @@ resource "aws_subnet" "public" { } resource "aws_route_table" "public" { - count = local.public_route_expr_enabled ? 0 : local.enabled + count = local.public_route_expr_enabled ? 0 : local.enabled_count vpc_id = join("", data.aws_vpc.default.*.id) tags = module.public_label.tags } resource "aws_route" "public" { - count = local.public_route_expr_enabled ? 0 : local.enabled + count = local.public_route_expr_enabled ? 0 : local.enabled_count route_table_id = join("", aws_route_table.public.*.id) destination_cidr_block = "0.0.0.0/0" gateway_id = var.igw_id diff --git a/test/src/Gopkg.lock b/test/src/Gopkg.lock deleted file mode 100644 index 87bb6bd6..00000000 --- a/test/src/Gopkg.lock +++ /dev/null @@ -1,92 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" - name = "github.com/davecgh/go-spew" - packages = ["spew"] - pruneopts = "UT" - revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" - version = "v1.1.1" - -[[projects]] - digest = "1:75d6042fc66aebc974cc49b0c6c7cc3b9adb5f8130fbfa0dbec0820d990afa25" - name = "github.com/gruntwork-io/terratest" - packages = [ - "modules/collections", - "modules/customerrors", - "modules/files", - "modules/logger", - "modules/retry", - "modules/shell", - "modules/ssh", - "modules/terraform", - ] - pruneopts = "UT" - revision = "892abb2c35878d0808101bbfe6559e931dc2d354" - version = "v0.16.0" - -[[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - pruneopts = "UT" - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - digest = "1:5da8ce674952566deae4dbc23d07c85caafc6cfa815b0b3e03e41979cedb8750" - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require", - ] - pruneopts = "UT" - revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" - version = "v1.3.0" - -[[projects]] - branch = "master" - digest = "1:831470c2758c8b733941144f2803a0ccad0632c5a767415b777ebd296b5f463e" - name = "golang.org/x/crypto" - packages = [ - "curve25519", - "ed25519", - "ed25519/internal/edwards25519", - "internal/chacha20", - "internal/subtle", - "poly1305", - "ssh", - "ssh/agent", - ] - pruneopts = "UT" - revision = "22d7a77e9e5f409e934ed268692e56707cd169e5" - -[[projects]] - branch = "master" - digest = "1:76ee51c3f468493aff39dbacc401e8831fbb765104cbf613b89bef01cf4bad70" - name = "golang.org/x/net" - packages = ["context"] - pruneopts = "UT" - revision = "f3200d17e092c607f615320ecaad13d87ad9a2b3" - -[[projects]] - branch = "master" - digest = "1:181f3fd33e620b958b5ab77da177cf775cdcccd7db82963607875fbd09ae995e" - name = "golang.org/x/sys" - packages = [ - "cpu", - "unix", - ] - pruneopts = "UT" - revision = "9cd6430ef91e39e1a0ec0470cf1321a33ef1b887" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/gruntwork-io/terratest/modules/terraform", - "github.com/stretchr/testify/assert", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/test/src/Gopkg.toml b/test/src/Gopkg.toml deleted file mode 100644 index 995bac57..00000000 --- a/test/src/Gopkg.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.2" - -[prune] - go-tests = true - unused-packages = true diff --git a/test/src/Makefile b/test/src/Makefile index 3a342e36..b772822c 100644 --- a/test/src/Makefile +++ b/test/src/Makefile @@ -1,50 +1,30 @@ -PACKAGE = terraform-aws-dynamic-subnets -GOEXE ?= /usr/bin/go -GOPATH = $(CURDIR)/.gopath -GOBIN = $(GOPATH)/bin -BASE = $(GOPATH)/src/$(PACKAGE) -PATH := $(PATH):$(GOBIN) - -export TF_DATA_DIR ?= $(CURDIR)/.terraform export TF_CLI_ARGS_init ?= -get-plugins=true -export GOPATH +export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1-2) +.DEFAULT_GOAL : all .PHONY: all + ## Default target all: test -ifneq (,$(wildcard /sbin/apk)) -## Install go, if not installed -$(GOEXE): - apk add --update go -endif - -ifeq ($(shell uname -s),Linux) -## Install all `dep`, if not installed -$(GOBIN)/dep: - @mkdir -p $(GOBIN) - @curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh -endif - -## Prepare the GOPATH -$(BASE): $(GOEXE) - @mkdir -p $(dir $@) - @ln -sf $(CURDIR) $@ - -## Download vendor dependencies to vendor/ -$(BASE)/vendor: $(BASE) $(GOBIN)/dep - cd $(BASE) && dep ensure - .PHONY : init ## Initialize tests -init: $(BASE)/vendor +init: + @exit 0 .PHONY : test ## Run tests test: init - cd $(BASE) && go test -v -timeout 30m -run TestExamplesComplete + go mod download + go test -v -timeout 60m -run TestExamplesComplete + +## Run tests in docker container +docker/test: + docker run --name terratest --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e GITHUB_TOKEN \ + -e PATH="/usr/local/terraform/$(TERRAFORM_VERSION)/bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ + -v $(CURDIR)/../../:/module/ cloudposse/test-harness:latest -C /module/test/src test .PHONY : clean ## Clean up files clean: - rm -rf .gopath/ vendor/ $(TF_DATA_DIR) + rm -rf ../../examples/complete/*.tfstate* diff --git a/test/src/go.mod b/test/src/go.mod new file mode 100644 index 00000000..003ea176 --- /dev/null +++ b/test/src/go.mod @@ -0,0 +1,14 @@ +module github.com/cloudposse/terraform-aws-dynamic-subnets + +go 1.14 + +require ( + github.com/aws/aws-sdk-go v1.34.11 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/google/uuid v1.1.1 // indirect + github.com/gruntwork-io/terratest v0.16.0 + github.com/pquerna/otp v1.2.0 // indirect + github.com/stretchr/testify v1.5.1 + golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect + golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e // indirect +) diff --git a/test/src/go.sum b/test/src/go.sum new file mode 100644 index 00000000..043d3605 --- /dev/null +++ b/test/src/go.sum @@ -0,0 +1,41 @@ +github.com/aws/aws-sdk-go v1.34.11 h1:QF9Gp3vvgIXsp7p5cYS0t7eRkauU3zM2OW4RN6FtYp0= +github.com/aws/aws-sdk-go v1.34.11/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= +github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI= +github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gruntwork-io/terratest v0.16.0 h1:8dDdkAzqwVDclmefcy//oBPWs5bVrWuKYCUwG0WFG4c= +github.com/gruntwork-io/terratest v0.16.0/go.mod h1:NjUn6YXA5Skxt8Rs20t3isYx5Rl+EgvGB8/+RRXddqk= +github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= +github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pquerna/otp v1.2.0 h1:/A3+Jn+cagqayeR3iHs/L62m5ue7710D35zl1zJ1kok= +github.com/pquerna/otp v1.2.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e h1:Pzdi8HRppinixnWWzN6KSa0QkBM+GKsTJaWwwfJskNw= +golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/variables.tf b/variables.tf index a8a46e71..980562c5 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,3 @@ -variable "enabled" { - type = bool - default = true - description = "Set to false to prevent the module from creating any resources" -} - variable "subnet_type_tag_key" { type = string default = "cpco.io/subnet/type" @@ -113,93 +107,3 @@ variable "public_subnets_additional_tags" { description = "Additional tags to be added to public subnets" } -variable "additional_tag_map" { - type = map(string) - default = {} - description = "Additional tags for appending to each tag map" -} - -variable "label_order" { - type = list(string) - 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(string) - 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 'cluster'" -} - -variable "environment" { - type = string - description = "The environment name if not using stage" - default = "" -} - -variable "attributes" { - type = list(string) - 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 = object({ - namespace = string - environment = string - stage = string - name = string - enabled = bool - delimiter = string - attributes = list(string) - label_order = list(string) - tags = map(string) - additional_tag_map = map(string) - regex_replace_chars = string - }) - default = { - namespace = "" - environment = "" - stage = "" - name = "" - enabled = true - delimiter = "" - attributes = [] - label_order = [] - tags = {} - additional_tag_map = {} - regex_replace_chars = "" - } - description = "Default context to use for passing state between label invocations" -} - diff --git a/versions.tf b/versions.tf index 65d7568b..5d534833 100644 --- a/versions.tf +++ b/versions.tf @@ -2,7 +2,7 @@ terraform { required_version = ">= 0.12.0, < 0.14.0" required_providers { - aws = "~> 2.0" + aws = ">= 2.0, < 4.0" template = "~> 2.0" local = "~> 1.2" null = "~> 2.0"