Skip to content

About

AWS account and EKS cluster in Terraform, with a CI pipeline that stores no AWS credentials.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

aws-landing-zone

The AWS account Kestrel runs in: one VPC, one EKS cluster, two environments, and a CI pipeline that holds no AWS credentials.

License Terraform AWS CI

The scenario

Kestrel is a small European logistics company with one product and no dedicated platform team. It needs an AWS account that is boring: two environments that differ only in the ways they should, state that cannot be corrupted by two people running apply at once, and a deploy pipeline that does not require handing long-lived AWS keys to GitHub.

That last part is the interesting one. There is no AWS_ACCESS_KEY_ID in this repository's secrets. GitHub mints a signed OIDC token that says which repo and which branch is asking, AWS trusts that specific combination and nothing else, and CI gets credentials that expire in an hour. There is no key to rotate, and a leaked repository secret would be worth nothing because there isn't one.

What gets built

flowchart TB
    subgraph gh["GitHub"]
        pr["Pull request"] -->|"plan, commented on the PR"| oidc
        main["Merge to main"] -->|"apply, gated on an environment"| oidc
        oidc(["OIDC token<br/>no stored credentials"])
    end

    oidc -->|"sts:AssumeRoleWithWebIdentity"| role["IAM role<br/>trusts only this repo + branch"]

    subgraph aws["AWS account (eu-west-1)"]
        role --> state[("S3 state bucket<br/>+ DynamoDB lock table")]

        subgraph vpc["VPC 10.30.0.0/16"]
            direction LR
            subgraph az_a["eu-west-1a"]
                pub_a["public /20<br/>NAT · ALB"]
                priv_a["private /20<br/>EKS nodes"]
            end
            subgraph az_b["eu-west-1b"]
                pub_b["public /20<br/>NAT · ALB"]
                priv_b["private /20<br/>EKS nodes"]
            end
        end

        role --> eks["EKS control plane<br/>access entries · audit logs"]
        eks --> priv_a
        eks --> priv_b
        eks --> irsa["IRSA roles<br/>EBS CSI · ALB controller · external-dns"]
    end
Loading

Try it without spending anything

Everything except apply runs offline with no AWS account:

git clone https://github.com/thisiskazem/aws-landing-zone
cd aws-landing-zone
make check     # fmt + validate + tflint across all 5 directories

To actually build it, apply bootstrap/ once by hand (it creates the state backend and the CI role), put the bucket name into envs/*/backend.tf, then:

make plan ENV=dev
make apply ENV=dev      # ~138 EUR/month if left running
make destroy ENV=dev    # do this when you are done

Cost

Worth stating plainly, because "I forgot it was running" is the most common way a learning AWS account produces a surprising bill.

dev prod
NAT gateways 1 (~33 EUR) 2 (~66 EUR)
EKS control plane ~70 EUR ~70 EUR
Nodes 2 x t3.large Spot (~35 EUR) 3 x m6i.large on-demand (~190 EUR)
Fixed monthly total ~138 EUR ~326 EUR

make cost ENV=dev prints this from Terraform outputs. make destroy ENV=dev takes it back to zero.

What is in here

bootstrap/          S3 state bucket, DynamoDB lock table, GitHub OIDC provider and role
                    Applied once, by hand. Keeps its own state locally, by necessity.
modules/network/    VPC, public/private subnets across 2 AZs, NAT, flow logs
modules/platform/   EKS via terraform-aws-modules/eks v21, addons, three IRSA roles
envs/dev/           Spot nodes, one NAT, 7-day log retention
envs/prod/          On-demand nodes, NAT per AZ, 90-day retention
.github/workflows/  validate everywhere · plan on PR · apply gated on an environment

What this demonstrates

Skill Where to look
Terraform module design modules/network/: derived CIDRs, validated inputs, no hardcoded values
Knowing what not to build modules/platform/main.tf: the EKS control plane comes from upstream
AWS networking modules/network/README.md: CIDR plan, subnet tags the ALB controller needs
IAM and least privilege bootstrap/main.tf: OIDC trust policy scoped to named branches, IRSA per service account
EKS operations access entries over aws-auth, IMDSv2 hop limit 1, prefix delegation, audit logs
GitHub Actions .github/workflows/terraform.yaml: plan-on-PR, saved plan applied unchanged
Cost awareness NAT topology as a variable, Spot in dev, cost in the outputs

Deliberate trade-offs

  • The EKS module is not hand-written. Reimplementing 4000 lines of launch templates and addon ordering would look impressive and be worse. The hand-written module is network/, where the decisions are actually mine.
  • The CI role has AdministratorAccess. Terraform needs to create and destroy nearly anything, so a hand-scoped policy grows on every new resource type and gets a wildcard added during the first incident anyway. The control that carries the weight is the trust policy: only named branches of one named repository can assume it at all.
  • The API endpoint is public with a CIDR allowlist, not fully private. A private cluster needs a bastion or VPN for every kubectl command and for Argo CD to reach the API. 0.0.0.0/0 is rejected by a variable validation.
  • Two AZs, not three. The third adds a third NAT gateway and a third of everything to survive a failure mode two AZs already handle.
  • State is encrypted with SSE-S3, not a customer-managed KMS key. KMS is stronger and means every principal reading state also needs kms:Decrypt. For a single-account setup that is complexity without a matching threat.
  • No RDS, ALB, WAF or CloudFront. They would each be twenty more files demonstrating nothing this repository does not already show.

Related

The workloads that run on this cluster are delivered by gitops-k8s-platform.

Author

Kazem Bigdeli · Cloud, DevOps & Platform Engineer · Turin, Italy linkedin.com/in/kazembigdeli

About

AWS account and EKS cluster in Terraform, with a CI pipeline that stores no AWS credentials.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages