Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,19 @@ Infrastructure is provisioned using Terraform.

### Prerequisites

1. Install [Terraform](https://developer.hashicorp.com/terraform/install)
2. Install TFLint
1. [Install Terraform](https://developer.hashicorp.com/terraform/install)

```bash
# macOS
brew install tflint
```

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
Expand All @@ -168,13 +159,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)
Expand Down
4 changes: 0 additions & 4 deletions infra/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@
*.tfstate
*.tfstate.*
.terraform/

# Terraform variables (may contain secrets)
*.tfvars
*.tfvars.json
26 changes: 9 additions & 17 deletions infra/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ENV ?= staging

fmt:
terraform fmt -recursive

Expand All @@ -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
destroy: fmt validate lint
@read -p "Destroy $(ENV) resources? (yes/no): " confirm && [ "$$confirm" = "yes" ]
terraform destroy -var-file=$(ENV).tfvars
2 changes: 2 additions & 0 deletions infra/staging.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
project_id = "student-progress-staging"
environment = "staging"