From cd9070d36b6b837e9b5b51fdc2bbfd75b813348c Mon Sep 17 00:00:00 2001 From: Johan Lanzrein Date: Fri, 10 Nov 2023 04:00:55 +0100 Subject: [PATCH] Add support for network address usage metrics (#124) Co-authored-by: Johan Lanzrein --- README.md | 1 + docs/terraform.md | 1 + examples/complete/fixtures.us-east-2.tfvars | 7 ++++--- examples/complete/main.tf | 10 +++++----- examples/complete/variables.tf | 4 ++++ main.tf | 11 ++++++----- variables.tf | 6 ++++++ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e4dbfe9..e67516f 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,7 @@ Available targets: | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | +| [network\_address\_usage\_metrics\_enabled](#input\_network\_address\_usage\_metrics\_enabled) | Set `true` to enable Network Address Usage Metrics for the VPC | `bool` | `false` | no | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 264555c..8e77a9d 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -67,6 +67,7 @@ | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | +| [network\_address\_usage\_metrics\_enabled](#input\_network\_address\_usage\_metrics\_enabled) | Set `true` to enable Network Address Usage Metrics for the VPC | `bool` | `false` | no | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no | diff --git a/examples/complete/fixtures.us-east-2.tfvars b/examples/complete/fixtures.us-east-2.tfvars index c256c96..b650c4c 100644 --- a/examples/complete/fixtures.us-east-2.tfvars +++ b/examples/complete/fixtures.us-east-2.tfvars @@ -8,6 +8,7 @@ stage = "test" name = "vpc-subnets" -default_security_group_deny_all = true -default_route_table_no_routes = true -default_network_acl_deny_all = true +default_security_group_deny_all = true +default_route_table_no_routes = true +default_network_acl_deny_all = true +network_address_usage_metrics_enabled = true \ No newline at end of file diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 4cc8059..cc1c73c 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -20,11 +20,11 @@ module "vpc" { assign_generated_ipv6_cidr_block = true - default_security_group_deny_all = var.default_security_group_deny_all - default_route_table_no_routes = var.default_route_table_no_routes - default_network_acl_deny_all = var.default_network_acl_deny_all - - context = module.this.context + default_security_group_deny_all = var.default_security_group_deny_all + default_route_table_no_routes = var.default_route_table_no_routes + default_network_acl_deny_all = var.default_network_acl_deny_all + network_address_usage_metrics_enabled = var.network_address_usage_metrics_enabled + context = module.this.context } module "subnets" { diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index b31a708..cc36a95 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -17,3 +17,7 @@ variable "default_route_table_no_routes" { variable "default_network_acl_deny_all" { type = bool } + +variable "network_address_usage_metrics_enabled" { + type = bool +} diff --git a/main.tf b/main.tf index 304cbb6..6326a70 100644 --- a/main.tf +++ b/main.tf @@ -41,11 +41,12 @@ resource "aws_vpc" "default" { ipv6_netmask_length = try(var.ipv6_primary_cidr_block_association.ipv6_netmask_length, null) # Additional IPv6 CIDRs are handled by aws_vpc_ipv6_cidr_block_association below - instance_tenancy = var.instance_tenancy - enable_dns_hostnames = local.dns_hostnames_enabled - enable_dns_support = local.dns_support_enabled - assign_generated_ipv6_cidr_block = local.assign_generated_ipv6_cidr_block - tags = module.label.tags + instance_tenancy = var.instance_tenancy + enable_dns_hostnames = local.dns_hostnames_enabled + enable_dns_support = local.dns_support_enabled + assign_generated_ipv6_cidr_block = local.assign_generated_ipv6_cidr_block + enable_network_address_usage_metrics = var.network_address_usage_metrics_enabled + tags = module.label.tags } # If `aws_default_security_group` is not defined, it will be created implicitly with access `0.0.0.0/0` diff --git a/variables.tf b/variables.tf index 8d66c60..2f4123e 100644 --- a/variables.tf +++ b/variables.tf @@ -155,3 +155,9 @@ variable "ipv6_egress_only_internet_gateway_enabled" { description = "Set `true` to create an IPv6 Egress-Only Internet Gateway for the VPC" default = false } + +variable "network_address_usage_metrics_enabled" { + type = bool + description = "Set `true` to enable Network Address Usage Metrics for the VPC" + default = false +} \ No newline at end of file