-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): adding in raw terraform commands
- Loading branch information
Showing
4 changed files
with
188 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: 'Execute Raw Terraform' | ||
description: 'Builds and either plans or applies a terraform environment' | ||
inputs: | ||
scope: | ||
description: 'Turbo Repo scope to run the build for' | ||
required: true | ||
stack-output-path: | ||
description: 'The path where CDKTF outputs the terraform json' | ||
required: true | ||
environment: | ||
description: 'The node environment to build for' | ||
required: true | ||
default: 'development' | ||
behavior: | ||
description: The behavior that Terraform should use, either plan or apply | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Install tfenv | ||
shell: bash | ||
run: | | ||
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv | ||
# Setup Terraform Comment | ||
- uses: shmokmt/actions-setup-tfcmt@v2 | ||
|
||
# Let's tell github actions we want to cache all the terraform verisons we install. | ||
# We do this to speed up terraform installing, as the cache will cache the terraform versions we download. | ||
- name: Cache tfenv installations | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.tfenv/versions | ||
key: ${{ runner.os }}-tfenv-${{ hashFiles('**/.terraform-version') }} | ||
restore-keys: | | ||
${{ runner.os }}-tfenv- | ||
# TODO: These need to request AWS credentials to run terraform | ||
# It may be best to not do AWS credentials here and do it in the calling workflow.. TBD | ||
|
||
- name: Copy Terraform Vars | ||
shell: bash | ||
run: | | ||
cd ${{ inputs.stack-output-path }} | ||
if [ "${{ inputs.environment }}" = "development" ]; then | ||
echo "Development environment specified, copying development tf vars" | ||
cp dev_backend.tfvars backend.tf | ||
else | ||
echo "Production environment specified, copying production tf vars" | ||
cp prod_backend.tfvars backend.tf | ||
fi | ||
- name: Init Terraform | ||
shell: bash | ||
run: | | ||
cd ${{ inputs['stack-output-path'] }} | ||
tfenv install | ||
tfenv use | ||
terraform init | ||
# Once TFCMT supports no change applies, change terraform apply to | ||
# tfcmt --var target:${{ inputs.scope }}-${{ inputs.environment }} apply -- terraform apply -auto-approve -lock-timeout=10m | ||
# https://github.com/suzuki-shunsuke/tfcmt/issues/1184 | ||
- name: Plan/Apply CDKTF | ||
shell: bash | ||
run: | | ||
cd ${{ inputs.stack-output-path }} | ||
if [ "${{ inputs.behavior }}" = "apply" ]; then | ||
echo "Apply behavior specified, applying terraform configuration in ${{ inputs.environment }}." | ||
terraform apply | ||
else | ||
echo "Plan behavior specified, planning terraform configuration in ${{ inputs.environment }}." | ||
tfcmt --var target:${{ inputs.scope }}-${{ inputs.environment }} plan --skip-no-changes --patch -- terraform plan -lock-timeout=10m | ||
fi |
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