# engineerbetter/iac-example architecture

> Architecture diagram of the GitHub repository engineerbetter/iac-example, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/engineerbetter/iac-example
- Repository: https://github.com/engineerbetter/iac-example

## Overview

#### 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: [`pipelines/deploy.Jenkinsfile`](https://github.com/engineerbetter/iac-example/blob/main/pipelines/deploy.Jenkinsfile) (Deploy and reconcile), [`terraform/cluster/eks-cluster.tf`](https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/eks-cluster.tf) (Terraform EKS stack), [`pipelines/push-git-branch.xml`](https://github.com/engineerbetter/iac-example/blob/main/pipelines/push-git-branch.xml) (Git promotion job), [`bootstrap/bootstrap.bash`](https://github.com/engineerbetter/iac-example/blob/main/bootstrap/bootstrap.bash) (State backend bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ci["Jenkins CI"]
  node_jenkins_install["Local Jenkins install<br/>Helmfile<br/>[jenkins.yaml]"]
  node_jenkins{{"Jenkins controller<br/>CI orchestrator"}}
  node_agent_image["Kubernetes agent image<br/>Docker image"]
  node_deploy_pipeline["Deploy and reconcile<br/>Jenkins pipeline<br/>[deploy.Jenkinsfile]"]
  node_destroy_pipeline["Isolated destroy<br/>Jenkins pipeline"]
  node_promotion_job["Git promotion job<br/>Jenkins job config"]
  node_jenkins_config["Environment Jenkins config<br/>rendered config<br/>[jenkins.yaml]"]
end

subgraph group_iac["AWS Infrastructure"]
  node_terraform["Terraform EKS stack<br/>IaC<br/>[eks-cluster.tf]"]
  node_tf_network["VPC and security<br/>Terraform modules<br/>[vpc.tf]"]
  node_tf_security["Security groups<br/>Terraform configuration<br/>[security-groups.tf]"]
  node_state_bootstrap["State backend bootstrap<br/>bootstrap script<br/>[bootstrap.bash]"]
  node_aws{{"AWS<br/>cloud platform"}}
end

subgraph group_delivery["Kubernetes Delivery"]
  node_sockshop_manifest["Sock Shop manifest<br/>Kubernetes manifest<br/>[manifest.yml]"]
  node_eks{{"Provisioned EKS cluster<br/>Kubernetes runtime"}}
end

subgraph group_gates["Quality Gates"]
  node_iac_gates["Terraform and Snyk gates<br/>validation and scan"]
  node_image_policy["Image digest policy<br/>OPA policy<br/>[image.rego]"]
  node_integration_tests["Browser integration tests<br/>Go tests<br/>[shop_shop.go]"]
  node_snyk{{"Snyk<br/>external security service"}}
end

node_make["Operator workflow<br/>Make"]
node_environments["Environment topology<br/>environment config<br/>[environments.yml]"]
node_slack{{"Slack<br/>notification service"}}

node_make -->|"runs IaC workflow"| node_terraform
node_jenkins_install -->|"installs"| node_jenkins
node_jenkins_config -->|"configures environments"| node_jenkins
node_jenkins -->|"runs agents with"| node_agent_image
node_jenkins -->|"executes"| node_deploy_pipeline
node_jenkins -.->|"executes when enabled"| node_destroy_pipeline
node_deploy_pipeline -->|"reads source and target"| node_environments
node_deploy_pipeline -->|"bootstraps state"| node_state_bootstrap
node_state_bootstrap -->|"creates state backend"| node_aws
node_deploy_pipeline -->|"runs before apply"| node_iac_gates
node_iac_gates -->|"scans IaC"| node_snyk
node_deploy_pipeline -->|"plans and applies"| node_terraform
node_terraform -->|"includes"| node_tf_network
node_terraform -->|"includes"| node_tf_security
node_terraform -->|"provisions"| node_aws
node_aws -->|"hosts"| node_eks
node_deploy_pipeline -->|"enforces"| node_image_policy
node_deploy_pipeline -->|"applies with kubectl"| node_sockshop_manifest
node_sockshop_manifest -->|"deploys to"| node_eks
node_deploy_pipeline -->|"runs after readiness"| node_integration_tests
node_integration_tests -->|"validates deployed app"| node_eks
node_deploy_pipeline -->|"triggers after success"| node_promotion_job
node_promotion_job -->|"updates next branch"| node_environments
node_deploy_pipeline -.->|"notifies failures"| node_slack

click node_make "https://github.com/engineerbetter/iac-example/blob/main/Makefile"
click node_environments "https://github.com/engineerbetter/iac-example/blob/main/environments.yml"
click node_jenkins_install "https://github.com/engineerbetter/iac-example/blob/main/helmfile.d/jenkins.yaml"
click node_agent_image "https://github.com/engineerbetter/iac-example/blob/main/Dockerfile"
click node_deploy_pipeline "https://github.com/engineerbetter/iac-example/blob/main/pipelines/deploy.Jenkinsfile"
click node_destroy_pipeline "https://github.com/engineerbetter/iac-example/blob/main/pipelines/destroy.Jenkinsfile"
click node_promotion_job "https://github.com/engineerbetter/iac-example/blob/main/pipelines/push-git-branch.xml"
click node_jenkins_config "https://github.com/engineerbetter/iac-example/blob/main/config/default/jenkins.yaml"
click node_terraform "https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/eks-cluster.tf"
click node_tf_network "https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/vpc.tf"
click node_tf_security "https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/security-groups.tf"
click node_state_bootstrap "https://github.com/engineerbetter/iac-example/blob/main/bootstrap/bootstrap.bash"
click node_sockshop_manifest "https://github.com/engineerbetter/iac-example/blob/main/deployments/sock-shop/manifest.yml"
click node_iac_gates "https://github.com/engineerbetter/iac-example/blob/main/Makefile"
click node_image_policy "https://github.com/engineerbetter/iac-example/blob/main/tests/policies/image.rego"
click node_integration_tests "https://github.com/engineerbetter/iac-example/blob/main/tests/integration/shop_shop.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_jenkins_install,node_jenkins,node_agent_image,node_deploy_pipeline,node_destroy_pipeline,node_promotion_job,node_jenkins_config toneBlue
class node_terraform,node_tf_network,node_tf_security,node_state_bootstrap,node_aws toneAmber
class node_sockshop_manifest,node_eks toneMint
class node_iac_gates,node_image_policy,node_integration_tests,node_snyk toneRose
class node_make,node_environments,node_slack toneNeutral
```

## Components

### Jenkins CI

- [Local Jenkins install](https://github.com/engineerbetter/iac-example/blob/main/helmfile.d/jenkins.yaml): Helmfile · Declares dependencies for operating Jenkins locally. · `helmfile.d/jenkins.yaml`
- **Jenkins controller**: CI orchestrator · Owns cloud, Git, Snyk, and Slack credentials.
- [Kubernetes agent image](https://github.com/engineerbetter/iac-example/blob/main/Dockerfile): Docker image · Execution environment for Jenkins workloads. · `Dockerfile`
- [Deploy and reconcile](https://github.com/engineerbetter/iac-example/blob/main/pipelines/deploy.Jenkinsfile): Jenkins pipeline · Source- and schedule-triggered deployment pipeline. · `pipelines/deploy.Jenkinsfile`
- [Isolated destroy](https://github.com/engineerbetter/iac-example/blob/main/pipelines/destroy.Jenkinsfile): Jenkins pipeline · Disabled by default to prevent accidental teardown. · `pipelines/destroy.Jenkinsfile`
- [Git promotion job](https://github.com/engineerbetter/iac-example/blob/main/pipelines/push-git-branch.xml): Jenkins job config · Moves the successful revision to the next environment branch. · `pipelines/push-git-branch.xml`
- [Environment Jenkins config](https://github.com/engineerbetter/iac-example/blob/main/config/default/jenkins.yaml): rendered config · `config/default/jenkins.yaml`

### AWS Infrastructure

- [Terraform EKS stack](https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/eks-cluster.tf): IaC · Creates the parameterized EKS cluster, VPC, and security perimeter. · `terraform/cluster/eks-cluster.tf`
- [VPC and security](https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/vpc.tf): Terraform modules · `terraform/cluster/vpc.tf`
- [Security groups](https://github.com/engineerbetter/iac-example/blob/main/terraform/cluster/security-groups.tf): Terraform configuration · `terraform/cluster/security-groups.tf`
- [State backend bootstrap](https://github.com/engineerbetter/iac-example/blob/main/bootstrap/bootstrap.bash): bootstrap script · Idempotently creates remote S3 and DynamoDB state storage. · `bootstrap/bootstrap.bash`
- **AWS**: cloud platform · Provides EKS, network resources, and remote Terraform state.

### Kubernetes Delivery

- [Sock Shop manifest](https://github.com/engineerbetter/iac-example/blob/main/deployments/sock-shop/manifest.yml): Kubernetes manifest · Pins workload images by SHA256 and defines readiness behavior. · `deployments/sock-shop/manifest.yml`
- **Provisioned EKS cluster**: Kubernetes runtime · Receives kubeconfig-driven kubectl deployments.

### Quality Gates

- [Terraform and Snyk gates](https://github.com/engineerbetter/iac-example/blob/main/Makefile): validation and scan · Validates, lints, formats, plans, and scans infrastructure changes. · `Makefile`
- [Image digest policy](https://github.com/engineerbetter/iac-example/blob/main/tests/policies/image.rego): OPA policy · Requires reproducible image digests. · `tests/policies/image.rego`
- [Browser integration tests](https://github.com/engineerbetter/iac-example/blob/main/tests/integration/shop_shop.go): Go tests · Verifies deployed Sock Shop content after rollout. · `tests/integration/shop_shop.go`
- **Snyk**: external security service · Authenticated with a Jenkins-managed token.

### Other components

- [Operator workflow](https://github.com/engineerbetter/iac-example/blob/main/Makefile): Make · Primary local interface for provisioning and checks. · `Makefile`
- [Environment topology](https://github.com/engineerbetter/iac-example/blob/main/environments.yml): environment config · Defines environment sources and promotion order. · `environments.yml`
- **Slack**: notification service · Receives Jenkins failure notifications.

## Connections

- 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
