Destroy Environment #30
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
name: 'Destroy Environment' | |
on: | |
workflow_dispatch: | |
inputs: | |
deploy-env: | |
description: 'Environment to destroy' | |
required: true | |
type: choice | |
options: | |
- Pre-prod | |
default: Pre-prod | |
jobs: | |
clean_ecr_repositories: | |
runs-on: ubuntu-latest | |
environment: ${{ inputs.deploy-env }} | |
steps: | |
- name: Get Environment Name for ${{ vars.ENV_NAME }} | |
id: get_env_name | |
uses: Entepotenz/change-string-case-action-min-dependencies@v1 | |
with: | |
string: ${{ vars.ENV_NAME }} | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Delete erc repostiroy for ${{ vars.ENV_NAME }} | |
run: | | |
./deployment/delete_ecr opensupplyhub-batch-${{ steps.get_env_name.outputs.lowercase }} | |
./deployment/delete_ecr opensupplyhub-${{ steps.get_env_name.outputs.lowercase }} | |
./deployment/delete_ecr opensupplyhub-kafka-${{ steps.get_env_name.outputs.lowercase }} | |
./deployment/delete_ecr opensupplyhub-deduplicate-${{ steps.get_env_name.outputs.lowercase }} | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: "eu-west-1" | |
destroy: | |
runs-on: ubuntu-latest | |
environment: ${{ inputs.deploy-env }} | |
needs: clean_ecr_repositories | |
steps: | |
- name: Get Environment Name for ${{ vars.ENV_NAME }} | |
id: get_env_name | |
uses: Entepotenz/change-string-case-action-min-dependencies@v1 | |
with: | |
string: ${{ vars.ENV_NAME }} | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Checkout config repository | |
uses: actions/checkout@v4 | |
with: | |
repository: 'opensupplyhub/ci-deployment' | |
path: 'terraform-config' | |
token: ${{ secrets.PAT }} | |
- name: Copy tfvars for ${{ vars.ENV_NAME }} | |
run: | | |
cat "terraform-config/environments/${{ env.TFVAR_NAME }}" "deployment/environments/${{env.TFVAR_NAME}}" > "deployment/terraform/${{ env.SETTINGS_BUCKET }}.tfvars" | |
env: | |
SETTINGS_BUCKET: oshub-settings-${{ steps.get_env_name.outputs.lowercase }} | |
TFVAR_NAME: terraform-${{steps.get_env_name.outputs.lowercase}}.tfvars | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.4.0 | |
terraform_wrapper: false | |
- name: Terraform destroy for ${{ vars.ENV_NAME }} | |
run: ./deployment/infra destroy | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
SETTINGS_BUCKET: oshub-settings-${{ steps.get_env_name.outputs.lowercase }} | |
AWS_DEFAULT_REGION: "eu-west-1" |