How engineerbetter/iac-example works
Purpose and Entry Points
This is a Continuous Infrastructure-as-Code reference repository. It provisions AWS Kubernetes environments, deploys Sock Shop, validates/policies-tests changes, and promotes successful revisions between environments through Jenkins. Primary operator interface is Makefile; CI entry points are Jenkins pipeline definitions in pipelines/deploy.Jenkinsfile, pipelines/destroy.Jenkinsfile, and promotion job configuration pipelines/push-git-branch.xml.
Environment and Promotion Model
Environment topology and promotion relationships are declared in environments.yml. Jenkins deployment for an environment consumes its configured source branch (defaulting to main); after success, a promotion job updates the branch for the next environment. This separates deployment success from Git branch movement and works around declarative-pipeline Git push limitations. Environment-specific Jenkins configuration is rendered from config/default/jenkins.yaml.
AWS Infrastructure Provisioning
Terraform defines an EKS cluster and its network/security perimeter, parameterized by environment name:
• terraform/cluster/eks-cluster.tf
• terraform/cluster/vpc.tf
• terraform/cluster/security-groups.tf
The workflow initializes Terraform, generates/plans/scans changes, then applies desired state. Bootstrap provisioning establishes the remote Terraform-state S3/DynamoDB backend idempotently via bootstrap/bootstrap.bash. AWS is the principal cloud dependency; AWS credentials and region/backend settings are supplied as CI secrets/environment variables.
Kubernetes Application Delivery
Sock Shop is deployed to the provisioned EKS cluster from deployments/sock-shop/manifest.yml. The manifest pins workload images by SHA256 for reproducibility and includes readiness-based smoke-test behavior. Deployment control crosses the Terraform-to-Kubernetes boundary through generated cluster credentials/kubeconfig and kubectl; rollout waits ensure resources are ready before later verification.
CI Execution and Reconciliation
Jenkins runs workloads in Kubernetes agents using the image built from Dockerfile. Deploy flow bootstraps Terraform state, initializes and validates IaC, runs checks in parallel, deploys cluster infrastructure, applies Sock Shop, waits for readiness, runs integration tests, and promotes the deployed Git revision. The deploy pipeline is periodically triggered as well as source-triggered, so it continuously reconciles manual drift. Destruction is isolated in pipelines/destroy.Jenkinsfile and disabled by default to limit accidental teardown.
Quality and Release Gates
Static and dynamic gates operate before or after apply:
• Terraform validation/lint/format and Snyk IaC scans are orchestrated through Makefile.
• Terraform plan scanning blocks unsafe infrastructure changes unless explicitly configured otherwise.
• OPA/Conftest image-digest policy resides at tests/policies/image.rego.
• Browser-driven Go integration tests validate deployed Sock Shop content under tests/integration/shop_shop.go.
Snyk is an external security service authenticated by token. Jenkins sends failure notifications to Slack through a configured webhook credential.
Runtime and Operational Boundaries
Execution requires Terraform, AWS CLI/authentication, Kubernetes tooling, Docker, Helm/Helmfile for local Jenkins installation, Jenkins CLI, Snyk, Conftest, and Go/browser tooling for integration tests. Secrets are intentionally externalized: secrets/ is a placeholder for generated local artifacts, while Jenkins owns cloud, Git deploy-key, Snyk, and Slack credentials. helmfile.d/jenkins.yaml defines Jenkins deployment dependencies when operating the local CI platform.
Main entry points: deploy.Jenkinsfile Deploy and reconcile · eks-cluster.tf Terraform EKS stack · push-git-branch.xml Git promotion job · bootstrap.bash State backend bootstrap
Components 21
Jenkins CI
- Local Jenkins install · Declares dependencies for operating Jenkins locally.
helmfile.d/jenkins.yaml - Jenkins controller · Owns cloud, Git, Snyk, and Slack credentials.
- Kubernetes agent image · Execution environment for Jenkins workloads.
Dockerfile - Deploy and reconcile · Source- and schedule-triggered deployment pipeline.
pipelines/deploy.Jenkinsfile - Isolated destroy · Disabled by default to prevent accidental teardown.
pipelines/destroy.Jenkinsfile - Git promotion job · Moves the successful revision to the next environment branch.
pipelines/push-git-branch.xml - Environment Jenkins config
config/default/jenkins.yaml
AWS Infrastructure
- Terraform EKS stack · Creates the parameterized EKS cluster, VPC, and security perimeter.
terraform/cluster/eks-cluster.tf - VPC and security
terraform/cluster/vpc.tf - Security groups
terraform/cluster/security-groups.tf - State backend bootstrap · Idempotently creates remote S3 and DynamoDB state storage.
bootstrap/bootstrap.bash - AWS · Provides EKS, network resources, and remote Terraform state.
Kubernetes Delivery
- Sock Shop manifest · Pins workload images by SHA256 and defines readiness behavior.
deployments/sock-shop/manifest.yml - Provisioned EKS cluster · Receives kubeconfig-driven kubectl deployments.
Quality Gates
- Terraform and Snyk gates · Validates, lints, formats, plans, and scans infrastructure changes.
Makefile - Image digest policy · Requires reproducible image digests.
tests/policies/image.rego - Browser integration tests · Verifies deployed Sock Shop content after rollout.
tests/integration/shop_shop.go - Snyk · Authenticated with a Jenkins-managed token.
Other components
- Operator workflow · Primary local interface for provisioning and checks.
Makefile - Environment topology · Defines environment sources and promotion order.
environments.yml - Slack · Receives Jenkins failure notifications.
Connections 24
- Operator workflow → Terraform EKS stack: runs IaC workflow
- Local Jenkins install → Jenkins controller: installs
- Environment Jenkins config → Jenkins controller: configures environments
- Jenkins controller → Kubernetes agent image: runs agents with
- Jenkins controller → Deploy and reconcile: executes
- Jenkins controller → Isolated destroy: executes when enabled
- Deploy and reconcile → Environment topology: reads source and target
- Deploy and reconcile → State backend bootstrap: bootstraps state
- State backend bootstrap → AWS: creates state backend
- Deploy and reconcile → Terraform and Snyk gates: runs before apply
- Terraform and Snyk gates → Snyk: scans IaC
- Deploy and reconcile → Terraform EKS stack: plans and applies
- Terraform EKS stack → VPC and security: includes
- Terraform EKS stack → Security groups: includes
- Terraform EKS stack → AWS: provisions
- AWS → Provisioned EKS cluster: hosts
- Deploy and reconcile → Image digest policy: enforces
- Deploy and reconcile → Sock Shop manifest: applies with kubectl
- Sock Shop manifest → Provisioned EKS cluster: deploys to
- Deploy and reconcile → Browser integration tests: runs after readiness
- Browser integration tests → Provisioned EKS cluster: validates deployed app
- Deploy and reconcile → Git promotion job: triggers after success
- Git promotion job → Environment topology: updates next branch
- Deploy and reconcile → Slack: notifies failures