Status: written, tested with mocked providers, never applied. No AWS account, no credential and no Spacelift stack exists for this code. Do not create the Spacelift stacks
cah-aws-00-foundationorcah-aws-10-accessuntil the maintainer's check of Spacelift's native AWS integration on the current plan has passed (design, section 10, decision 6). If that check fails, return to the maintainer before any fallback to a static key..spacelift/config.ymlhas no AWS entry for the same reason.
This is the AWS twin of stage 0 and stage 1. The shape is the same: a foundation layer, then an access layer that builds two Twingate connectors with no public inbound. The objects underneath differ; the provider pages explain how.
Stack stacks/aws/00-foundation (cost: nothing):
modules/aws/vpc), default range 10.78.0.0/24. The VPC's default security group is emptied.modules/aws/firewall). No stage 1 machine wears it (an instance carries exactly one group); it is the deny-all starting point for later stages.us-east-1, the region the price table was recorded for) and a Project default tag. It names no account id, profile, key or role. Credentials come from the environment at run time.vpc_id, vpc_ip_range, subnet_id, baseline_security_group_id, region.Stack stacks/aws/10-access (cost: $20.84 a month):
access-<region>, the group cah-<region>-admins, and one restricted SSH resource per connector (TCP 22 only, UDP denied, no ICMP), the same as the DigitalOcean stack.t4g.micro instances, access-<region>-connector-a and -b, each running a Twingate connector (the shared modules/twingate-bootstrap). Each has a public IPv4 address, an 8 GiB encrypted gp3 root volume, standard CPU credits, IMDSv2 required, no key pair and no instance profile.connector_private_ips (keys a and b), connector_security_group_id.Values pass between the stacks the way they do on DigitalOcean: Spacelift stack dependencies mapped to TF_VAR_* variables, no remote state.
Opt-in metrics (issue #99, AWS half; all off by default, the plan is a no-op). node_exporter and node_exporter_instances install a node exporter bound to each connector's private address; metrics_source_security_group_id (an sg-... id you supply, empty by default) admits the enabled metrics ports (the exporter's, and connector_telemetry.metrics_port with its previous value during a rollout) from that one security group only, as inbound_from_other_groups of the firewall module: never a CIDR, an IPv6 range or a prefix list. Turning the exporter on changes user_data, so it REPLACES the instance (and its public address, there is no Elastic IP) of every connector in node_exporter_instances: roll out ["a"], check SSH through Twingate, then ["a", "b"]. Setting only the source group (or only the telemetry port) changes the security group and replaces no instance. The group must exist in the same VPC and is not created here. It must be a different group from the connector group: naming the connector group itself is refused (a precondition in the firewall module and on the stack output), because it would admit connector-to-connector metrics, which this change does not offer. Changing the source group is a different rule key, so the plan removes the old rule and adds the new one in the same apply and AWS may briefly hold both (or, if the add runs first, a duplicate-rule conflict can fail the apply). Do it in two applies: first set metrics_source_security_group_id = "" and apply (the old rules go), then set the new group and apply (the new rules arrive). Metrics are unscrapable between the two applies; that is expected. This is written and mock-tested only: nothing is applied, no Spacelift stack exists for these AWS stacks, and Spacelift's native AWS integration is still unchecked, so do not assume it works. Details and limits: stage 2, section 2.3. Log shipping is not offered on AWS yet.
What the tests prove (tofu test, mocked providers, no account needed): names and wiring; instance type and root size read from cost.json; two connectors with distinct reboot times; the connector group has exactly the member-only SSH rule and no inbound from an address anywhere; the baseline has zero inbound; with the metrics inputs on, the exact ingress list (member SSH plus the enabled metrics ports from the one source group); the golden user_data hashes at the default; outputs; and that no stack file names an account id, profile, key or role. What they cannot prove is in section 7.
ssm:GetParameter on Canonical's public path /aws/service/canonical/ubuntu/server/24.04/stable/current/arm64/hvm/ebs-gp3/ami-id, plus the EC2 permissions to create the objects above. Scope it to the one region.prd config. That config holds DIGITALOCEAN_TOKEN, and its service token can read the whole config whatever names the hook asks for, so an AWS run holding it could read the DigitalOcean credential. Create the AWS-only config (8a proposes project cah, config dev_aws) holding TWINGATE_API_TOKEN, TWINGATE_NETWORK, ADMIN_SSH_PUBLIC_KEY and ADMIN_USER_IDS (ADMIN_SSH_KEY_NAME is not used on AWS: there is no key pair), its own read-only service token, and its own Spacelift context (8a proposes cah-doppler-aws). Label the AWS stacks with a cloud label such as cah-aws, so the existing cah-doppler context does not auto-attach to them (a stack must never receive two tokens). Attach the push policy to the AWS stacks before any secret context (the policy autoattaches on the cah label, which the AWS stacks no longer carry): attach it manually or extend its autoattach labels. No AWS secret goes in Doppler if the native integration is available.10.78.0.0/24 overlaps no homelab range, or set vpc_ip_range.Phase id aws-twin, planned, proposed ceiling $30. Planned $20.84 a month (two t4g.micro at $0.0084 an hour, two public IPv4 addresses at $0.005 an hour, two 8 GiB gp3 volumes at $0.08 per GiB-month), against an approved $21.00 for AWS. The current phase's ceiling (stage-1, $30) applies, and DigitalOcean stage 1 ($12) plus AWS ($21) would be $33, so apply this only while the DigitalOcean access stage is torn down. Data transfer and anything created outside OpenTofu are not priced; a billing alert only notifies. See cost and the AWS cost lesson.
The cost switch is two flags, not one. providers.digitalocean.active is true today and providers.aws.active is false. Turning only AWS on fails the gate. Order of operations:
docs/stages/approved.json set providers.digitalocean.active to false and providers.aws.active to true, in one reviewed change.The gate for each state, run on copies of the repository with only the flags changed:
digitalocean.active |
aws.active |
Result |
|---|---|---|
| true | false (today) | passes: aws inactive, digitalocean $12.00 active |
| false | true (the AWS stage) | passes: aws $20.84 against $21.00 active, digitalocean inactive |
| true | true | fails: the approved figures of the active providers add up to $33.00, above the shared ceiling $30.00 (the message keeps the wording "shared ceiling"; the ceiling is the current phase's) |
| false | false | passes (nothing is attested as applied) |
python3 -I scripts/cost_check.py --root . reports aws: planned $20.84/mo, approved $21.00, inactive today. Once a trusted run produces a real plan, run the gate with --plan plan.json --stack stacks/aws/10-access before the first apply; it prices what the plan resolves, which source code can hide.
Order on every instance: update, baseline, harden, then applications. The AWS connectors use the same cloud-init template as the DigitalOcean ones (modules/twingate-bootstrap), so the order is the one in the stage 1 guide and the first-hour lesson: update and automatic security updates first, a baseline you take by hand, the hardening, and the connector last. Amazon Linux behaves differently from Ubuntu at launch (see the lesson); this stack uses the Ubuntu image path through the shared template.
cah-aws-00-foundation rooted at stacks/aws/00-foundation, labeled cah-aws (not cah), with the push policy attached first, then the AWS integration and the cah-doppler-aws context, and TF_VAR_region set.cah-aws-10-access rooted at stacks/aws/10-access, labeled cah-aws, push policy first, then the same AWS integration and the cah-doppler-aws context attached to this stack too (a stack dependency passes the mapped outputs, not credentials, so the access stack gets none from the foundation stack). It depends on the foundation stack, with this mapping:| Foundation output | Environment variable |
|---|---|
| vpc_id | TF_VAR_vpc_id |
| subnet_id | TF_VAR_subnet_id |
| region | TF_VAR_region |
The Doppler hook must export TF_VAR_twingate_network, TF_VAR_admin_ssh_public_key and TF_VAR_admin_user_ids for this stack, as it does for the DigitalOcean one.
access-<region> exists in the console (a hand-made one makes the apply fail or leaves a duplicate)..spacelift/config.yml and the CI trigger paths in that same change, then run tracked. Autodeploy stays off; read the plan, then confirm.access-<region>.ssh cah-admin@<private ip> works for each address in connector_private_ips.nmap -Pn -p 22,80,443 <connector public ip> shows the ports filtered (scanning your own instance is authorized).python3 -I scripts/cost_check.py --root . still reports the planned AWS figure, and the AWS bill for the first day matches two instances, two public addresses and two 8 GiB volumes.Destroy cah-aws-10-access first, then cah-aws-00-foundation; the VPC is in use by the access stack until then. The connector tokens die with the instances and the Twingate site goes with the stack. Afterwards confirm in the console that no instance, volume or public address remains (an address left allocated keeps billing), then, if DigitalOcean stage 1 is returning, reverse both flags in approved.json in one change: providers.aws.active to false and providers.digitalocean.active to true. To rotate a token or the admin key, replace one connector at a time as in stage 1 section 3; a changed cloud-init replaces the instance (user_data_replace_on_change) and probably changes its private address.
If a connector is offline, use the other one for SSH, then sudo systemctl status twingate-connector and sudo cat /var/log/cah-connector-install.log, as in stage 1 section 6a. There is no AWS key pair and no console password path by design, so a total loss of both connectors is recovered by replacing them in a run.
Mocked tests show the shape of the code, not AWS's behavior. Keep the command output with the apply notes. Everything below is UNVERIFIED until then.
From the vpc module:
describe-security-group-rules filtered to it).0.0.0.0/0 to the internet gateway; the subnet does not use the main table.From the firewall module:
aws ec2 describe-security-group-rules for the connector group: the seven outbound rules to 0.0.0.0/0, the member rules (TCP 22 in and out, source and destination the group itself), no every-protocol (-1) egress rule, no inbound rule from 0.0.0.0/0 or ::/0; when metrics_source_security_group_id is set, one more inbound rule per enabled metrics port whose source is that group and nothing else. The baseline group: five outbound rules, no inbound. Repeat after any manual console change (drift in a rule added outside the code is not detected).From the twingate-connector module:
aws ec2 describe-instances: HttpTokens=required, hop limit 1, no IAM instance profile, no key name, CpuCredits=standard.t4g.micro.cloud-init status --wait (through Twingate) completed and the connector is healthy in the console.From these stacks:
DIGITALOCEAN_TOKEN through the AWS context and confirm the hook fails with could not read DIGITALOCEAN_TOKEN from Doppler. Also confirm the cah-doppler context is not attached to either AWS stack, and the push policy is attached to both.tofu plan shows no Project tag drift on any resource (default tags interacting with module resources is untested against AWS).