Skip to content

Commit

Permalink
fix: separate jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
furiousme committed Sep 30, 2024
1 parent 6e8c509 commit 9dd47b2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
48 changes: 42 additions & 6 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


1 change: 0 additions & 1 deletion providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ terraform {

provider "aws" {
region = "us-east-1"
shared_credentials_files = ["~/.aws/credentials"]
profile = var.user_profile_name
}

0 comments on commit 9dd47b2

Please sign in to comment.