Skip to main content
3 min read

Destroy StackGen-Provisioned Infrastructure

Destroy StackGen-Provisioned Infrastructure

The stackgen destroy command is used to tear down the infrastructure provisioned from exported appStack IaC configurations.

Usage​

stackgen destroy [flags]
note

If you skip adding the --apply flag, you will only be able to preview changes and not execute them.

Flags​

FlagDescription
--applyPreview and apply the infrastructure changes. This command does not require further approval.
--appstack stringAppStack UUID or name to destroy. Use stackgen appstack list, show, or ls for names and ids.
--backend-config stringArrayBackend configuration as a key=value pair or a path to an HCL file with key/value assignments. This flag can be specified multiple times.
--ci-job-url stringURL of the CI job that triggered the CLI command.
--cloud-profile stringSpecify the credential profile to use for provisioning the infrastructure. This works only for AWS. For other clouds, make sure default credentials are set.
-e, --environment stringName of the environment that belongs to the provided appStack.
-h, --helpDisplays help information for the destroy command.
--iac-tool stringIaC tool: terraform or tofu (default terraform). See IaC tool and infrastructure lifecycle.
--restrict-output-accessDo not make resource attributes available to other appStacks.
--use-runner-credentialsUse the encrypted credentials stored in StackGen Vault for this environment's runner configuration. Credentials are not written to disk and are not set as global environment variables. Requires -e / --environment. Configure runner credentials in StackGen for the environment first.
--var stringArraySpecify a value for one of the input variables. This flag can be specified multiple times.
--var-file stringVars file path. Default terraform.tfvars.json in the working directory.
-v, --verbosePrint each OpenTofu/Terraform subprocess invocation and captured stdout/stderr to stderr.

Examples

Usage 1: Destroy Infrastructure with Apply Preview​

stackgen destroy --apply --appstack 12345-uuid

The above command will:

  • Preview and apply the infrastructure changes.
  • Use the provided appStack UUID or name (12345-uuid).

Usage 2: Destroy Infrastructure with Cloud Profile​

stackgen destroy --appstack 12345-uuid --cloud-profile my-aws-profile --var-file ./custom-vars.tfvars.json

The above command will:

  • Use the provided appStack UUID or name (12345-uuid).
  • Specify the cloud profile (my-aws-profile) for AWS credential usage.
  • Use the custom variables file (./custom-vars.tfvars.json).

Usage 3: Destroy Infrastructure with Backend Configuration​

stackgen destroy --appstack 12345-uuid --backend-config 'bucket=my-bucket' --environment prod

The above command will:

  • Use the provided appStack UUID or name (12345-uuid).
  • Set the backend configuration to use my-bucket.
  • Pass the environment name prod for the appStack (-e / --environment).

Usage 4: Destroy with StackGen Vault runner credentials​

stackgen destroy --appstack <appstack-id-or-name> -e <environment> --use-runner-credentials --apply

Uses the runner credentials stored in StackGen Vault for that environment instead of a local --cloud-profile.