fix(ci): update terraform job template
This commit is contained in:
@@ -21,58 +21,77 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Retrieve artifacts
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
- name: Check if job errored
|
||||||
|
shell: bash
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
echo "code=$(cat exitcode)" >> $GITHUB_OUTPUT
|
||||||
|
if [ "$(cat exitcode)" -lt 2 ]; then
|
||||||
|
exit "$(cat exitcode)";
|
||||||
|
fi
|
||||||
- name: Clone blackbox repo
|
- name: Clone blackbox repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
with:
|
with:
|
||||||
repository: xaked/blackbox
|
repository: xaked/blackbox
|
||||||
path: blackbox
|
path: blackbox
|
||||||
ref: master
|
ref: master
|
||||||
- name: Install blackbox
|
- name: Install blackbox
|
||||||
shell: bash
|
shell: bash
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
run: |
|
run: |
|
||||||
cd blackbox || exit 1;
|
cd blackbox || exit 1;
|
||||||
make copy-install;
|
make copy-install;
|
||||||
cd ${{ github.workspace }};
|
cd ${{ github.workspace }};
|
||||||
rm -rf blackbox;
|
rm -rf blackbox;
|
||||||
- uses: hashicorp/setup-terraform@v2
|
- uses: hashicorp/setup-terraform@v2
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
with:
|
with:
|
||||||
terraform_version: 1.5.7
|
terraform_version: 1.5.7
|
||||||
cli_config_credentials_token: ${{ secrets.tf-api-token }}
|
cli_config_credentials_token: ${{ secrets.tf-api-token }}
|
||||||
- name: Clone repo
|
- name: Clone repo
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Decrypt secrets
|
- name: Decrypt secrets
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
echo ${{ secrets.gpg-key }} | base64 -d | gpg --import;
|
echo ${{ secrets.gpg-key }} | base64 -d | gpg --import;
|
||||||
blackbox_decrypt_all_files;
|
blackbox_decrypt_all_files;
|
||||||
- name: Setup SSH key
|
- name: Setup SSH key
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
uses: benoitchantre/setup-ssh-authentication-action@1.0.1
|
uses: benoitchantre/setup-ssh-authentication-action@1.0.1
|
||||||
with:
|
with:
|
||||||
private-key: ${{ secrets.ssh-private-key }}
|
private-key: ${{ secrets.ssh-private-key }}
|
||||||
private-key-name: id_ed25519
|
private-key-name: id_ed25519
|
||||||
known-hosts: ${{ secrets.ssh-known-hosts }}
|
known-hosts: ${{ secrets.ssh-known-hosts }}
|
||||||
- name: Restore terraform cache
|
- name: Restore terraform cache
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
id: cache-terraform-restore
|
id: cache-terraform-restore
|
||||||
with:
|
with:
|
||||||
path: .terraform
|
path: .terraform
|
||||||
key: ${{ github.repository }}-${{ runner.os }}-${{ runner.arch }}-tf
|
key: ${{ github.repository }}-${{ runner.os }}-${{ runner.arch }}-tf
|
||||||
- name: Download terraform plan
|
|
||||||
uses: actions/download-artifact@v3
|
|
||||||
with:
|
|
||||||
name: tfplan
|
|
||||||
- name: Run terraform init
|
- name: Run terraform init
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: terraform init
|
run: terraform init
|
||||||
- name: Run terraform validate
|
- name: Run terraform validate
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: terraform validate
|
run: terraform validate
|
||||||
- name: Run terraform apply
|
- name: Run terraform apply
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
id: tfplan
|
id: tfplan
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
terraform apply -input=false -auto-approve tfplan.binary;
|
terraform apply -input=false -auto-approve tfplan.binary;
|
||||||
- name: Save terraform cache
|
- name: Save terraform cache
|
||||||
|
if: ${{ steps.check.outputs.code == 2 }}
|
||||||
uses: actions/cache/save@v3
|
uses: actions/cache/save@v3
|
||||||
id: cache-terraform-save
|
id: cache-terraform-save
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -14,16 +14,11 @@ on:
|
|||||||
ssh-known-hosts:
|
ssh-known-hosts:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
outputs:
|
|
||||||
tfplanexitcode:
|
|
||||||
value: ${{ jobs.tf-plan.outputs.tfplanexitcode }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tf-plan:
|
tf-plan:
|
||||||
name: Terraform Plan
|
name: Terraform Plan
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
|
||||||
tfplanexitcode: ${{ steps.tfplan.outputs.exitcode }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: hashicorp/setup-terraform@v2
|
- uses: hashicorp/setup-terraform@v2
|
||||||
@@ -73,17 +68,21 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
terraform plan -detailed-exitcode -out=tfplan.binary -input=false;
|
terraform plan -detailed-exitcode -out=tfplan.binary -input=false;
|
||||||
|
printf "$?" > exitcode;
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
- name: Check if job errored
|
- name: Upload artifacts
|
||||||
if: ${{ steps.tfplan.outputs.exitcode == 1 }}
|
|
||||||
shell: sh
|
|
||||||
run: exit 1
|
|
||||||
- name: Upload terraform plan if diffs are detected
|
|
||||||
if: ${{ steps.tfplan.outputs.exitcode == 2 }}
|
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: tfplan
|
name: artifacts
|
||||||
path: tfplan.binary
|
path: |
|
||||||
|
tfplan.binary
|
||||||
|
exitcode
|
||||||
|
- name: Check if job errored
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ "$(cat exitcode)" == "1" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
- name: Save terraform cache
|
- name: Save terraform cache
|
||||||
uses: actions/cache/save@v3
|
uses: actions/cache/save@v3
|
||||||
id: cache-terraform-save
|
id: cache-terraform-save
|
||||||
|
|||||||
Reference in New Issue
Block a user