Public github actions workflows that are reusable within StrongMind.
graph LR
Code owners can be found in CODEOWNERS file
-
Check for Protected Resources
- If There Are Protected Resources:
- Either manually delete the protected resources via the AWS Management Console or follow the manual steps from the other method, skipping this method.
- You need to manually delete a resource in AWS if pulumi asks you to unprotect a resource.
- If There Are Protected Resources:
-
Clone the Repository
- Clone the repository for the infrastructure you want to delete.
-
Locate the Deployment Workflow
- Go to the
.github/workflows
folder and find the deployment file for the environment you want to delete. - For example, if you are deleting production infrastructure, look for
deploy-prod.yml
.
- Go to the
-
Modify the GitHub Action Workflow
- Open the deployment file (
deploy-prod.yml
or similar). - Locate the job that references:
uses: strongmind/public-reusable-workflows/.github/workflows/aws-deploy.yml@main
- Find or create the
with
section in that job. - Add 'pulumi-command: down' environment variable to the
with
section:with: pulumi-command: down
- Open the deployment file (
-
Push Changes and Merge
- Push the changes to a new branch.
- Create a pull request (PR) and merge it into the main branch.
-
Trigger the GitHub Action
- If the GitHub Action doesn't automatically start after merging the PR, manually trigger it:
- Go to the GitHub Actions tab in the repository.
- Find and run the
build.yml
workflow from the GitHub Actions web UI.
- This should bring down the infrastructure as intended.
- NOTE: You will need to run the
build.yml
workflow everytime pulumi asks you to unprotect/delete something.- This needs to happen so that the pulumi state file is refreshed.
- If the GitHub Action doesn't automatically start after merging the PR, manually trigger it:
-
Clone the Repository
- Clone the repository for the infrastructure you want to delete.
-
Set Up Your AWS Credentials
- Ensure your
~/.aws/credentials
file has a[default]
profile linked to the AWS account where the infrastructure resides. - For example, if the infrastructure is in the StrongMind AWS account, the
[default]
profile should have access to that account.
- Ensure your
-
Set Cloudflare API Token (If Needed)
- If a Cloudflare API token is required for the infrastructure, export it as an environment variable:
export CLOUDFLARE_API_TOKEN="<cloudflare_api_token_from_bitwarden>"
- If a Cloudflare API token is required for the infrastructure, export it as an environment variable:
-
Set Up Pulumi
- Retrieve the Pulumi config passphrase from Bitwarden:
- Secret Name: "pulumi state pass Devops (and tesla)"
- Export the Pulumi passphrase:
export PULUMI_CONFIG_PASSPHRASE="<pulumi_config_passphrase_from_bitwarden>"
- Retrieve the Pulumi config passphrase from Bitwarden:
-
Login to Pulumi
- Log in to the Pulumi state file:
pulumi login s3://pulumi-state-sm/{Repository_name}
- Example:
pulumi login s3://pulumi-state-sm/Helpers
- Log in to the Pulumi state file:
-
Navigate to the Infrastructure Directory
- Change to the infrastructure directory:
cd infrastructure
- Change to the infrastructure directory:
-
Create and Activate a Virtual Environment
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- Install the required dependencies:
python3 -m pip install -r requirements.txt
- Create a virtual environment:
-
Select the Stack
- Choose the stack you want to bring down:
pulumi stack select prod
- Replace
prod
with the name of the stack you wish to delete.
- Choose the stack you want to bring down:
-
Bring Down the Infrastructure
- Run the following command to destroy the infrastructure:
pulumi down
- Dealing with Protected Resources:
- If Protected by Pulumi:
- Pulumi will provide instructions to unprotect the resource.
- Run
pulumi down
again after unprotecting the resource. - If the issue persists, follow the steps in the "If Protected by AWS" section.
- Note: If there are multiple protected resources, you will need to unprotect them individually.
- If Protected by AWS:
- Disable protection directly in the AWS Management Console.
- After doing so, run:
pulumi refresh
- Then, run
pulumi down
again to complete the teardown.
- If Protected by Pulumi:
- Run the following command to destroy the infrastructure: