From 9dd47b21edda522179dfeb50afdc1262ae05a71c Mon Sep 17 00:00:00 2001 From: furiousme Date: Mon, 30 Sep 2024 22:01:29 +0300 Subject: [PATCH] fix: separate jobs --- .github/workflows/terraform.yml | 48 ++++++++++++++++++++++++++++----- providers.tf | 1 - 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index e2a519e..09ae90d 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -11,13 +11,14 @@ on: pull_request: branches: - main + jobs: terraform-check: runs-on: ubuntu-latest env: - TF_VAR_account_id: ${{ secrets.AWS_ACCOUNT_ID }} - TF_VAR_gh_username: ${{ secrets.TF_VAR_gh_username }} - TF_VAR_user_profile_name: ${{ secrets.TF_VAR_user_profile_name }} + TF_VAR_account_id: ${{ secrets.AWS_ACCOUNT_ID }} + TF_VAR_gh_username: ${{ secrets.TF_VAR_gh_username }} + TF_VAR_user_profile_name: ${{ secrets.TF_VAR_user_profile_name }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -26,21 +27,56 @@ jobs: uses: hashicorp/setup-terraform@v2 with: terraform_version: 1.9.6 - + + - name: Terraform Format Check + run: terraform fmt -check + terraform-plan: + runs-on: ubuntu-latest + needs: terraform-check + env: + TF_VAR_account_id: ${{ secrets.AWS_ACCOUNT_ID }} + TF_VAR_gh_username: ${{ secrets.TF_VAR_gh_username }} + TF_VAR_user_profile_name: ${{ secrets.TF_VAR_user_profile_name }} + steps: + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.6 + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GithubActionsRole aws-region: us-east-1 role-duration-seconds: 1200 - - name: Terraform Init run: terraform init - name: Terraform Plan run: terraform plan + terraform-apply: + runs-on: ubuntu-latest + needs: terraform-plan + env: + TF_VAR_account_id: ${{ secrets.AWS_ACCOUNT_ID }} + TF_VAR_gh_username: ${{ secrets.TF_VAR_gh_username }} + TF_VAR_user_profile_name: ${{ secrets.TF_VAR_user_profile_name }} + steps: + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.9.6 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GithubActionsRole + role-duration-seconds: 1200 + aws-region: us-east-1 + + - name: Terraform Init + run: terraform init - name: Terraform Apply run: terraform apply -auto-approve - diff --git a/providers.tf b/providers.tf index e57ba54..654aee8 100644 --- a/providers.tf +++ b/providers.tf @@ -18,6 +18,5 @@ terraform { provider "aws" { region = "us-east-1" - shared_credentials_files = ["~/.aws/credentials"] profile = var.user_profile_name } \ No newline at end of file