From 899f61ba8715e0ad8686dfc218c305cba6b671f5 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 13:07:35 +0530 Subject: [PATCH 01/17] Bucket name and cluster name updated --- terraform/terraform.tf | 4 ++-- terraform/variables.tf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/terraform/terraform.tf b/terraform/terraform.tf index 67b75c673..5fd4bf51d 100644 --- a/terraform/terraform.tf +++ b/terraform/terraform.tf @@ -27,9 +27,9 @@ terraform { } backend "s3" { - bucket = "gitopsterrastate" + bucket = "vprofileaction1803" key = "terraform.tfstate" - region = "us-east-2" + region = "us-east-1" } required_version = "~> 1.6.3" diff --git a/terraform/variables.tf b/terraform/variables.tf index a41d982a0..3e49f4a09 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -7,5 +7,5 @@ variable "region" { variable "clusterName" { description = "Name of the EKS cluster" type = string - default = "kitops-eks" + default = "vprofile-eks" } From 908ef0eb7b17beb38dcbef45090365f228ac0301 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 13:44:05 +0530 Subject: [PATCH 02/17] Staging workflow --- .github/workflows/terraform.yml | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/terraform.yml diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 000000000..4d3778925 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,61 @@ +name: "Vprofile IAC" +on: + push: + branches: + - main + - stage + paths: + - terraform/** + pull_request: + branches: + - main + paths: + - terraform/** + +env: + # Credentials for deployment to AWS + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # S3 bucket for the Terraform state + BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}} + AWS_REGION: us-east-1 + EKS_CLUSTER: vprofile-eks + +jobs: + terraform: + name: "Apply terraform code changes" + runs-on: ubuntu-latest + defaults: + run: + shell: bash + working-directory: ./terraform + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Terraform with specified version on the runner + uses: hashicorp/setup-terraform@v2 + #with: + # terraform_version: 1.6.3 + + - name: Terraform init + id: init + run: terraform init -backend-config="bucket=$BUCKET_TF_STATE" + + - name: Terraform format + id: fmt + run: terraform fmt -check + + - name: Terraform validate + id: validate + run: terraform validate + + - name: Terraform plan + id: plan + run: terraform plan -no-color -input=false -out planfile + continue-on-error: true + + - name: Terraform plan status + if: steps.plan.outcome == 'failure' + run: exit 1 From b3e9199113e82b3100640592056a25573653721b Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 13:53:13 +0530 Subject: [PATCH 03/17] test workflow --- .github/workflows/terraform.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 4d3778925..a869ad84e 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -11,6 +11,7 @@ on: - main paths: - terraform/** + workflow_dispatch: env: # Credentials for deployment to AWS @@ -58,4 +59,4 @@ jobs: - name: Terraform plan status if: steps.plan.outcome == 'failure' - run: exit 1 + run: exit 1 From d13b3db6bb363a9f34ba19fef07488841a62171c Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 14:06:50 +0530 Subject: [PATCH 04/17] chnges in workflow --- .github/workflows/terraform.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index a869ad84e..6bf341e01 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -11,7 +11,6 @@ on: - main paths: - terraform/** - workflow_dispatch: env: # Credentials for deployment to AWS @@ -19,7 +18,7 @@ env: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # S3 bucket for the Terraform state BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}} - AWS_REGION: us-east-1 + AWS_REGION: us-east-2 EKS_CLUSTER: vprofile-eks jobs: @@ -59,4 +58,4 @@ jobs: - name: Terraform plan status if: steps.plan.outcome == 'failure' - run: exit 1 + run: exit 1 From 30db48fb3310772ed313cb26e563ec148b00d948 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 14:10:59 +0530 Subject: [PATCH 05/17] testing workflow --- .github/workflows/terraform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 6bf341e01..a69b900e8 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,5 +1,6 @@ name: "Vprofile IAC" on: + workflow_dispatch: # This enables manual triggering of the workflow push: branches: - main From 39064553503c69d5c6c9d790305745d756001fce Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 14:20:30 +0530 Subject: [PATCH 06/17] testing workflow changes in workflow --- .github/workflows/terraform.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index a69b900e8..6edeaaa9e 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -37,8 +37,6 @@ jobs: - name: Setup Terraform with specified version on the runner uses: hashicorp/setup-terraform@v2 - #with: - # terraform_version: 1.6.3 - name: Terraform init id: init From 2c83a9c808fdddf4cb93fae2d7804ce38bc92444 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 14:27:44 +0530 Subject: [PATCH 07/17] Run workflow on stage branch push --- .github/workflows/terraform.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 6edeaaa9e..6bf341e01 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,6 +1,5 @@ name: "Vprofile IAC" on: - workflow_dispatch: # This enables manual triggering of the workflow push: branches: - main @@ -37,6 +36,8 @@ jobs: - name: Setup Terraform with specified version on the runner uses: hashicorp/setup-terraform@v2 + #with: + # terraform_version: 1.6.3 - name: Terraform init id: init From 43bb7f54a547e5db13ceb1a593537552f73af2ab Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 16:29:14 +0530 Subject: [PATCH 08/17] Updated variables.tf to set default region --- .github/workflows/terraform.yml | 2 +- terraform/variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 6bf341e01..4d3778925 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -18,7 +18,7 @@ env: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # S3 bucket for the Terraform state BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}} - AWS_REGION: us-east-2 + AWS_REGION: us-east-1 EKS_CLUSTER: vprofile-eks jobs: diff --git a/terraform/variables.tf b/terraform/variables.tf index 3e49f4a09..d19424a8e 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -1,7 +1,7 @@ variable "region" { description = "AWS region" type = string - default = "us-east-2" + default = "us-east-1" } variable "clusterName" { From 02107f4d7ff383bfddd3b769f68236ed767c40eb Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 16:36:51 +0530 Subject: [PATCH 09/17] Version declaration in workflow --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 4d3778925..30ae801a7 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -36,8 +36,8 @@ jobs: - name: Setup Terraform with specified version on the runner uses: hashicorp/setup-terraform@v2 - #with: - # terraform_version: 1.6.3 + with: + terraform_version: 1.6.3 - name: Terraform init id: init From 51be080ef6656e53fb8bdb552af2d13c8946467d Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 16:38:55 +0530 Subject: [PATCH 10/17] Update GitHub Actions workflow for Terraform --- .github/workflows/terraform.yml | 2 +- terraform/variables.tf | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 30ae801a7..67a249e9c 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -58,4 +58,4 @@ jobs: - name: Terraform plan status if: steps.plan.outcome == 'failure' - run: exit 1 + run: exit 1 diff --git a/terraform/variables.tf b/terraform/variables.tf index d19424a8e..eb39987cb 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -9,3 +9,4 @@ variable "clusterName" { type = string default = "vprofile-eks" } +#### \ No newline at end of file From 93ad48c3362d19a16f9cbdef41053f65dafbe255 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:02:36 +0530 Subject: [PATCH 11/17] terraform apply steps included --- .github/workflows/terraform.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 67a249e9c..99d048bd8 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -59,3 +59,24 @@ jobs: - name: Terraform plan status if: steps.plan.outcome == 'failure' run: exit 1 + + - name: Terraform "Apply + id: apply + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + run: terraform apply -auto-approve -input=false -parallelism=1 planfile + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Get Kube config file + id: getconfig + if: steps.apple.outcome == 'success' + run: aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ env.EKS_CLUSTER }} + + - name: Install Ingress controller + if: steps.apple.outcome == 'success' && steps.getconfig.outcome == 'success' + run: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/aws/deploy.yaml From 0350938a551b875b504adf884d0d9afb7cf1ee9b Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:03:46 +0530 Subject: [PATCH 12/17] stage test --- terraform/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/variables.tf b/terraform/variables.tf index eb39987cb..4aab47024 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -9,4 +9,4 @@ variable "clusterName" { type = string default = "vprofile-eks" } -#### \ No newline at end of file +##### \ No newline at end of file From 33801a50d0b2456c2ba569373d9a8870bb0b32e1 Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:40:36 +0530 Subject: [PATCH 13/17] deleter terraform/variables.tf --- .github/workflows/terraform.yml | 26 ++++++++++++++++++++++++++ terraform.tfstate | 9 +++++++++ 2 files changed, 35 insertions(+) create mode 100644 terraform.tfstate diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 99d048bd8..67dd26877 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -80,3 +80,29 @@ jobs: - name: Install Ingress controller if: steps.apple.outcome == 'success' && steps.getconfig.outcome == 'success' run: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/aws/deploy.yaml + + destroy: + name: "Destroy terraform resources" + runs-on: ubuntu-latest + if: github.event_name == 'workflow_dispatch' + defaults: + run: + shell: bash + working-directory: ./terraform + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Setup Terraform with specified version on the runner + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: 1.6.3 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + - name: Terraform init + run: terraform init -backend-config="bucket=$BUCKET_TF_STATE" + - name: Destroy resources + run: terraform destroy -auto-approve diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 000000000..d2fcb9273 --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,9 @@ +{ + "version": 4, + "terraform_version": "1.12.2", + "serial": 1, + "lineage": "98b71824-ee26-c0f3-c27a-1ba2b7160a13", + "outputs": {}, + "resources": [], + "check_results": null +} From 85bb973cbf2465058781d0ed0470e53444642f6b Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:41:19 +0530 Subject: [PATCH 14/17] ss --- terraform/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/variables.tf b/terraform/variables.tf index 4aab47024..dfcc504d6 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -9,4 +9,4 @@ variable "clusterName" { type = string default = "vprofile-eks" } -##### \ No newline at end of file +####### \ No newline at end of file From c25b5305b1cb558d4e713d690d255179935732ef Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:55:56 +0530 Subject: [PATCH 15/17] sedfrgthyuji --- .github/workflows/terraform.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 67dd26877..ad2fe643f 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -3,7 +3,6 @@ on: push: branches: - main - - stage paths: - terraform/** pull_request: @@ -65,12 +64,12 @@ jobs: if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve -input=false -parallelism=1 planfile - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ${{ env.AWS_REGION }} - name: Get Kube config file id: getconfig @@ -96,12 +95,12 @@ jobs: uses: hashicorp/setup-terraform@v2 with: terraform_version: 1.6.3 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} + # - name: Configure AWS credentials + # uses: aws-actions/configure-aws-credentials@v1 + # with: + # aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + # aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # aws-region: ${{ env.AWS_REGION }} - name: Terraform init run: terraform init -backend-config="bucket=$BUCKET_TF_STATE" - name: Destroy resources From 42f34648fd4142e5c61b0ed925ede3092b3443ea Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 17:56:47 +0530 Subject: [PATCH 16/17] sqdfg --- .github/workflows/terraform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index ad2fe643f..bf9d5046a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -61,8 +61,8 @@ jobs: - name: Terraform "Apply id: apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - run: terraform apply -auto-approve -input=false -parallelism=1 planfile + if: github.ref == github.event_name == 'push' + run: terraform apply -auto-approve -input=false -parallelism=1 planfile # - name: Configure AWS credentials # uses: aws-actions/configure-aws-credentials@v1 From f0852f296524ae5b37e00ea3ed8c0f76f68cd68b Mon Sep 17 00:00:00 2001 From: AaravMathur Date: Fri, 11 Jul 2025 18:05:50 +0530 Subject: [PATCH 17/17] sqwdefrt --- .github/workflows/terraform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index bf9d5046a..a1df843cd 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - stage paths: - terraform/** pull_request: @@ -10,6 +11,7 @@ on: - main paths: - terraform/** + workflow_dispatch: env: # Credentials for deployment to AWS