Skip to main content
⏳ Estimated read time: 4 min read

stackgen import state

The stackgen import state command will parse a Terraform state file and import the infrastructure configuration into an appstack or a new version of an existing appstack.

Usage

stackgen import state [flags]

Flags

FlagDescriptionDefault
--cloud-providerCloud provider for the infrastructureaws
--appstack-idAppstack ID to import into an existing appstack. This creates a new appstack version.
--appstack-nameAppstack name to create if importing into a new appstack. It must be unique.

Usage Guide

Follow the step-by-step instructions to use the import state backend command to:

Prerequisites

Click to view

Before running this command, ensure you have:

  • StackGen CLI v0.52.0 or higher installed.
  • To install StackGen CLI, run the command:
    brew install stackgenhq/stackgen/stackgen
  • If you are creating a new appStack, you need: A valid Terraform-generated state file (.tfstate).
  • If you are creating an appStack version, you will need:
    • An updated Terraform state file (.tfstate)
    • appStack ID for an existing appStack in StackGen.
  • Configure your StackGen environment by running the command:
    export STACKGEN_TOKEN=<TOKEN> where <TOKEN> is your PAT.
    • Skip this step if you’ve already configured your environment.
  • If you’re trying to create an appsStack within a team workspace (i.e., not the default personal workspace), then:
    1. Select the team workspace from the Teams dropdown.
    2. From the browser address bar, copy the Team ID.
    3. Run the following:
      Export STACKGEN_TEAM=<Team ID>
  • This feature is supported in the following cloud providers:
    • AWS
    • Azure
    • GCP

Create New appStack

Click to view

Use this command to create a new appStack in StackGen by importing an existing Terraform state file. This is especially useful when you want to bring your current infrastructure under StackGen's visibility without manually recreating configurations.

Once imported, StackGen will analyze the resources in the state file, generate the corresponding appStack definition, and make it available for further compliance checks, versioning, and deployment actions.

important

Please read the Prerequisites section before running the command.

Usage

Create a new appStack in StackGen by importing resources from a .tfstate file.

stackgen import state --file=<path/to/.tfstate file> --cloud-provider=<provider name>

Flags

FlagDescriptionRequired
--filePath to the Terraform state fileYes
--cloud-providerThe cloud provider (e.g., AWS, Azure, GCP)Yes

Example:

Import resources from the .tfstate file and create a new appStack for an Azure-based infrastructure.

stackgen import state --file=/Users/abc/Downloads/terraform/terraform.tfstate --cloud-provider=azure

Create New Version of an Existing appStack

Click to view

Use this command to create a new version of an existing appStack by importing an updated Terraform state file. This helps keep your StackGen environment in sync with infrastructure changes and re-evaluating compliance after each iteration.

Usage

Create a new version of the specified appStack using the updated tfstate file.

stackgen import state --appstack-id=<your-appstack-id> --file=<path/to/terraform.tfstate> --cloud-provider=<provider name>

Flags

FlagDescriptionRequired
--appstack-idThe ID of the existing appStack to create a new version forYes
--filePath to the Terraform state fileYes
--cloud-providerThe cloud provider (e.g., AWS, Azure, GCP)Yes

Example:

Create a new version of the appStack with ID app-1234abcd5678efgh using the latest Terraform state file for an AWS infrastructure.

stackgen import state --appstack-id=app-1234abcd5678efgh --file=/Users/abc/Downloads/terraform/terraform.tfstate --cloud-provider=aws