Terraform & IaC
The suecodelabs/outbound provider onboards AWS accounts and replaces NAT gateways with Multistax Outbound gateways from the same Terraform or OpenTofu configuration as your VPC. It only calls the Multistax Outbound API: the control plane launches the gateways, allocates their Elastic IPs and owns the private subnets’ default routes.
Set up the provider
Section titled “Set up the provider”Create a token under Settings → API Tokens (admins only). The token carries your tenant and the role you pick; use admin for Terraform that changes networks. Pass it as an environment variable, not in code:
export OUTBOUND_API_TOKEN=outbound_tok_...terraform { required_providers { outbound = { source = "suecodelabs/outbound" } }}
provider "outbound" { endpoint = "https://api.outbound.cloudphilos.net"}Onboard the AWS account
Section titled “Onboard the AWS account”The onboarding stack grants Multistax Outbound a cross-account role. The external ID is your tenant’s own, so take it from the outbound_onboarding data source:
data "aws_caller_identity" "current" {}
data "outbound_onboarding" "aws" { cloud = "aws"}
resource "aws_cloudformation_stack" "outbound" { name = "outbound-onboarding" template_url = data.outbound_onboarding.aws.template_url capabilities = ["CAPABILITY_NAMED_IAM"]
parameters = { ExternalId = data.outbound_onboarding.aws.external_id CloudPhilosAccountId = data.outbound_onboarding.aws.trusted_account_id }}
resource "outbound_cloud_account" "this" { cloud = "aws" account_name = "production"
aws { account_id = data.aws_caller_identity.current.account_id role_arn = aws_cloudformation_stack.outbound.outputs["CloudPhilosNetworksRoleArn"] external_id = data.outbound_onboarding.aws.external_id regions = ["eu-west-1"] }}Accounts onboarded in the console can be adopted with terraform import outbound_cloud_account.this <account-id>.
New VPC without a NAT gateway
Section titled “New VPC without a NAT gateway”Create the VPC without NAT gateways and let Multistax Outbound add the default routes. instance_type is required here: there is no traffic yet to size from.
module "vpc" { source = "terraform-aws-modules/vpc/aws"
name = "main" cidr = "10.0.0.0/16" azs = ["eu-west-1a", "eu-west-1b"] public_subnets = ["10.0.0.0/24", "10.0.1.0/24"] private_subnets = ["10.0.10.0/24", "10.0.11.0/24"]
enable_nat_gateway = false}
resource "outbound_network" "main" { cloud_account_id = data.aws_caller_identity.current.account_id
aws { region = "eu-west-1" vpc_id = module.vpc.vpc_id }
# One gateway per AZ, serving that AZ's private subnet. dynamic "gateway" { for_each = range(length(module.vpc.public_subnets)) content { public_subnet_id = module.vpc.public_subnets[gateway.value] private_subnet_ids = [module.vpc.private_subnets[gateway.value]] } }
instance_type = "t4g.nano"
# The VPC must be complete (internet gateway route included) before Outbound scans it. depends_on = [module.vpc]}
output "egress_ips" { value = outbound_network.main.egress_ips}apply returns once the gateways run and the routes point at them; egress_ips holds the addresses for your allowlists.
Replace an existing NAT gateway
Section titled “Replace an existing NAT gateway”One apply: Terraform forgets the NAT gateway, its Elastic IP and the default routes without destroying them, and outbound_network takes over. Multistax Outbound repoints the routes, then deletes the old NAT gateway (set retain_replaced_nat_gateway = true to keep it). For a terraform-aws-modules/vpc VPC:
module "vpc" { # ...unchanged... enable_nat_gateway = false # was true}
removed { from = module.vpc.aws_nat_gateway.this lifecycle { destroy = false }}
removed { from = module.vpc.aws_eip.nat lifecycle { destroy = false }}
removed { from = module.vpc.aws_route.private_nat_gateway lifecycle { destroy = false }}
resource "outbound_network" "main" { # as above}The plan must show the three resources as “will no longer be managed”, not destroyed, plus the new outbound_network. removed blocks with lifecycle need Terraform ≥ 1.7. On older versions, or an OpenTofu version that rejects the lifecycle block, run terraform state rm (or tofu state rm) on the same addresses first. With your own resources instead of a module, use their addresses (aws_nat_gateway.main, aws_eip.nat, aws_route.private_default).
The replaced NAT gateway’s Elastic IP is not carried over: your egress IPs change to the new egress_ips. Update allowlists before the cutover.
Adopt a network onboarded in the console
Section titled “Adopt a network onboarded in the console”apply refuses to create a network that is already enabled. Import it instead; the ID is <account-id>_<region>_<vpc-id>:
terraform import outbound_network.main 123456789012_eu-west-1_vpc-0abc123Then align the gateway blocks and instance_type with what the plan shows, until it shows no changes.
Changes made in the console
Section titled “Changes made in the console”You can keep using the console. Changes made there show up as drift in the next plan, and apply sets them back to your configuration. If someone changes the network between your plan and apply, the apply fails instead of overwriting their change — run plan again.
Destroy and go back to a NAT gateway
Section titled “Destroy and go back to a NAT gateway”Destroying an outbound_network disables the network: Multistax Outbound deletes the default routes it manages and terminates the gateways. The private subnets have no egress until you add a NAT gateway again. The pooled Elastic IPs are kept so a later re-enable gets the same egress IPs; set release_ips_on_destroy = true before destroying to release them. The outbound_cloud_account cannot be destroyed while a network still holds Elastic IPs.
Use two applies, so the new NAT route doesn’t collide with the route Outbound still owns:
- Remove the
outbound_networkresource (orterraform destroy -target=outbound_network.main) and apply. Wait for it to finish. - Set
enable_nat_gateway = true(or re-add youraws_nat_gateway,aws_eipandaws_routeresources) and apply.
See Offboarding for leaving Multistax Outbound entirely.
What Outbound owns
Section titled “What Outbound owns”A resource can only have one owner. While a network is enabled:
- Default routes (
0.0.0.0/0in managed private subnets) point at the Multistax Outbound gateway. If Terraform still has the old route in state,applyreverts it to your old NAT gateway — and if that NAT gateway is gone, egress breaks outright. - Elastic IPs: Multistax Outbound allocates the gateway EIPs and keeps a spare pool (tagged
do-not-delete-cloudphilos-gateway) that preserves your egress IP across replacements. If Terraform manages these, adestroyor drift correction can release your static egress IP for good. - NAT gateways: after cutover the replaced NAT gateway is deleted. If it is still in state,
applyrecreates it: an idle NAT gateway you pay for.
You can recognize Multistax Outbound-managed resources by their tags: instances Name=cloudphilos-gateway, security groups cloudphilos-gateway-<vpc-id>, Elastic IPs Name=do-not-delete-cloudphilos-gateway. Never import these into Terraform, and never delete them by hand.
Onboarding in the console with Terraform-managed VPCs
Section titled “Onboarding in the console with Terraform-managed VPCs”If you enable networks in the console rather than with the provider, remove the same three kinds of resources from state before enabling the network, with the removed blocks above or terraform state rm:
terraform state rm 'aws_route.private_default'terraform state rm 'aws_nat_gateway.main'terraform state rm 'aws_eip.nat'
# with count/for_each, quote the index:terraform state rm 'aws_route.private_default["eu-west-1a"]'Then delete the resource blocks so a later apply doesn’t recreate them.
Inline route {} blocks on an aws_route_table can’t be removed from state individually. Migrate them to standalone aws_route resources first (preferred), or ignore the table’s routes:
resource "aws_route_table" "private" { vpc_id = aws_vpc.main.id
lifecycle { ignore_changes = [route] }}ignore_changes = [route] ignores all route drift on that table, including routes you still consider yours — acceptable for tables whose only variable route is the default route.
Verifying you’re clean
Section titled “Verifying you’re clean”terraform plan must show no changes to default routes, NAT gateways, or EIPs in managed VPCs. If it proposes replacing a route target or creating a NAT gateway, something is still in state — resolve it before applying anything.
Teams with automated applies should add a plan check that fails on changes to aws_route, aws_nat_gateway, or aws_eip in managed VPCs (for example by inspecting terraform show -json plan.out). It turns an outage into a failed pipeline.