Skip to content

Adding Cognito module to Terraform #48

Adding Cognito module to Terraform

Adding Cognito module to Terraform #48

name: PR Terraform Plan
on: [pull_request]
permissions:
contents: read
pull-requests: write
jobs:
changed-files:
name: Get changed terraform directories
runs-on: ubuntu-latest
outputs:
module-directory: ${{ steps.module-directory.outputs.directory }}
project-directory: ${{ steps.project-directory.outputs.directory }}
environment-directory: ${{ steps.environment-directory.outputs.directory }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: dorny/paths-filter@v2
with:
filters: |
module-change:
- 'terraform-modules/**'
project-change:
- 'terraform-incubator/*/project/*.tf'
environment-change:
- 'terraform-incubator/*/!(project)/*.tf'
list-files: json
- name: List all changed files
run: |
echo 'module-change: ${{ steps.changed-files.outputs.module-change_files }}'
echo 'project-change: ${{ steps.changed-files.outputs.project-change_files }}'
echo 'environment-change: ${{ steps.changed-files.outputs.environment-change_files }}'
- name: Extract module directory
id: module-directory
if: ${{ fromJson(steps.changed-files.outputs.module-change_files).length > 0 }}
run: |
echo "Directory: $(dirname ${{ fromJson(steps.changed-files.outputs.module-change_files)[0] }})"
echo "::set-output name=directory::$(dirname ${{ fromJson(steps.changed-files.outputs.module-change_files)[0] }})"
- name: Extract project directory
id: project-directory
if: ${{ fromJson(steps.changed-files.outputs.project-change_files).length > 0 }}
run: |
echo "Directory: $(dirname ${{ fromJson(steps.changed-files.outputs.project-change_files)[0] }})"
echo "::set-output name=directory::$(dirname ${{ fromJson(steps.changed-files.outputs.project-change_files)[0] }})"
- name: Extract environment directory
id: environment-directory
if: ${{ fromJson(steps.changed-files.outputs.environment-change_files).length > 0 }}
run: |
echo "Directory: $(dirname ${{ fromJson(steps.changed-files.outputs.environment-change_files)[0] }})"
echo "::set-output name=directory::$(dirname ${{ fromJson(steps.changed-files.outputs.environment-change_files)[0] }})"
plan-module:
runs-on: ubuntu-latest
name: Terraform plan - Module changes
needs: [changed-files]
if: ${{ needs.changed-files.outputs.module-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: terraform plan
uses: dflook/terraform-plan@v1
with:
path: ${{ needs.changed-files.outputs.module-directory }}
plan-project:
runs-on: ubuntu-latest
name: Terraform plan - Project changes
needs: [changed-files]
if: ${{ needs.changed-files.outputs.project-directory && !needs.changed-files.outputs.module-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: terraform plan
uses: dflook/terraform-plan@v1
with:
path: ${{ needs.changed-files.outputs.project-directory }}
plan-environment:
runs-on: ubuntu-latest
name: Terraform plan - Environment changes
needs: [changed-files]
if: ${{ needs.changed-files.outputs.environment-directory && !needs.changed-files.outputs.module-directory && !needs.changed-files.outputs.project-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.INCUBATOR_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.INCUBATOR_AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: terraform plan
uses: dflook/terraform-plan@v1
with:
path: ${{ needs.changed-files.outputs.environment-directory }}