AWS Fargate infrastructure with Vault workload identity
Individual cloud infrastructure project, 2026
- Role
- Architecture, Terraform implementation, security model, tests, and documentation
- Stack
- AWS, Terraform, ECS Fargate, VPC, ALB, IAM, Vault, CloudWatch
- Scope
- Validated locally; not presented as a live AWS environment
Terraform for running private Fargate workloads, written with production in mind. The task definition contains no cloud credentials and no Vault tokens.
Problem
An identity instead of a static secret
A small service had to be reachable from the internet while its containers stayed private. It also had to read its runtime content from Vault, without a long-lived Vault token or AWS access key sitting in the task definition.
- 2 availability zonesA public and a private subnet in each zone, for the load balancer and for Fargate.
- 0 static tokensA Vault Agent sidecar logs in with the ECS task role through Vault's AWS auth method.
- 3 tested variantsPlans for AWS only, with Vault, and with HTTPS through ACM.
Architecture
Public load balancer, private tasks
↓ private routing, no public task IPs ↓
↓ operations and external secret service ↓
Runtime flow
Log in and fetch secrets before taking traffic
- ECS gives the Vault Agent sidecar rotating task-role credentials.
- The agent signs an AWS IAM request and logs in to a Vault role that is bound to that exact task-role ARN.
- A least-privilege policy only allows reads from the one KV v2 path the app needs.
- The agent writes what it gets back to an ephemeral volume scoped to the task.
- Once that file exists, the app reports healthy and the ALB starts sending it requests.
The app container itself never holds a Vault token or an AWS access key, and it has no permission to read any other secrets. Vault mode is optional: the default plan runs the same service without Vault, and Terraform writes the Vault role and policy before it creates the service.
Delivery
CI that can't deploy by accident
GitHub Actions checks the Terraform formatting, runs init without a backend, validates the configuration, and runs plan tests against mocked AWS and Vault providers, so it needs no credentials. On purpose, the workflow only has read access to the repository and has no cloud credentials at all.
- The Makefile saves a Terraform plan and never applies anything while planning.
- Applying needs a plan that already exists and has been reviewed, plus an explicit
ALLOW_APPLY=yes. - The service has a deployment circuit breaker that rolls back automatically.
- When ACM is configured, HTTP redirects to HTTPS with a modern TLS policy.
Engineering
Reliability, security, and cost
- Network isolationOnly the load balancer is public. The tasks run privately and have no public IP addresses.
- Workload identityCredentials managed by ECS take the place of long-lived keys and static Vault tokens.
- ObservabilityBoth containers log to CloudWatch through awslogs with 30-day retention, and Container Insights is enabled. There are no CloudWatch alarms yet.
- AvailabilityThe subnets cover two availability zones. The service runs 1 to 3 tasks, scaled to keep CPU near 60%, with health checks, rolling replacement, and rollback. With one task and one NAT gateway, it doesn't survive losing a zone.
- CostFargate Spot gets four times the weight of regular Fargate, scaling has fixed limits, and the single NAT gateway is a deliberate tradeoff for a demo.
- ScopeI verified the configuration and the three mocked plan variants locally. I don't present this as production experience with a live AWS deployment.