Skip to content

Commit

Permalink
tinker more
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs committed Jan 17, 2024
1 parent 4a4a459 commit 40081db
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions composite-action/terragrunt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ runs:
uses: hashicorp/setup-terraform@v2
with:
terraform_version: v${{ env.tf_version }}
# This is required for Terragrunt to parse Terraform outputs.
terraform_wrapper: false

- name: Setup Terragrunt
Expand All @@ -56,14 +57,14 @@ runs:
terragrunt -v
- name: Check terragrunt HCL
working-directory: ${{ inputs.working_directory }}
shell: bash
working-directory: ${{ inputs.working_directory }}
run: |
terragrunt hclfmt --terragrunt-check --terragrunt-diff
- name: Validate
working-directory: ${{ inputs.working_directory }}
shell: bash
working-directory: ${{ inputs.working_directory }}
run: |
terragrunt validate
env:
Expand All @@ -73,9 +74,9 @@ runs:
- name: Plan
if: github.event_name == 'pull_request'
id: plan
shell: bash
working-directory: ${{ inputs.working_directory }}
continue-on-error: true
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }}
Expand All @@ -88,7 +89,10 @@ runs:
TF_VAR_new_relic_api_key: ${{ inputs.new_relic_api_key }}
TF_VAR_new_relic_account_id: ${{ inputs.new_relic_account_id }}
run: |
terragrunt plan -no-color --terragrunt-non-interactive -out ${{ github.workspace }}/tfplan
terragrunt plan -no-color --terragrunt-non-interactive -out ${{ github.workspace }}/tfplan | tee output
echo 'plan<<EOF' >> $GITHUB_OUTPUT
cat output >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Find Comment
if: github.event.pull_request.draft == false &&
Expand All @@ -104,7 +108,7 @@ runs:
- name: Create or Update Comment
if: github.event.pull_request.draft == true &&
github.event_name == 'pull_request' &&
!contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.')
!contains(steps.plan.outputs.plan, 'No changes. Your infrastructure matches the configuration.')
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
Expand All @@ -115,7 +119,7 @@ runs:
<details><summary>Show Plan</summary>
```
${{ steps.plan.outputs.stdout }}
${{ steps.plan.outputs.plan }}
```
</details>
Expand All @@ -125,17 +129,18 @@ runs:
uses: detomarco/delete-comments@v1.0.4
if: github.event.pull_request.draft == true &&
github.event_name == 'pull_request' &&
contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.')
contains(steps.plan.outputs.plan, 'No changes. Your infrastructure matches the configuration.')
with:
comment-id: ${{ steps.fc.outputs.comment-id }}

- name: Terragrunt Plan Status
shell: bash
if: steps.plan.outcome == 'failure'
shell: bash
run: exit 1

- name: Terragrunt Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
shell: bash
run: |
if grep -q 'No changes.' tfplan; then
echo "No changes detected."
Expand All @@ -144,7 +149,6 @@ runs:
terragrunt destroy -auto-approve --terragrunt-non-interactive
terragrunt apply -auto-approve --terragrunt-non-interactive
fi
shell: bash
working-directory: ${{ inputs.working_directory }}
env:
TF_VAR_do_token: ${{ inputs.do_token }}
Expand All @@ -161,7 +165,6 @@ runs:

- name: Terragrunt Force Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
shell: bash
working-directory: ${{ inputs.working_directory }}
env:
TF_VAR_do_token: ${{ inputs.do_token }}
Expand All @@ -175,6 +178,7 @@ runs:
TF_VAR_NEW_RELIC_API_KEY: ${{ inputs.new_relic_api_key }}
TF_VAR_NR_LICENSE_KEY: ${{ inputs.nr_license_key }}
TF_VAR_NEW_RELIC_ACCOUNT_ID: ${{ inputs.new_relic_account_id }}
shell: bash
run: |
terragrunt destroy -auto-approve --terragrunt-non-interactive
terragrunt apply -auto-approve --terragrunt-non-interactive

0 comments on commit 40081db

Please sign in to comment.