generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: CD - Terraform Module Deplyment | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
env: | ||
MODULE_DEPLOYMENT_DIR: "module-deployment" | ||
|
||
jobs: | ||
set-outputs: | ||
name: Set Output Vars | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
branch: ${{ steps.var.outputs.branch }} | ||
steps: | ||
- id: var | ||
run: | | ||
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | ||
BRANCH="$(echo "$BRANCH" | sed 's;/;%2F;g')" | ||
echo "branch=$BRANCH" >> $GITHUB_OUTPUT | ||
terraform-apply: | ||
name: Terraform Apply | ||
runs-on: ubuntu-latest | ||
needs: set-outputs | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} | ||
|
||
- name: Get terraform version | ||
id: get-terraform-version | ||
run: | | ||
DOTFILE_VERSION=$(cat ${{ env.MODULE_DEPLOYMENT_DIR }}/.terraform-version) | ||
echo "version=$DOTFILE_VERSION" >> $GITHUB_OUTPUT | ||
- name: Setup Terraform | ||
uses: hashicorp/[email protected] | ||
with: | ||
terraform_version: ${{ steps.get-terraform-version.outputs.version }} | ||
|
||
- name: Download tfvars and backend | ||
run: | | ||
aws s3 cp s3://${{ secrets.TFVARS_S3_BUCKET_NAME }}/${{ secrets.TFVARS_FILENAME }} ${{ env.MODULE_DEPLOYMENT_DIR }}/. | ||
aws s3 cp s3://${{ secrets.TFVARS_S3_BUCKET_NAME }}/${{ secrets.TF_BACKEND_FILENAME }} ${{ env.MODULE_DEPLOYMENT_DIR }}/. | ||
- name: Replace module version with Revision tag | ||
run: | | ||
sed -i "s/ source = \"github.com\/chris-qa-org\/terraform-aws-tfl-notice-board.*/ source = \"github.com\/chris-qa-org\/terraform-aws-tfl-notice-board?ref=${{ github.ref_name }}\"/g" ${{ env.MODULE_DEPLOYMENT_DIR }}/tfl-notice-board.tf | ||
- name: Run a Terraform init | ||
run: | | ||
terraform -chdir=${{ env.MODULE_DEPLOYMENT_DIR }} \ | ||
init | ||
- name: Run a Terraform validate | ||
run: | | ||
terraform -chdir=${{ env.MODULE_DEPLOYMENT_DIR }} \ | ||
validate | ||
- name: Run a Terraform format check | ||
run: | | ||
terraform -chdir=${{ env.MODULE_DEPLOYMENT_DIR }} \ | ||
fmt -check=true -diff=true | ||
- name: Run a Terraform plan | ||
run: | | ||
terraform -chdir=${{ env.MODULE_DEPLOYMENT_DIR }} \ | ||
plan | ||
- name: Run a Terraform apply | ||
run: | | ||
terraform -chdir=${{ env.MODULE_DEPLOYMENT_DIR }} \ | ||
apply |