Skip to content

Commit

Permalink
Merge pull request #35 from ADORSYS-GIS/fix/terraform-apply
Browse files Browse the repository at this point in the history
feat: added a state
  • Loading branch information
Arielpetit authored Dec 16, 2024
2 parents 226efdf + bb8a887 commit 8df3ca9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:
exit 0
fi
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
Expand All @@ -110,7 +111,7 @@ jobs:

- name: Set DB Password and Username as Environment Variables
run: |
echo "TF_VAR_name=${{ matrix.name }}-cluster1" >> $GITHUB_ENV
echo "TF_VAR_name=${{ matrix.name }}-env" >> $GITHUB_ENV
echo "TF_VAR_db_username=${{ vars.DB_USERNAME }}" >> $GITHUB_ENV
echo "TF_VAR_db_password=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV
echo "TF_VAR_oidc_kc_client_id=${{ vars.OIDC_KC_CLIENT_ID }}" >> $GITHUB_ENV
Expand All @@ -121,11 +122,17 @@ jobs:
echo "TF_VAR_zone_name=${{ vars.DOMAIN_NAME }}" >> $GITHUB_ENV
- name: Terraform Init
run: terraform init -var-file=${{ matrix.name }}.tfvars -backend-config="bucket=adorsys-webank-dev-tfstate" -backend-config="dynamodb_table=webank-tflock"
run: |
terraform init -var-file=${{ matrix.name }}.tfvars \
-backend-config="region=${{ vars.AWS_REGION }}" \
-backend-config="bucket=webank-dev-terraform-state" \
-backend-config="dynamodb_table=webank-dev-terraform-state-lock"
- name: Terraform Plan
run: terraform plan -var-file=${{ matrix.name }}.tfvars -out=plan.tfplan
run: |
terraform plan -var-file=${{ matrix.name }}.tfvars -out=plan.tfplan
- name: Terraform Apply
if: github.event_name == 'workflow_dispatch'
run: terraform apply -auto-approve plan.tfplan
run: |
terraform apply -auto-approve plan.tfplan
23 changes: 17 additions & 6 deletions .github/workflows/destroy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ jobs:
matrix:
name:
- dev
include:
- name: dev
description: "Environment to be destroyed"
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check if deployment should proceed
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.environment }}" != "${{ matrix.name }}" ]]; then
echo "Skipping deployment for ${{ matrix.name }}"
exit 0
fi
- name: Set up Terraform
uses: hashicorp/setup-terraform@v2
with:
Expand All @@ -52,11 +57,17 @@ jobs:
echo "TF_VAR_zone_name=${{ vars.DOMAIN_NAME }}" >> $GITHUB_ENV
- name: Terraform Init
run: terraform init -var-file=${{ matrix.name }}.tfvars -backend-config="bucket=adorsys-webank-dev-tfstate" -backend-config="dynamodb_table=webank-tflock"
run: |
terraform init -var-file=${{ matrix.name }}.tfvars \
-backend-config="region=${{ vars.AWS_REGION }}" \
-backend-config="bucket=webank-dev-terraform-state" \
-backend-config="dynamodb_table=webank-dev-terraform-state-lock"
- name: Terraform Plan
run: terraform plan -destroy -var-file=${{ matrix.name }}.tfvars -out=plan.tfplan
run: |
terraform plan -destroy -var-file=${{ matrix.name }}.tfvars -out=plan.tfplan
- name: Terraform Destroy
if: github.event_name == 'workflow_dispatch'
run: terraform destroy -auto-approve plan.tfplan
run: |
terraform destroy -auto-approve -var-file=${{ matrix.name }}.tfvars
1 change: 0 additions & 1 deletion terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This Terraform configuration creates a basic AWS EKS cluster with the following
export TF_VAR_db_password="db_username_password123"
export TF_VAR_name="webank-test-me"
export TF_VAR_region="eu-central-1"
export TF_VAR_azs='["eu-central-1a", "eu-central-1b"]'
```

1. Initialize Terraform:
Expand Down
4 changes: 2 additions & 2 deletions terraform/dev.tfvars
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
vpc_cidr = "12.34.0.0/16"
environment = "dev"
eks_min_instance = 2
eks_min_instance = 1
eks_max_instance = 8
eks_desired_instance = 3
eks_desired_instance = 2
db_instance = "db.t3.medium"
db_backup_retention_period = null
db_skip_final_snapshot = true
Expand Down
21 changes: 6 additions & 15 deletions terraform/s3.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
module "terraform_state_backend" {
source = "cloudposse/tfstate-backend/aws"
version = "1.5.0"

namespace = "webank"
stage = "dev"
name = "terraform"

attributes = ["state"]

terraform_backend_config_file_path = "."
terraform_backend_config_file_name = "backend.tf"
force_destroy = false

}
terraform {
backend "s3" {
key = "terraform.tfstate"
encrypt = true
}
}

0 comments on commit 8df3ca9

Please sign in to comment.