-
Notifications
You must be signed in to change notification settings - Fork 0
feat(infra): add Terraform kind cluster and operator deployment module #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f8cc9b
feat(infra): add Terraform kind cluster and operator deployment module
gitcommitankit f7d0ba7
ci: update trivy-action to valid release tag 0.28.0
gitcommitankit 58c9aea
ci: update trivy-action reference to @master
gitcommitankit 6e13e68
refactor: unify TFLint configuration, improve Terraform Makefile inte…
gitcommitankit 6242c7b
fix(infra): quote tflint config path and fix markdown heading hierarchy
gitcommitankit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| name: Terraform Lint | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "infra/**" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| terraform-lint: | ||
| name: fmt / tflint / trivy | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Terraform | ||
| uses: hashicorp/setup-terraform@v3 | ||
| with: | ||
| terraform_version: "1.9.5" | ||
|
|
||
| - name: Terraform Format Check | ||
| run: terraform fmt -check -recursive infra/ | ||
|
|
||
| - name: Set up TFLint | ||
| uses: terraform-linters/setup-tflint@v4 | ||
| with: | ||
| tflint_version: "v0.53.0" | ||
|
|
||
| - name: TFLint init | ||
| run: tflint --init --config=infra/.tflint.hcl | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: TFLint | ||
| run: tflint --chdir=infra/environments/dev --config="$(pwd)/infra/.tflint.hcl" | ||
|
|
||
| - name: Trivy IaC Scan | ||
| uses: aquasecurity/trivy-action@v0.36.0 | ||
| with: | ||
| scan-type: config | ||
| scan-ref: infra/ | ||
| exit-code: "1" | ||
| severity: HIGH,CRITICAL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # tflint configuration for the infra/ directory. | ||
| # Enables the official Terraform plugin for provider-level schema validation. | ||
| # Run: tflint --chdir=infra/environments/dev | ||
|
|
||
| plugin "terraform" { | ||
| enabled = true | ||
| preset = "recommended" | ||
| } | ||
|
|
||
| # Enforce consistent code style. | ||
| rule "terraform_naming_convention" { | ||
| enabled = true | ||
| } | ||
|
|
||
| rule "terraform_required_version" { | ||
| enabled = true | ||
| } | ||
|
|
||
| rule "terraform_required_providers" { | ||
| enabled = true | ||
| } | ||
|
|
||
| rule "terraform_documented_variables" { | ||
| enabled = true | ||
| } | ||
|
|
||
| rule "terraform_documented_outputs" { | ||
| enabled = true | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # dev environment — local kind cluster + agentrax stack | ||
| # This is the primary target for local development, integration testing, and CI. | ||
| # State is stored in a local backend file (terraform.tfstate) — not shared. | ||
|
|
||
| terraform { | ||
| required_version = ">= 1.6" | ||
|
|
||
| # Local backend — intentional for dev. Do not check in terraform.tfstate. | ||
| backend "local" {} | ||
|
|
||
| required_providers { | ||
| kind = { | ||
| source = "tehcyx/kind" | ||
| version = "~> 0.6" | ||
| } | ||
| helm = { | ||
| source = "hashicorp/helm" | ||
| version = "~> 2.14" | ||
| } | ||
| kubernetes = { | ||
| source = "hashicorp/kubernetes" | ||
| version = "~> 2.31" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Step 1: Provision the kind cluster | ||
| # --------------------------------------------------------------------------- | ||
| module "kind_cluster" { | ||
| source = "../../modules/kind_cluster" | ||
| cluster_name = var.cluster_name | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Step 2: Configure the Helm and Kubernetes providers to target the new cluster. | ||
| # Both providers read credentials from the kind_cluster module outputs so no | ||
| # local kubeconfig file needs to exist before `terraform apply`. | ||
| # --------------------------------------------------------------------------- | ||
| provider "helm" { | ||
| kubernetes { | ||
| host = module.kind_cluster.endpoint | ||
| client_certificate = module.kind_cluster.client_certificate | ||
| client_key = module.kind_cluster.client_key | ||
| cluster_ca_certificate = module.kind_cluster.cluster_ca_certificate | ||
| } | ||
| } | ||
|
|
||
| provider "kubernetes" { | ||
| host = module.kind_cluster.endpoint | ||
| client_certificate = module.kind_cluster.client_certificate | ||
| client_key = module.kind_cluster.client_key | ||
| cluster_ca_certificate = module.kind_cluster.cluster_ca_certificate | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Step 3: Install cert-manager → kube-prometheus-stack → agentrax | ||
| # --------------------------------------------------------------------------- | ||
| module "agentrax_stack" { | ||
| source = "../../modules/agentrax_stack" | ||
|
|
||
| cert_manager_version = var.cert_manager_version | ||
| prometheus_stack_version = var.prometheus_stack_version | ||
| agentrax_chart_path = var.agentrax_chart_path | ||
| agentrax_leader_elect = var.agentrax_leader_elect | ||
| agentrax_extra_values = var.agentrax_extra_values | ||
|
|
||
| # The stack module requires the cluster to exist first. | ||
| # Provider-level dependency is enforced via the shared kubeconfig above. | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # dev environment — outputs | ||
|
|
||
| output "cluster_endpoint" { | ||
| description = "Kubernetes API server endpoint for the dev kind cluster." | ||
| value = module.kind_cluster.endpoint | ||
| } | ||
|
|
||
| output "agentrax_namespace" { | ||
| description = "Namespace where the agentrax operator was deployed." | ||
| value = module.agentrax_stack.agentrax_namespace | ||
| } | ||
|
|
||
| output "agentrax_release_status" { | ||
| description = "Helm release status for the agentrax chart." | ||
| value = module.agentrax_stack.agentrax_release_status | ||
| } | ||
|
|
||
| output "prometheus_namespace" { | ||
| description = "Namespace where kube-prometheus-stack is deployed." | ||
| value = module.agentrax_stack.prometheus_namespace | ||
| } | ||
|
|
||
| output "kubeconfig" { | ||
| description = "Raw kubeconfig for the kind cluster. Pipe into kubectl or save to a file." | ||
| value = module.kind_cluster.kubeconfig | ||
| sensitive = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # dev environment — variables | ||
|
|
||
| variable "cluster_name" { | ||
| description = "Name of the local kind cluster." | ||
| type = string | ||
| default = "agentrax-dev" | ||
| } | ||
|
|
||
| variable "cert_manager_version" { | ||
| description = "cert-manager Helm chart version." | ||
| type = string | ||
| default = "v1.15.3" | ||
| } | ||
|
|
||
| variable "prometheus_stack_version" { | ||
| description = "kube-prometheus-stack Helm chart version." | ||
| type = string | ||
| default = "61.8.0" | ||
| } | ||
|
|
||
| variable "agentrax_chart_path" { | ||
| description = "Path to the agentrax Helm chart directory, relative to this environment root." | ||
| type = string | ||
| default = "../../../charts/agentrax" | ||
| } | ||
|
|
||
| variable "agentrax_leader_elect" { | ||
| description = "Enable leader election for the Agentrax controller manager." | ||
| type = bool | ||
| default = false | ||
| } | ||
|
|
||
| variable "agentrax_extra_values" { | ||
| description = "Additional Helm set key=value overrides for the agentrax release." | ||
| type = map(string) | ||
| default = {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Production Environment — Azure AKS (Stub) | ||
|
|
||
| This environment targets an Azure Kubernetes Service (AKS) cluster for production workloads. The `agentrax_stack` module is cloud-agnostic; the production configuration differs from `dev` in four ways: | ||
|
|
||
| 1. **Remote State Backend**: State stored in Azure Blob Storage with state locking. | ||
| 2. **Cloud Provider Authentication**: Uses `azurerm` / `azapi` providers authenticated via Azure OIDC / Workload Identity. | ||
| 3. **High Availability**: `agentrax_leader_elect = true` with $\ge 2$ controller replicas. | ||
| 4. **Workload Identity**: Cloud identity parameters passed via `agentrax_extra_values`. | ||
|
|
||
| ## Activation Runbook (Future — Not Yet Implemented) | ||
|
|
||
| > [!NOTE] | ||
| > The `infra/environments/prod/` directory is a stub. No `main.tf` exists here yet. The steps below are guidance for when the production Terraform root module is implemented. | ||
|
|
||
| 1. Provision the target AKS cluster and retrieve its kubeconfig credentials. | ||
| 2. Configure `backend.tf` with the Azure Blob Storage container coordinates. | ||
| 3. Export Azure authentication environment variables (`ARM_CLIENT_ID`, `ARM_TENANT_ID`, `ARM_SUBSCRIPTION_ID`, `ARM_USE_OIDC=true`). | ||
| 4. Execute deployment: | ||
| ```bash | ||
| terraform -chdir=infra/environments/prod init | ||
| terraform -chdir=infra/environments/prod apply | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.