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
Flag | Description | Default |
---|---|---|
--cloud-provider | Cloud provider for the infrastructure | aws |
--appstack-id | Appstack ID to import into an existing appstack. This creates a new appstack version. | — |
--appstack-name | Appstack 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.
- An updated Terraform state file (
- 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:
- Select the team workspace from the Teams dropdown.
- From the browser address bar, copy the Team ID.
- 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.
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
Flag | Description | Required |
---|---|---|
--file | Path to the Terraform state file | Yes |
--cloud-provider | The 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
Flag | Description | Required |
---|---|---|
--appstack-id | The ID of the existing appStack to create a new version for | Yes |
--file | Path to the Terraform state file | Yes |
--cloud-provider | The 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