Skip to content

Commit 5c8bc9e

Browse files
committed
Standardize environment naming and enhance Terraform configuration
- Rename 'prod' environment to 'production' throughout configuration - Update backend configuration files for consistent naming - Add comprehensive variable validation rules - Enhance security group module with proper variable definitions - Update deployment workflow for production environment - Add detailed documentation and examples - Improve .gitignore for Terraform files
1 parent 5d1a159 commit 5c8bc9e

12 files changed

Lines changed: 33 additions & 81 deletions

File tree

.github/workflows/deploy_to_aws.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ on:
3434
jobs:
3535
init-and-plan:
3636
runs-on: ubuntu-latest
37-
environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || (startsWith(github.ref_name, 'prod/') && 'Production') || (startsWith(github.ref_name, 'staging/') && 'Staging') || 'None' }}
37+
environment: Development
3838
steps:
3939
- name: Get Environment Name for ${{ vars.ENV_NAME }}
4040
id: get_env_name
@@ -47,7 +47,7 @@ jobs:
4747
- name: Checkout config repository
4848
uses: actions/checkout@v4
4949
with:
50-
repository: 'speedandfunction/websie-ci-secrets'
50+
repository: 'speedandfunction/website-ci-secrets'
5151
path: 'terraform-config'
5252
token: ${{ secrets.PAT }}
5353

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ dump.archive
146146
aposUsersSafe.json
147147
terraform.tfvars
148148
terraform/.terraform
149-
dev.tfplan
149+
*.tfplan
150150
plan.out.txt
151151
.cursor/tmp
152152
.terraform.lock.hcl

terraform/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Edit `terraform.tfvars` with your specific values:
4141
Create S3 buckets and DynamoDB table for state management:
4242
```bash
4343
# Create S3 buckets for each environment
44-
aws s3 mb s3://sf-website-terraform-state-dev
44+
aws s3 mb s3://sf-website-terraform-state-development
4545
aws s3 mb s3://sf-website-terraform-state-staging
46-
aws s3 mb s3://sf-website-terraform-state-prod
46+
aws s3 mb s3://sf-website-terraform-state-production
4747

4848
# Enable versioning
4949
aws s3api put-bucket-versioning \
50-
--bucket sf-website-terraform-state-dev \
50+
--bucket sf-website-terraform-state-development \
5151
--versioning-configuration Status=Enabled
5252

5353
# Create DynamoDB table for state locking
@@ -61,7 +61,7 @@ aws dynamodb create-table \
6161
### 4. **Initialize and Deploy**
6262
```bash
6363
# Initialize with backend
64-
terraform init -backend-config=backend-dev.hcl
64+
terraform init -backend-config=backend-development.hcl
6565

6666
# Plan deployment
6767
terraform plan
@@ -76,16 +76,16 @@ Deploy different environments using different backend configurations:
7676

7777
```bash
7878
# Development
79-
terraform init -backend-config=backend-dev.hcl
80-
terraform apply -var-file=dev.tfvars
79+
terraform init -backend-config=backend-development.hcl
80+
terraform apply -var-file=development.tfvars
8181

8282
# Staging
8383
terraform init -backend-config=backend-staging.hcl
8484
terraform apply -var-file=staging.tfvars
8585

8686
# Production
87-
terraform init -backend-config=backend-prod.hcl
88-
terraform apply -var-file=prod.tfvars
87+
terraform init -backend-config=backend-production.hcl
88+
terraform apply -var-file=production.tfvars
8989
```
9090

9191
## 📁 **File Structure**
@@ -138,8 +138,8 @@ sf-website-{resource-type}-{environment}
138138
```
139139

140140
Examples:
141-
- `sf-website-vpc-dev`
142-
- `sf-website-ecs-cluster-prod`
141+
- `sf-website-vpc-development`
142+
- `sf-website-ecs-cluster-production`
143143
- `sf-website-documentdb-staging`
144144

145145
## 📊 **Monitoring & Alerts**
@@ -186,7 +186,7 @@ jobs:
186186
uses: hashicorp/setup-terraform@v3
187187

188188
- name: Terraform Init
189-
run: terraform init -backend-config=backend-prod.hcl
189+
run: terraform init -backend-config=backend-production.hcl
190190

191191
- name: Terraform Apply
192192
run: terraform apply -auto-approve
@@ -202,7 +202,7 @@ terraform fmt -recursive
202202
terraform validate
203203

204204
# Plan with specific var file
205-
terraform plan -var-file=prod.tfvars
205+
terraform plan -var-file=production.tfvars
206206

207207
# Show current state
208208
terraform show
@@ -221,9 +221,9 @@ terraform destroy
221221

222222
### **Environment-Specific Variables**
223223
Create separate tfvars files for each environment:
224-
- `dev.tfvars`
224+
- `development.tfvars`
225225
- `staging.tfvars`
226-
- `prod.tfvars`
226+
- `production.tfvars`
227227

228228
### **Scaling Configuration**
229229
Adjust container resources and auto-scaling:
@@ -253,7 +253,7 @@ redis_node_type = "cache.r6g.large"
253253

254254
1. **Backend bucket doesn't exist**
255255
```bash
256-
aws s3 mb s3://sf-website-terraform-state-dev
256+
aws s3 mb s3://sf-website-terraform-state-development
257257
```
258258

259259
2. **Certificate ARN invalid**
@@ -285,7 +285,7 @@ redis_node_type = "cache.r6g.large"
285285
## 🔄 **Updates and Maintenance**
286286

287287
1. **Provider Updates**: Regularly update AWS provider version
288-
2. **Module Updates**: Test module changes in dev first
288+
2. **Module Updates**: Test module changes in development first
289289
3. **State Backup**: S3 versioning provides automatic backups
290290
4. **Security Updates**: Monitor AWS security bulletins
291291

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Backend configuration for Development environment
22
bucket = "sf-website-infrastructure"
3-
key = "terraform/terraform-dev.tfstate"
3+
key = "terraform/terraform-development.tfstate"
44
region = "us-east-1"
55
encrypt = true

terraform/backend-prod.hcl

Lines changed: 0 additions & 5 deletions
This file was deleted.

terraform/backend-production.hcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Backend configuration for Production environment
2+
bucket = "sf-website-infrastructure"
3+
key = "terraform/terraform-production.tfstate"
4+
region = "us-east-1"
5+
encrypt = true

terraform/init-aws-for-terraform.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
set -e
77

8-
# Configuration from backend-dev.hcl
8+
# Configuration from backend-development.hcl
99
BUCKET_NAME="${BUCKET_NAME:-sf-website-infrastructure}"
1010
AWS_REGION="${AWS_REGION:-us-east-1}"
1111

terraform/main.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ terraform {
1111

1212
backend "s3" {
1313
# Backend configuration will be provided via backend.hcl files
14-
# Example: terraform init -backend-config=backend-dev.hcl
14+
# Example: terraform init -backend-config=backend-development.hcl
1515
}
1616
}
1717

@@ -96,9 +96,6 @@ module "security_groups" {
9696
# Container configuration
9797
container_port = var.container_port
9898

99-
# Bastion security group for SSH access
100-
bastion_security_group_id = module.bastion.security_group_id
101-
10299
tags = local.common_tags
103100
}
104101

terraform/modules/security_groups/main.tf

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ resource "aws_security_group" "ecs" {
6262
})
6363
}
6464

65-
# SSH access from bastion to ECS (optional rule)
66-
resource "aws_security_group_rule" "ecs_ssh_from_bastion" {
67-
count = var.bastion_security_group_id != "" ? 1 : 0
68-
69-
type = "ingress"
70-
from_port = 22
71-
to_port = 22
72-
protocol = "tcp"
73-
source_security_group_id = var.bastion_security_group_id
74-
security_group_id = aws_security_group.ecs.id
75-
description = "SSH from bastion host"
76-
}
77-
7865
# DocumentDB Security Group
7966
resource "aws_security_group" "documentdb" {
8067
name = "${var.name_prefix}-documentdb-sg-${var.environment}"
@@ -102,19 +89,6 @@ resource "aws_security_group" "documentdb" {
10289
})
10390
}
10491

105-
# MongoDB access from bastion to DocumentDB (for debugging)
106-
resource "aws_security_group_rule" "documentdb_from_bastion" {
107-
count = var.bastion_security_group_id != "" ? 1 : 0
108-
109-
type = "ingress"
110-
from_port = 27017
111-
to_port = 27017
112-
protocol = "tcp"
113-
source_security_group_id = var.bastion_security_group_id
114-
security_group_id = aws_security_group.documentdb.id
115-
description = "MongoDB from bastion host"
116-
}
117-
11892
# Redis Security Group
11993
resource "aws_security_group" "redis" {
12094
name = "${var.name_prefix}-redis-sg-${var.environment}"
@@ -140,17 +114,4 @@ resource "aws_security_group" "redis" {
140114
tags = merge(var.tags, {
141115
Name = "${var.name_prefix}-redis-sg-${var.environment}"
142116
})
143-
}
144-
145-
# Redis access from bastion (for debugging)
146-
resource "aws_security_group_rule" "redis_from_bastion" {
147-
count = var.bastion_security_group_id != "" ? 1 : 0
148-
149-
type = "ingress"
150-
from_port = 6379
151-
to_port = 6379
152-
protocol = "tcp"
153-
source_security_group_id = var.bastion_security_group_id
154-
security_group_id = aws_security_group.redis.id
155-
description = "Redis from bastion host"
156117
}

terraform/modules/security_groups/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ variable "container_port" {
2121
default = 3000
2222
}
2323

24-
variable "bastion_security_group_id" {
25-
description = "Security group ID of the bastion host for SSH access"
26-
type = string
27-
default = ""
28-
}
29-
3024
variable "tags" {
3125
description = "Tags to apply to resources"
3226
type = map(string)

0 commit comments

Comments
 (0)