This OpenTofu module provisions foundational networking infrastructure in spoke VPCs that host business applications or workloads. It helps to quickly set up basic networking required by workloads in a multi-account hub-spoke network topology on AWS, where all ingress and egress traffic to/from the workload VPC passes through a hub VPC (in another AWS account) via a Transit Gateway (TGW).
- Provisions the following network infrastructure in a spoke AWS account:
- A VPC with subnets
- TGW share acceptance and TGW attachments
- Route tables with local and TGW-bound routes
- DHCP options set with custom DNS settings
- Security Groups for workloads
- Leverages the cloudposse terraform-null-label module to assign standardized names to provisioned resources.
- Applies tags consistently to provisioned resources.
- The TGW set up in the
network services
AWS account must be shared with theworkload
AWS account via Resource Access Manager (RAM) and theTGW share ARN
must be made available. Ideally, if the TGW share is automated via OpenTofu, then the ARN may be accessed from OpenTofu state. - The
TGW ID
must be made available. Ideally, if the TGW provisioning is automated via OpenTofu, then the TGW ID may be accessed from OpenTofu state.
Refer to the sales-spoke-vpc example for a complete example of how to use this module.
NOTE: The sales-spoke-vpc
example links the module via relative paths, but you can also link the module via the module registry as shown below.
module "sales-spoke-vpc" {
source = "git::https://github.com/cybergavin/terraform-aws-vpc-spoke-tgw.git?ref=<COMMIT_HASH>" # commit hash for required version
# insert the required variables here
}
Name | Version |
---|---|
terraform | ~> 1.0, >= 1.8 |
aws | ~> 5.0 |
Name | Version |
---|---|
aws | ~> 5.0 |
Name | Source | Version |
---|---|---|
networking_base_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_dop_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_rtb_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_sg_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_subnet_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_tgw_attachment_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
networking_vpc_label | git::https://github.com/cloudposse/terraform-null-label.git | 488ab91e34a24a86957e397d9f7262ec5925586a |
Name | Type |
---|---|
aws_default_security_group.this | resource |
aws_ec2_transit_gateway_vpc_attachment.this | resource |
aws_ram_resource_share_accepter.this | resource |
aws_route.tgw_route | resource |
aws_route_table.this | resource |
aws_route_table_association.this | resource |
aws_security_group.this | resource |
aws_subnet.this | resource |
aws_vpc.this | resource |
aws_vpc_dhcp_options.this | resource |
aws_vpc_dhcp_options_association.this | resource |
aws_vpc_security_group_egress_rule.this | resource |
aws_vpc_security_group_ingress_rule.this | resource |
aws_availability_zones.current | data source |
aws_region.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
app_id | The universally unique application ID for the service. Only alphanumeric characters are valid, with a string length from 3 to 8 characters. | string |
"appid" |
no |
dns_domain | Domain name for DHCP option set | string |
"" |
no |
dns_servers | List of custom DNS servers to use | list(string) |
[] |
no |
environment | A valid Infrastructure Environment | string |
"poc" |
no |
global_tags | A map of global tags to apply to all resources. | map(string) |
{} |
no |
org | A name or abbreviation for the Organization. Only alphanumeric characters and hyphens are valid, with a string length from 3 to 8 characters. | string |
"acme-it" |
no |
security_groups | List of security groups with associated ingress and egress rules | list(object({ |
n/a | yes |
shared_transit_gateway_arn | The ARN of the Ingress network account's shared Transit Gateway. | string |
n/a | yes |
subnet_cidrs | A map of subnet aliases and their associated list of CIDR blocks across multiple AZs, with an alias length from 3 to 8 lowercase alphanumeric characters and valid CIDR blocks. | map(list(string)) |
{} |
no |
tgw_sharing_enabled | Enable or disable the Transit Gateway sharing and attachment resources. Set to true to create the resources. | bool |
false |
no |
transit_gateway_id | Transit Gateway ID for the peering connection. TBD: Obtain output from another tofu module. | string |
n/a | yes |
vpc_cidr | The CIDR block for the VPC | string |
n/a | yes |
Name | Description |
---|---|
security_groups | Map of security groups |
subnets | Map of subnets |
vpc_id | VPC ID |