-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d96af8f
commit 44a3f78
Showing
6 changed files
with
197 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugin "terraform" { | ||
enabled = true | ||
version = "0.2.2" | ||
source = "github.com/terraform-linters/tflint-ruleset-terraform" | ||
enabled = true | ||
version = "0.5.0" | ||
source = "github.com/terraform-linters/tflint-ruleset-terraform" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
name: Custom Composite action to deploy terragrunt resources | ||
|
||
description: | | ||
This action deploys the Forest infrastructure with Terragrunt | ||
inputs: | ||
environment: | ||
description: 'The terraform plan for the the environment infrastructure to be deployed' | ||
required: true | ||
do_token: | ||
description: 'The DigitalOcean access token to use for deploying the infrastructure' | ||
required: true | ||
aws_access_key_id: | ||
description: 'S3 access keys id used by terraform and service like sync check, Deploy Snapshot Service etc' | ||
required: true | ||
aws_secret_access_key: | ||
description: 'S3 secret access keys used by terraform and service like sync check, Deploy Snapshot Service etc' | ||
required: true | ||
working_directory: | ||
description: 'The working Directory' | ||
required: true | ||
slack_token: | ||
description: 'The slack token secret used to connect the Infrastructure to Slack' | ||
new_relic_api_key: | ||
description: 'The New Relic API KEY' | ||
nr_license_key: | ||
description: 'The New Relic Access Token' | ||
new_relic_account_id: | ||
description: 'The New Relic Platform Region' | ||
r2_access_key: | ||
description: 'CloudFlare R2 access key id' | ||
r2_secret_key: | ||
description: 'CloudFlare R2 private access key' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
# Workaround for https://github.com/orgs/community/discussions/51280 | ||
- name: Set TF/TG versions | ||
shell: bash | ||
run: | | ||
echo "tf_version=1.6.6" >> $GITHUB_ENV | ||
echo "tg_version=0.53.2" >> $GITHUB_ENV | ||
- name: Check terragrunt HCL | ||
uses: gruntwork-io/terragrunt-action@v2 | ||
with: | ||
tf_version: ${{ env.tf_version }} | ||
tg_version: ${{ env.tg_version }} | ||
tg_dir: ${{ inputs.working_directory }} | ||
tg_command: 'hclfmt --terragrunt-check --terragrunt-diff' | ||
|
||
- name: Validate | ||
uses: gruntwork-io/terragrunt-action@v2 | ||
with: | ||
tf_version: ${{ env.tf_version }} | ||
tg_version: ${{ env.tg_version }} | ||
tg_dir: ${{ inputs.working_directory }} | ||
tg_command: 'validate' | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
|
||
- name: Plan | ||
if: github.event_name == 'pull_request' | ||
uses: gruntwork-io/terragrunt-action@v2 | ||
id: plan | ||
with: | ||
tf_version: ${{ env.tf_version }} | ||
tg_version: ${{ env.tg_version }} | ||
tg_dir: ${{ inputs.working_directory }} | ||
tg_command: 'plan' | ||
tg_comment: 1 | ||
continue-on-error: true | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
TF_VAR_digitalocean_token: ${{ inputs.do_token }} | ||
TF_VAR_AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
TF_VAR_AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
TF_VAR_R2_ACCESS_KEY: ${{ inputs.r2_access_key }} | ||
TF_VAR_R2_SECRET_KEY: ${{ inputs.r2_secret_key }} | ||
TF_VAR_slack_token: ${{ inputs.slack_token }} | ||
TF_VAR_new_relic_api_key: ${{ inputs.new_relic_api_key }} | ||
TF_VAR_new_relic_account_id: ${{ inputs.new_relic_account_id }} | ||
|
||
- name: Find Comment | ||
if: github.event.pull_request.draft == false && | ||
github.event_name == 'pull_request' | ||
uses: peter-evans/find-comment@v2 | ||
id: fc | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: 'github-actions[bot]' | ||
body-regex: "^### Forest: ${{ inputs.environment }} Infrastructure Plan" | ||
|
||
|
||
- name: Create or Update Comment | ||
if: github.event.pull_request.draft == false && | ||
github.event_name == 'pull_request' && | ||
!contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.') | ||
uses: peter-evans/create-or-update-comment@v2 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
### Forest: ${{ inputs.environment }} Infrastructure Plan: ${{ steps.plan.outcome }} | ||
<details><summary>Show Plan</summary> | ||
``` | ||
${{ steps.plan.outputs.stdout }} | ||
``` | ||
</details> | ||
edit-mode: replace | ||
|
||
- name: Delete Comment | ||
uses: detomarco/delete-comments@v1.0.4 | ||
if: github.event.pull_request.draft == false && | ||
github.event_name == 'pull_request' && | ||
contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.') | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
|
||
- name: Terraform Plan Status | ||
shell: bash | ||
if: steps.plan.outcome == 'failure' | ||
run: exit 1 | ||
# | ||
# - name: Terraform Apply | ||
# if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
# run: | | ||
# if grep -q 'No changes.' tfplan; then | ||
# echo "No changes detected." | ||
# else | ||
# echo "Changes detected. Redeploying everything..." | ||
# terraform destroy -auto-approve -input=false | ||
# terraform apply -auto-approve -input=false | ||
# fi | ||
# shell: bash | ||
# working-directory: ${{ inputs.working_directory }} | ||
# env: | ||
# TF_VAR_do_token: ${{ inputs.do_token }} | ||
# TF_VAR_AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
# TF_VAR_AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
# AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
# AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
# TF_VAR_slack_token: ${{ inputs.slack_token }} | ||
# TF_VAR_R2_ACCESS_KEY: ${{ inputs.r2_access_key }} | ||
# TF_VAR_R2_SECRET_KEY: ${{ inputs.r2_secret_key }} | ||
# 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 }} | ||
# | ||
# - name: Terraform 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 }} | ||
# TF_VAR_AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
# TF_VAR_AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
# AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }} | ||
# AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }} | ||
# TF_VAR_R2_ACCESS_KEY: ${{ inputs.r2_access_key }} | ||
# TF_VAR_R2_SECRET_KEY: ${{ inputs.r2_secret_key }} | ||
# TF_VAR_slack_token: ${{ inputs.slack_token }} | ||
# 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 }} | ||
# run: | | ||
# terraform destroy -auto-approve -input=false | ||
# terraform apply -auto-approve -input=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters