From 589d875e6cd0e41a3bde67350ca0182b5e3cc5ab Mon Sep 17 00:00:00 2001 From: Matt Calhoun Date: Thu, 7 Dec 2023 16:43:33 -0500 Subject: [PATCH] feature(tgw): add support for multiple cross-region connections (#923) Co-authored-by: cloudpossebot --- modules/tgw/spoke/README.md | 1 + modules/tgw/spoke/remote-state.tf | 8 +------- modules/tgw/spoke/variables.tf | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/tgw/spoke/README.md b/modules/tgw/spoke/README.md index f2e80dd65..ee096dfad 100644 --- a/modules/tgw/spoke/README.md +++ b/modules/tgw/spoke/README.md @@ -131,6 +131,7 @@ atmos terraform apply tgw/spoke -s -- | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no | | [connections](#input\_connections) | A list of objects to define each TGW connections.

By default, each connection will look for only the default `vpc` component. |
list(object({
account = object({
stage = string
environment = optional(string, "")
tenant = optional(string, "")
})
vpc_component_names = optional(list(string), ["vpc"])
eks_component_names = optional(list(string), [])
}))
| `[]` | no | | [context](#input\_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. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | +| [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.
- 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) | `map(object({ component = string, environment = string }))` | `{}` | no | | [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 | | [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 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | diff --git a/modules/tgw/spoke/remote-state.tf b/modules/tgw/spoke/remote-state.tf index 41e013679..8edd8f2de 100644 --- a/modules/tgw/spoke/remote-state.tf +++ b/modules/tgw/spoke/remote-state.tf @@ -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" @@ -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 diff --git a/modules/tgw/spoke/variables.tf b/modules/tgw/spoke/variables.tf index 752a9e607..c87a0efaf 100644 --- a/modules/tgw/spoke/variables.tf +++ b/modules/tgw/spoke/variables.tf @@ -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 = {} +}