Skip to content

destroy-command

destroy-command #98

name: Pull Request Destroy Handler
on:
repository_dispatch:
types:
- destroy-command
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}
GOOGLE_REGION: ${{ secrets.GOOGLE_REGION }}
GOOGLE_ZONE: ${{ secrets.GOOGLE_ZONE }}
jobs:
public_active_active:
name: Destroy resources from Public Active/Active
if: ${{ contains(github.event.client_payload.slash_command.args.unnamed.all, 'all') || contains(github.event.client_payload.slash_command.args.unnamed.all, 'public-active-active') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
WORK_DIR_PATH: ./tests/public-active-active
steps:
- name: Create URL to the run output
id: vars
run: echo ::set-output name=run-url::https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
- name: Checkout Pull Request Branch
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Set Terraform Module Source
working-directory: ${{ env.WORK_DIR_PATH }}
env:
LOGIN: ${{ github.event.client_payload.pull_request.head.repo.owner.login }}
NAME: ${{ github.event.client_payload.pull_request.head.repo.name }}
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
run: |
sed --in-place "s/source = \"..\/..\"/source = \"github.com\/$LOGIN\/$NAME?ref=$SHA\"/" main.tf
sed --in-place "s/source = \"..\/..\/fixtures\/test_proxy\"/source = \"github.com\/$LOGIN\/$NAME\/\/fixtures\/test_proxy?ref=$SHA\"/" main.tf
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_hostname: 'app.terraform.io'
cli_config_credentials_token: ${{ secrets.PUBLIC_ACTIVE_ACTIVE_TFC_TOKEN }}
terraform_version: 1.1.7
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
- name: Terraform Init
id: init
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform init -input=false -no-color
- name: Write Terraform Variables
working-directory: ${{ env.WORK_DIR_PATH }}
run: |
iact_subnet=$( dig +short @resolver1.opendns.com myip.opendns.com )
cat <<EOF > github.auto.tfvars
iact_subnet_list = ["$iact_subnet/32"]
consolidated_services_enabled = true
tfe = {
hostname = "${{ secrets.TFE_HOSTNAME }}"
organization = "${{ secrets.TFE_ORGANIZATION }}"
token = "${{ secrets.TFE_TOKEN }}"
workspace = "${{ secrets.TFE_WORKSPACE }}"
}
EOF
- name: Terraform Destroy
id: destroy
working-directory: ${{ env.WORK_DIR_PATH }}
env:
TFE_HOSTNAME: ${{ secrets.TFE_HOSTNAME }}
TFE_TOKEN: ${{ secrets.TFE_TOKEN }}
run: terraform destroy -auto-approve -input=false -no-color
- name: Update comment
if: ${{ always() }}
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
${{ format('### {0} Terraform Public Active/Active Destruction Report', job.status == 'success' && ':white_check_mark:' || ':x:') }}
${{ format(':link: [Action Summary Page]({0})', steps.vars.outputs.run-url) }}
${{ format('- {0} Terraform Init', steps.init.outcome == 'success' && ':white_check_mark:' || ':x:') }}
${{ format('- {0} Terraform Destroy', steps.destroy.outcome == 'success' && ':white_check_mark:' || ':x:') }}
private_active_active:
name: Destroy resources from Private Active/Active
if: ${{ contains(github.event.client_payload.slash_command.args.unnamed.all, 'all') || contains(github.event.client_payload.slash_command.args.unnamed.all, 'private-active-active') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
WORK_DIR_PATH: ./tests/private-active-active
steps:
- name: Create URL to the run output
id: vars
run: echo ::set-output name=run-url::https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
- name: Checkout Pull Request Branch
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Set Terraform Module Source
working-directory: ${{ env.WORK_DIR_PATH }}
env:
LOGIN: ${{ github.event.client_payload.pull_request.head.repo.owner.login }}
NAME: ${{ github.event.client_payload.pull_request.head.repo.name }}
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
run: |
sed --in-place "s/source = \"..\/..\"/source = \"github.com\/$LOGIN\/$NAME?ref=$SHA\"/" main.tf
sed --in-place "s/source = \"..\/..\/fixtures\/test_proxy\"/source = \"github.com\/$LOGIN\/$NAME\/\/fixtures\/test_proxy?ref=$SHA\"/" main.tf
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_hostname: 'app.terraform.io'
cli_config_credentials_token: ${{ secrets.PRIVATE_ACTIVE_ACTIVE_TFC_TOKEN }}
terraform_version: 1.1.7
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
- name: Terraform Init
id: init
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform init -input=false -no-color
- name: Write Terraform Variables
working-directory: ${{ env.WORK_DIR_PATH }}
run: |
cat <<EOF > github.auto.tfvars
iact_subnet_list = ["( dig +short @resolver1.opendns.com myip.opendns.com )/32"]
tfe = {
hostname = "${{ secrets.TFE_HOSTNAME }}"
organization = "${{ secrets.TFE_ORGANIZATION }}"
token = "${{ secrets.TFE_TOKEN }}"
workspace = "${{ secrets.TFE_WORKSPACE }}"
}
EOF
- name: Terraform Destroy
id: destroy
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform destroy -auto-approve -input=false -no-color
- name: Update comment
if: ${{ always() }}
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
${{ format('### {0} Terraform Private Active/Active Destruction Report', job.status == 'success' && ':white_check_mark:' || ':x:') }}
${{ format(':link: [Action Summary Page]({0})', steps.vars.outputs.run-url) }}
${{ format('- {0} Terraform Init', steps.init.outcome == 'success' && ':white_check_mark:' || ':x:') }}
${{ format('- {0} Terraform Destroy', steps.destroy.outcome == 'success' && ':white_check_mark:' || ':x:') }}
private_tcp_active_active:
name: Destroy resources from Private TCP Active/Active
if: ${{ contains(github.event.client_payload.slash_command.args.unnamed.all, 'all') || contains(github.event.client_payload.slash_command.args.unnamed.all, 'private-tcp-active-active') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
WORK_DIR_PATH: ./tests/private-active-active
steps:
- name: Create URL to the run output
id: vars
run: echo ::set-output name=run-url::https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
- name: Checkout Pull Request Branch
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Set Terraform Module Source
working-directory: ${{ env.WORK_DIR_PATH }}
env:
LOGIN: ${{ github.event.client_payload.pull_request.head.repo.owner.login }}
NAME: ${{ github.event.client_payload.pull_request.head.repo.name }}
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
run: |
sed --in-place "s/source = \"..\/..\"/source = \"github.com\/$LOGIN\/$NAME?ref=$SHA\"/" main.tf
sed --in-place "s/source = \"..\/..\/fixtures\/test_proxy\"/source = \"github.com\/$LOGIN\/$NAME\/\/fixtures\/test_proxy?ref=$SHA\"/" main.tf
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_hostname: 'app.terraform.io'
cli_config_credentials_token: ${{ secrets.PRIVATE_TCP_ACTIVE_ACTIVE_TFC_TOKEN }}
terraform_version: 1.1.7
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
- name: Terraform Init
id: init
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform init -input=false -no-color
- name: Write Terraform Variables
working-directory: ${{ env.WORK_DIR_PATH }}
run: |
iact_subnet=$( dig +short @resolver1.opendns.com myip.opendns.com )
cat <<EOF > github.auto.tfvars
iact_subnet_list = ["$iact_subnet/32"]
consolidated_services_enabled = true
tfe = {
hostname = "${{ secrets.TFE_HOSTNAME }}"
organization = "${{ secrets.TFE_ORGANIZATION }}"
token = "${{ secrets.TFE_TOKEN }}"
workspace = "${{ secrets.TFE_WORKSPACE }}"
}
EOF
- name: Terraform Destroy
id: destroy
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform destroy -auto-approve -input=false -no-color
- name: Update comment
if: ${{ always() }}
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
${{ format('### {0} Terraform Private TCP Active/Active Destruction Report', job.status == 'success' && ':white_check_mark:' || ':x:') }}
${{ format(':link: [Action Summary Page]({0})', steps.vars.outputs.run-url) }}
${{ format('- {0} Terraform Init', steps.init.outcome == 'success' && ':white_check_mark:' || ':x:') }}
${{ format('- {0} Terraform Destroy', steps.destroy.outcome == 'success' && ':white_check_mark:' || ':x:') }}
standalone_mounted_disk:
name: Destroy resources from Standalone Mounted Disk
if: ${{ contains(github.event.client_payload.slash_command.args.unnamed.all, 'all') || contains(github.event.client_payload.slash_command.args.unnamed.all, 'standalone-mounted-disk') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
WORK_DIR_PATH: ./tests/standalone-mounted-disk
steps:
- name: Create URL to the run output
id: vars
run: echo ::set-output name=run-url::https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
- name: Checkout Pull Request Branch
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Set Terraform Module Source
working-directory: ${{ env.WORK_DIR_PATH }}
env:
LOGIN: ${{ github.event.client_payload.pull_request.head.repo.owner.login }}
NAME: ${{ github.event.client_payload.pull_request.head.repo.name }}
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
run: |
sed --in-place "s/source = \"..\/..\"/source = \"github.com\/$LOGIN\/$NAME?ref=$SHA\"/" main.tf
sed --in-place "s/source = \"..\/..\/fixtures\/test_proxy\"/source = \"github.com\/$LOGIN\/$NAME\/\/fixtures\/test_proxy?ref=$SHA\"/" main.tf
- name: Create Terraform Backend to google-standalone-mounted-disk TFC Workspace
working-directory: ${{ env.WORK_DIR_PATH }}
env:
TFC_ORGANIZATION: ${{ secrets.TFC_ORGANIZATION }}
run: |
cat <<EOF > backend.tf
terraform {
backend "remote" {
organization = "$TFC_ORGANIZATION"
workspaces {
name = "google-standalone-mounted-disk"
}
}
}
EOF
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_hostname: 'app.terraform.io'
cli_config_credentials_token: ${{ secrets.STANDALONE_MOUNTED_DISK_TFC_TOKEN }}
terraform_version: 1.1.7
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
- name: Terraform Init
id: init
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform init -input=false -no-color
- name: Write Terraform Variables
working-directory: ${{ env.WORK_DIR_PATH }}
run: |
iact_subnet=$( dig +short @resolver1.opendns.com myip.opendns.com )
cat <<EOF > github.auto.tfvars
iact_subnet_list = ["$iact_subnet/32"]
consolidated_services_enabled = true
tfe = {
hostname = "${{ secrets.TFE_HOSTNAME }}"
organization = "${{ secrets.TFE_ORGANIZATION }}"
token = "${{ secrets.TFE_TOKEN }}"
workspace = "${{ secrets.TFE_WORKSPACE }}"
}
EOF
- name: Terraform Destroy
id: destroy
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform destroy -auto-approve -input=false -no-color
- name: Update comment
if: ${{ always() }}
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
${{ format('### {0} Terraform Standalone Mounted Disk Destruction Report', job.status == 'success' && ':white_check_mark:' || ':x:') }}
${{ format(':link: [Action Summary Page]({0})', steps.vars.outputs.run-url) }}
${{ format('- {0} Terraform Init', steps.init.outcome == 'success' && ':white_check_mark:' || ':x:') }}
${{ format('- {0} Terraform Destroy', steps.destroy.outcome == 'success' && ':white_check_mark:' || ':x:') }}
standalone_external_rhel8_worker:
name: Destroy resources from Standalone External RHEL8 Worker
if: ${{ contains(github.event.client_payload.slash_command.args.unnamed.all, 'all') || contains(github.event.client_payload.slash_command.args.unnamed.all, 'standalone-external-rhel8-worker') }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
env:
WORK_DIR_PATH: ./tests/standalone-external-rhel8-worker
steps:
- name: Create URL to the run output
id: vars
run: echo ::set-output name=run-url::https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
- name: Checkout Pull Request Branch
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- name: Set Terraform Module Source
working-directory: ${{ env.WORK_DIR_PATH }}
env:
LOGIN: ${{ github.event.client_payload.pull_request.head.repo.owner.login }}
NAME: ${{ github.event.client_payload.pull_request.head.repo.name }}
SHA: ${{ github.event.client_payload.pull_request.head.sha }}
run: |
sed --in-place "s/source = \"..\/..\"/source = \"github.com\/$LOGIN\/$NAME?ref=$SHA\"/" main.tf
sed --in-place "s/source = \"..\/..\/fixtures\/test_proxy\"/source = \"github.com\/$LOGIN\/$NAME\/\/fixtures\/test_proxy?ref=$SHA\"/" main.tf
- name: Create Terraform Backend to google-standalone-external-rhel8-worker TFC Workspace
working-directory: ${{ env.WORK_DIR_PATH }}
env:
TFC_ORGANIZATION: ${{ secrets.TFC_ORGANIZATION }}
run: |
cat <<EOF > backend.tf
terraform {
backend "remote" {
organization = "$TFC_ORGANIZATION"
workspaces {
name = "google-standalone-external-rhel8-worker"
}
}
}
EOF
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_hostname: 'app.terraform.io'
cli_config_credentials_token: ${{ secrets.STANDALONE_EXTERNAL_RHL8_WORKER_TFC_TOKEN }}
terraform_version: 1.1.7
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
- name: Terraform Init
id: init
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform init -input=false -no-color
- name: Write Terraform Variables
working-directory: ${{ env.WORK_DIR_PATH }}
run: |
iact_subnet=$( dig +short @resolver1.opendns.com myip.opendns.com )
cat <<EOF > github.auto.tfvars
iact_subnet_list = ["$iact_subnet/32"]
consolidated_services_enabled = true
tfe = {
hostname = "${{ secrets.TFE_HOSTNAME }}"
organization = "${{ secrets.TFE_ORGANIZATION }}"
token = "${{ secrets.TFE_TOKEN }}"
workspace = "${{ secrets.TFE_WORKSPACE }}"
}
EOF
- name: Terraform Destroy
id: destroy
working-directory: ${{ env.WORK_DIR_PATH }}
run: terraform destroy -auto-approve -input=false -no-color
- name: Update comment
if: ${{ always() }}
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
${{ format('### {0} Terraform Standalone External RHEL8 Worker Destruction Report', job.status == 'success' && ':white_check_mark:' || ':x:') }}
${{ format(':link: [Action Summary Page]({0})', steps.vars.outputs.run-url) }}
${{ format('- {0} Terraform Init', steps.init.outcome == 'success' && ':white_check_mark:' || ':x:') }}
${{ format('- {0} Terraform Destroy', steps.destroy.outcome == 'success' && ':white_check_mark:' || ':x:') }}