From 1d2ffded83bed060a54b02fdd114c58744f32b0d Mon Sep 17 00:00:00 2001 From: aga Date: Tue, 26 May 2026 11:45:08 +0200 Subject: [PATCH 1/2] Improve Terraform README and Makefile --- README.md | 36 +++++++++++++++--------------------- infra/.gitignore | 4 ---- infra/Makefile | 26 +++++++++----------------- infra/staging.tfvars | 2 ++ 4 files changed, 26 insertions(+), 42 deletions(-) create mode 100644 infra/staging.tfvars diff --git a/README.md b/README.md index 00d4f11..2d79554 100644 --- a/README.md +++ b/README.md @@ -135,28 +135,20 @@ Infrastructure is provisioned using Terraform. ### Prerequisites -1. Install [Terraform](https://developer.hashicorp.com/terraform/install) -2. Install TFLint -```bash -# macOS -brew install tflint -``` +1. [Install Terraform](https://developer.hashicorp.com/terraform/install) -3. Install TFSec +2. [Install TFLint](https://github.com/terraform-linters/tflint?utm_source=chatgpt.com) -```bash -# macOS -brew install tfsec -``` +3. [Install TFSec](https://aquasecurity.github.io/tfsec/v0.63.1/getting-started/installation/) ### Configuration -Create environment variable files for each Terraform environment: +Terraform non-secret environment configuration lives in: -```bash -cp infra/staging.tfvars.example infra/staging.tfvars -cp infra/prod.tfvars.example infra/prod.tfvars +```text +infra/staging.tfvars +infra/prod.tfvars ``` ### Workflow @@ -168,13 +160,15 @@ cd infra terraform init # one-off -make plan-staging -make apply-staging -make destroy-staging +make plan +make apply +make destroy +``` + +Commands default to the staging environment. In prod: -make plan-prod -make apply-prod -make destroy-prod +```bash +make apply ENV=prod ``` ## One-off Infrastructure Setup (GCP) diff --git a/infra/.gitignore b/infra/.gitignore index 71742f3..7de2754 100644 --- a/infra/.gitignore +++ b/infra/.gitignore @@ -4,7 +4,3 @@ *.tfstate *.tfstate.* .terraform/ - -# Terraform variables (may contain secrets) -*.tfvars -*.tfvars.json diff --git a/infra/Makefile b/infra/Makefile index 0b570ab..08fe2ba 100644 --- a/infra/Makefile +++ b/infra/Makefile @@ -1,3 +1,5 @@ +ENV ?= staging + fmt: terraform fmt -recursive @@ -6,23 +8,13 @@ validate: lint: tflint - -plan-staging: fmt validate lint - terraform plan -var-file=staging.tfvars - -apply-staging: fmt validate lint - terraform apply -var-file=staging.tfvars - -plan-prod: fmt validate lint - terraform plan -var-file=prod.tfvars -apply-prod: fmt validate lint - terraform apply -var-file=prod.tfvars +plan: fmt validate lint + terraform plan -var-file=$(ENV).tfvars -destroy-staging: fmt validate lint - @read -p "Destroy STAGING resources? (yes/no): " confirm && [ "$$confirm" = "yes" ] - terraform destroy -var-file=staging.tfvars +apply: fmt validate lint + terraform apply -var-file=$(ENV).tfvars -destroy-prod: fmt validate lint - @read -p "Destroy PROD resources? (yes/no): " confirm && [ "$$confirm" = "yes" ] - terraform destroy -var-file=prod.tfvars \ No newline at end of file +destroy: fmt validate lint + @read -p "Destroy $(ENV) resources? (yes/no): " confirm && [ "$$confirm" = "yes" ] + terraform destroy -var-file=$(ENV).tfvars diff --git a/infra/staging.tfvars b/infra/staging.tfvars new file mode 100644 index 0000000..cd265d9 --- /dev/null +++ b/infra/staging.tfvars @@ -0,0 +1,2 @@ +project_id = "student-progress-staging" +environment = "staging" From ebdb2bfeeff1f4e5778db0c1a1e84b3835c2e73a Mon Sep 17 00:00:00 2001 From: aga Date: Tue, 26 May 2026 11:46:35 +0200 Subject: [PATCH 2/2] Format --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2d79554..20f4327 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,6 @@ Infrastructure is provisioned using Terraform. ### Prerequisites - 1. [Install Terraform](https://developer.hashicorp.com/terraform/install) 2. [Install TFLint](https://github.com/terraform-linters/tflint?utm_source=chatgpt.com)