Skip to content

Commit f1f7c57

Browse files
Allow nullification of customer_gateway_ip_address (#39)
* feat(tf): Make more variables optional * feat(tf): Base creation of resources on existing variables * fix(typo) * fix(tf): Set variable to null by default * fix(docs): Regenerate documentation --------- Co-authored-by: Andriy Knysh <[email protected]>
1 parent c13622a commit f1f7c57

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Available targets:
142142
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
143143
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
144144
| <a name="input_customer_gateway_bgp_asn"></a> [customer\_gateway\_bgp\_asn](#input\_customer\_gateway\_bgp\_asn) | The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN) | `number` | `65000` | no |
145-
| <a name="input_customer_gateway_ip_address"></a> [customer\_gateway\_ip\_address](#input\_customer\_gateway\_ip\_address) | The IP address of the gateway's Internet-routable external interface | `string` | n/a | yes |
145+
| <a name="input_customer_gateway_ip_address"></a> [customer\_gateway\_ip\_address](#input\_customer\_gateway\_ip\_address) | The IP address of the gateway's Internet-routable external interface. Set to null to not create the customer gateway. | `string` | `null` | no |
146146
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
147147
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
148148
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |

docs/terraform.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
4242
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
4343
| <a name="input_customer_gateway_bgp_asn"></a> [customer\_gateway\_bgp\_asn](#input\_customer\_gateway\_bgp\_asn) | The gateway's Border Gateway Protocol (BGP) Autonomous System Number (ASN) | `number` | `65000` | no |
44-
| <a name="input_customer_gateway_ip_address"></a> [customer\_gateway\_ip\_address](#input\_customer\_gateway\_ip\_address) | The IP address of the gateway's Internet-routable external interface | `string` | n/a | yes |
44+
| <a name="input_customer_gateway_ip_address"></a> [customer\_gateway\_ip\_address](#input\_customer\_gateway\_ip\_address) | The IP address of the gateway's Internet-routable external interface. Set to null to not create the customer gateway. | `string` | `null` | no |
4545
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
4646
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
4747
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ locals {
1212

1313
# https://www.terraform.io/docs/providers/aws/r/vpn_gateway.html
1414
resource "aws_vpn_gateway" "default" {
15-
count = local.enabled && var.transit_gateway_enabled == false ? 1 : 0
15+
count = local.enabled && !var.transit_gateway_enabled ? 1 : 0
1616
vpc_id = var.vpc_id
1717
amazon_side_asn = var.vpn_gateway_amazon_side_asn
1818
tags = module.this.tags
1919
}
2020

2121
# https://www.terraform.io/docs/providers/aws/r/customer_gateway.html
2222
resource "aws_customer_gateway" "default" {
23-
count = local.enabled ? 1 : 0
23+
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
2424
bgp_asn = var.customer_gateway_bgp_asn
2525
ip_address = var.customer_gateway_ip_address
2626
type = "ipsec.1"
@@ -40,7 +40,7 @@ module "logs" {
4040

4141
# https://www.terraform.io/docs/providers/aws/r/vpn_connection.html
4242
resource "aws_vpn_connection" "default" {
43-
count = local.enabled ? 1 : 0
43+
count = local.enabled && var.customer_gateway_ip_address != null ? 1 : 0
4444
vpn_gateway_id = local.transit_gateway_enabled == false ? local.vpn_gateway_id : null
4545
customer_gateway_id = local.customer_gateway_id
4646
transit_gateway_id = local.transit_gateway_enabled ? var.existing_transit_gateway_id : null

variables.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ variable "customer_gateway_bgp_asn" {
1717

1818
variable "customer_gateway_ip_address" {
1919
type = string
20-
description = "The IP address of the gateway's Internet-routable external interface"
20+
description = "The IP address of the gateway's Internet-routable external interface. Set to null to not create the customer gateway."
21+
default = null
2122
}
2223

2324
variable "route_table_ids" {

0 commit comments

Comments
 (0)