Skip to content

Commit

Permalink
fix: workflow adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
furiousme committed Sep 30, 2024
1 parent 5fef889 commit 1015698
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
34 changes: 12 additions & 22 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Terraform Workflow

permissions:
id-token: write
contents: read

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand All @@ -9,32 +16,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.6
uses: actions/checkout@v4

- name: Terraform Format Check
run: terraform fmt -check
terraform-plan:
runs-on: ubuntu-latest
needs: terraform-check
permissions:
id-token: write
contents: read
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
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
Expand All @@ -43,21 +37,17 @@ jobs:
run: terraform plan
terraform-apply:
runs-on: ubuntu-latest
needs: terraform-plan
permissions:
id-token: write
contents: read
if: github.ref == 'refs/heads/main'
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
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
Expand Down
8 changes: 5 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ resource "aws_iam_role" "github_actions_role" {
Federated : "arn:aws:iam::${var.account_id}:oidc-provider/token.actions.githubusercontent.com"
},
Condition = {
StringEquals = {
"token.actions.githubusercontent.com:aud" : "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub" : "repo:${var.gh_username}/rsschool-devops-course-tasks:ref:refs/heads/main"
StringLike : {
"token.actions.githubusercontent.com:sub" : "repo:${var.gh_username}/rsschool-devops-course-tasks:*"
},
StringEquals : {
"token.actions.githubusercontent.com:aud" : "sts.amazonaws.com"
}
}
},
Expand Down

0 comments on commit 1015698

Please sign in to comment.