Skip to content

Commit 24afb00

Browse files
committed
Remove legacy Terraform configuration files and add a new script for setting up the S3 backend. The script initializes the backend resources, generates necessary Terraform configuration files, and ensures prerequisites are met before execution.
1 parent 8a1f124 commit 24afb00

File tree

21 files changed

+207
-574
lines changed

21 files changed

+207
-574
lines changed

.github/workflows/deploy-to-ecr.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
env:
99
AWS_REGION: ${{ secrets.AWS_REGION }}
1010
AWS_IAM_ROLE_ARN: ${{ secrets.AWS_IAM_ROLE_ARN }}
11+
TERRAFORM_DIR: ./01-tf
12+
TERRAFORM_VERSION: '1.12.0'
1113

1214
jobs:
1315
deploy:
@@ -30,24 +32,24 @@ jobs:
3032
- name: Setup Terraform
3133
uses: hashicorp/setup-terraform@v3
3234
with:
33-
terraform_version: '1.12.0'
35+
terraform_version: ${{ env.TERRAFORM_VERSION }}
3436

3537
- name: Terraform Init
3638
id: init
3739
run: terraform init -input=false
38-
working-directory: ./terraform
40+
working-directory: ${{ env.TERRAFORM_DIR }}
3941

4042
- name: Terraform Apply
4143
id: apply
4244
run: |
4345
echo "O_AWS_REGION=${{ env.AWS_REGION }}"
4446
terraform apply -auto-approve -input=false -var="AWS_REGION=${{ env.AWS_REGION }}"
45-
working-directory: ./terraform
47+
working-directory: ${{ env.TERRAFORM_DIR }}
4648

4749
- name: Get ECR Repository URL
4850
id: get_ecr_url
4951
run: echo "ECR_REPOSITORY_URL=$(terraform output -raw ecr_repository_url)" >> $GITHUB_ENV
50-
working-directory: ./terraform
52+
working-directory: ${{ env.TERRAFORM_DIR }}
5153

5254
- name: Login to Amazon ECR
5355
id: login-ecr
File renamed without changes.
File renamed without changes.

pre-terraform/outputs.tf renamed to 00-tf-infra/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ output "s3_bucket_name" {
33
value = aws_s3_bucket.terraform_state.bucket
44
}
55

6-
output "dynamodb_table_name" {
6+
output "dynamodb_lock_table_name" {
77
description = "DynamoDB table name for Terraform locks"
88
value = aws_dynamodb_table.terraform_locks.name
99
}
File renamed without changes.
File renamed without changes.

01-tf/backend.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# !!! DO NOT MODIFY THIS FILE MANUALLY !!!
2+
# File generated by 'setup_tf_backend.sh' dont modify this file manually
3+
# unless you know what you are doing
4+
5+
terraform {
6+
backend "s3" {
7+
bucket = "poc-hello-world-tfstate-058264118467-us-east-1"
8+
key = "states/poc-hello-world/terraform.tfstate"
9+
region = "us-east-1"
10+
dynamodb_table = "poc-hello-world-terraform-lock-table"
11+
encrypt = true
12+
}
13+
}

01-tf/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
provider "aws" {
2+
region = var.AWS_REGION
3+
}
4+
5+
resource "aws_ecr_repository" "app_ecr" {
6+
name = var.ECR_REPOSITORY_NAME
7+
8+
tags = {
9+
Environment = "dev"
10+
}
11+
}
File renamed without changes.

terraform/variables.tf renamed to 01-tf/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# !!! DO NOT MODIFY THIS FILE MANUALLY !!!
2+
# File generated by 'setup_tf_backend.sh' dont modify this file manually
3+
# unless you know what you are doing
4+
15
variable "AWS_REGION" {
26
description = "AWS region for ECR repository"
37
type = string

0 commit comments

Comments
 (0)