From d1a3a2c665eab50ebb3621fa2d023bc24a48c4e0 Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 18:42:53 +0400 Subject: [PATCH 1/6] Bucket name & Cluster name updated --- terraform/terraform.tf | 2 +- terraform/variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/terraform.tf b/terraform/terraform.tf index 67b75c673..d68901a13 100644 --- a/terraform/terraform.tf +++ b/terraform/terraform.tf @@ -27,7 +27,7 @@ terraform { } backend "s3" { - bucket = "gitopsterrastate" + bucket = "vprofileactions23" key = "terraform.tfstate" region = "us-east-2" } 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 feead73d81ac21401fede93633ee81fc1fdd1ee8 Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 20:27:37 +0400 Subject: [PATCH 2/6] 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..3872475e2 --- /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-2 + 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 \ No newline at end of file From db24924fded977dc07353876f08f0e6bc9694f49 Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 20:32:44 +0400 Subject: [PATCH 3/6] fixed jobs --- .github/workflows/terraform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 3872475e2..d56219ed2 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -21,7 +21,7 @@ env: AWS_REGION: us-east-2 EKS_CLUSTER: vprofile-eks - jobs: +jobs: terraform: name: "Apply terraform code changes" runs-on: ubuntu-latest From a216f6029b1e4bd2bfaad12af6635d409cb376a3 Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 20:34:08 +0400 Subject: [PATCH 4/6] test workflow --- terraform/variables.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/terraform/variables.tf b/terraform/variables.tf index 3e49f4a09..576ba161e 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -9,3 +9,5 @@ variable "clusterName" { type = string default = "vprofile-eks" } + +## \ No newline at end of file From b017b43dcf1ab49c6a5a8598228043ba680b0ecb Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 20:54:26 +0400 Subject: [PATCH 5/6] terraform apply steps included --- .github/workflows/terraform.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index d56219ed2..bc7fdbf1a 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -58,4 +58,25 @@ jobs: - name: Terraform plan status if: steps.plan.outcome == 'failure' - run: exit 1 \ No newline at end of file + run: exit 1 + + - name: Terraform Apply + id: apple + 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 79f840db3d66ee032913f59343ed56b8f4f83b9f Mon Sep 17 00:00:00 2001 From: devops4sure Date: Mon, 13 Nov 2023 20:55:30 +0400 Subject: [PATCH 6/6] stage test --- terraform/variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/terraform/variables.tf b/terraform/variables.tf index 576ba161e..b8fe9d331 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -10,4 +10,5 @@ variable "clusterName" { default = "vprofile-eks" } +## ## \ No newline at end of file