Merge pull request #1 from tabarak23/staging #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Vprofile eks project" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - staging | |
| paths: | |
| - terraform/** | |
| pull_request: | |
| branches: | |
| - main | |
| - staging | |
| paths: | |
| - terraform/** | |
| env: | |
| AWS_REGION: us-west-1 | |
| TFVARS_FILE: staging.tfvars | |
| #clister name | |
| EKS_CLUSTER: tabarakvprofile-staging | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| #bucket for terraform state | |
| BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE }} | |
| jobs: | |
| terraform: | |
| name: "appky terraform code changes" | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| working-directory: ./terraform | |
| steps: | |
| - name: checkout source code | |
| uses: actions/checkout@v3 | |
| - name: Setup terraform with respective version | |
| uses: hashicorp/setup-terraform@v2 | |
| with: | |
| terraform_version: 1.6.6 | |
| - name: Check terraform version | |
| run: terraform version | |
| - name: terraform init | |
| id: init | |
| run: terraform init -backend-config="bucket=${{ env.BUCKET_TF_STATE }}" | |
| - name: terraform fmt | |
| id: fmt | |
| run: terraform fmt -check | |
| - name: Terraform Validate | |
| id: validate | |
| run: terraform validate | |
| - name: Terraform Plan | |
| id: plan | |
| run: | | |
| terraform plan \ | |
| -var-file=${{ env.TFVARS_FILE }} \ | |
| -input=false \ | |
| -no-color | |
| continue-on-error: false | |
| - name: terraform plan status | |
| if: steps.plan.outcome == 'failure' | |
| run: exit 1 | |
| - name: Terraform apply only on main branch | |
| id: apply | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| terraform apply \ | |
| -var-file=${{ env.TFVARS_FILE }} \ | |
| -auto-approve \ | |
| -input=false | |
| - 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: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: | | |
| aws eks update-kubeconfig \ | |
| --region ${{ env.AWS_REGION }} \ | |
| --name ${{ env.EKS_CLUSTER }} | |
| - name: Install Ingress controller | |
| if: steps.apply.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 |