Skip to content

Commit

Permalink
feature(tgw): add support for multiple cross-region connections (#923)
Browse files Browse the repository at this point in the history
Co-authored-by: cloudpossebot <[email protected]>
  • Loading branch information
mcalhoun and cloudpossebot authored Dec 7, 2023
1 parent 4cb4c36 commit 589d875
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions modules/tgw/spoke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ atmos terraform apply tgw/spoke -s <tenant>-<environment>-<stage>
| <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 |
| <a name="input_connections"></a> [connections](#input\_connections) | A list of objects to define each TGW connections.<br><br>By default, each connection will look for only the default `vpc` component. | <pre>list(object({<br> account = object({<br> stage = string<br> environment = optional(string, "")<br> tenant = optional(string, "")<br> })<br> vpc_component_names = optional(list(string), ["vpc"])<br> eks_component_names = optional(list(string), [])<br> }))</pre> | `[]` | no |
| <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 |
| <a name="input_cross_region_hub_connector_components"></a> [cross\_region\_hub\_connector\_components](#input\_cross\_region\_hub\_connector\_components) | A map of cross-region hub connector components that provide this spoke with the appropriate Transit Gateway attachments IDs.<br>- The key should be the environment that the remote VPC is located in.<br>- The component is the name of the compoent in the remote region (e.g. `tgw/cross-region-hub-connector`)<br>- The environment is the region that the cross-region-hub-connector is deployed in.<br>e.g. the following would configure a component called `tgw/cross-region-hub-connector/use1` that is deployed in the<br>If use2 is the primary region, the following would be its configuration:<br>use1:<br> component: "tgw/cross-region-hub-connector"<br> environment: "use1" (the remote region)<br>and in the alternate region, the following would be its configuration:<br>use2:<br> component: "tgw/cross-region-hub-connector"<br> environment: "use1" (our own region) | `map(object({ component = string, environment = string }))` | `{}` | no |
| <a name="input_default_route_enabled"></a> [default\_route\_enabled](#input\_default\_route\_enabled) | Enable default routing via transit gateway, requires also nat gateway and instance to be disabled in vpc component. Default is disabled. | `bool` | `false` | no |
| <a name="input_default_route_outgoing_account_name"></a> [default\_route\_outgoing\_account\_name](#input\_default\_route\_outgoing\_account\_name) | The account name which is used for outgoing traffic, when using the transit gateway as default route. | `string` | `null` | no |
| <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 |
Expand Down
8 changes: 1 addition & 7 deletions modules/tgw/spoke/remote-state.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
locals {
# Any cross region connection requires a TGW Hub connector deployed
# If any connections given are cross-region, get the `tgw/cross-region-hub-connector` component from that region
connected_environments = distinct(compact(concat([for c in var.connections : c.account.environment], [module.this.environment])))
}

module "tgw_hub" {
source = "cloudposse/stack-config/yaml//modules/remote-state"
version = "1.5.0"
Expand All @@ -28,7 +22,7 @@ module "cross_region_hub_connector" {
source = "cloudposse/stack-config/yaml//modules/remote-state"
version = "1.5.0"

for_each = toset(local.connected_environments)
for_each = var.cross_region_hub_connector_components

component = "tgw/cross-region-hub-connector"
tenant = length(var.tgw_hub_tenant_name) > 0 ? var.tgw_hub_tenant_name : module.this.tenant
Expand Down
20 changes: 20 additions & 0 deletions modules/tgw/spoke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,23 @@ variable "default_route_outgoing_account_name" {
description = "The account name which is used for outgoing traffic, when using the transit gateway as default route."
default = null
}

variable "cross_region_hub_connector_components" {
type = map(object({ component = string, environment = string }))
description = <<-EOT
A map of cross-region hub connector components that provide this spoke with the appropriate Transit Gateway attachments IDs.
- The key should be the environment that the remote VPC is located in.
- The component is the name of the compoent in the remote region (e.g. `tgw/cross-region-hub-connector`)
- The environment is the region that the cross-region-hub-connector is deployed in.
e.g. the following would configure a component called `tgw/cross-region-hub-connector/use1` that is deployed in the
If use2 is the primary region, the following would be its configuration:
use1:
component: "tgw/cross-region-hub-connector"
environment: "use1" (the remote region)
and in the alternate region, the following would be its configuration:
use2:
component: "tgw/cross-region-hub-connector"
environment: "use1" (our own region)
EOT
default = {}
}

0 comments on commit 589d875

Please sign in to comment.