Skip to content

initial commit

initial commit #1

Workflow file for this run

# This workflow is designed to be run as needed to remove costly resources
name: Terraform Cleanup - Cost Savings
run-name: Terraform Cleanup - Cost Savings (Dev, Test, Prod)
on:
workflow_dispatch:
inputs:
resource_targets:
description: Comma-separated list of resources to target for destruction (optional). If omitted, all resources in the selected stack will be destroyed.
required: false
type: string
stack_name:
description: Name of Terraform stack.
required: true
type: choice
options:
- api
- oidc
- vpc
default: vpc
# schedule:
# - cron: '0 0 * * *' # This represents daily at 5 PM PST
permissions:
contents: read
id-token: write
env:
# Comma-separated list of resources to target for destruction
VPC_TARGETS: aws_eip.nat,aws_nat_gateway.nat,aws_internet_gateway.default
jobs:
env-vars:
name: Set Env Vars as Outputs
runs-on: ubuntu-latest
outputs:
RESOURCE_TARGETS: ${{ steps.set-targets.outputs.resource_targets }}
steps:
- name: Set Targets for Manual Trigger
if: ${{ github.event_name == 'workflow_dispatch' }}
id: set-targets
run: |
echo "resource_targets=${{ github.event.inputs.resource_targets }}" >> $GITHUB_ENV
- name: Set Targets for Scheduled Run
if: ${{ github.event_name == 'schedule' }}
id: set-targets
run: |
# Grab preset target values from environment variable
echo "resource_targets=$VPC_TARGETS" >> $GITHUB_ENV
tf-destroy:
name: Terraform Cleanup
needs:
- env-vars
strategy:
fail-fast: false
matrix:
stack_name:
- vpc
environment:
- [dev, '${{ vars.DEV_ACCOUNT_ID }}']
- [test, '${{ vars.TEST_ACCOUNT_ID }}']
- [prod, '${{ vars.PROD_ACCOUNT_ID }}']
uses: chrisba11/terraform-feature-stacks/.github/workflows/reusable-workflows/tf_destroy.yml@main

Check failure on line 69 in .github/workflows/cost_cleanup.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/cost_cleanup.yml

Invalid workflow file

invalid value workflow reference: workflows must be defined at the top level of the .github/workflows/ directory
with:
aws_account_id: ${{ matrix.environment[1] }}
aws_region: ${{ vars.AWS_REGION }}
environment: ${{ matrix.environment[0] }}
resource_targets: ${{ needs.env-vars.outputs.RESOURCE_TARGETS }}
role_name: GithubActionsRole-ReadOnly
terraform_version: =1.7.0
tf_backend_name: ${{ vars.TF_BACKEND_PREFIX }}-${{ matrix.environment[0] }}
tf_backend_key: ${{ github.event.repository.name }}/${{ matrix.stack_name }}
tfvars_path: ./environments/${{ matrix.environment[0] }}.tfvars
working_directory: infra/tf/stacks/${{ matrix.stack_name }}