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 string | Cloud provider for the infrastructure | aws |
-m, --mode string | Import strategy: replace or merge | replace |
-h, --help | Help for import state. | n/a |
Global flags (with this command)
| Flag | Description |
|---|---|
-f, --file string | Path to the Terraform state file (required). |
--appstack-id string | Appstack ID to import into an existing appstack (creates a new appstack version). |
--appstack-name string | Appstack name to create if importing into a new appstack (must be unique). |
See Global flags for --project, --output, --interactive, --log, --stackgen-home, and other globals.
Usage Guide
Use stackgen import state 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:
export STACKGEN_TOKEN=<TOKEN>Replace
<TOKEN>with your personal access token (PAT). Skip this step if you have already configured your environment. -
If you are creating an appStack inside a project workspace (not the default personal workspace):
-
Select the project workspace from the Projects dropdown.
-
From the browser address bar, copy the Project ID.
-
Run:
export STACKGEN_PROJECT=<Project ID>
You can also pass
--project <Project ID>instead of the environment variable. -
-
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 -f <path/to/.tfstate> --cloud-provider=<provider name>
Flags (this flow)
| Flag | Description | Required |
|---|---|---|
-f, --file | Path to the Terraform state file | Yes |
--cloud-provider | Cloud provider (for example AWS, Azure, GCP) | Yes |
-m, --mode | replace or merge (default replace) | No |
Example:
Import resources from the .tfstate file and create a new appStack for an Azure-based infrastructure.
stackgen import state -f /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> -f <path/to/terraform.tfstate> --cloud-provider=<provider name>
Flags (this flow)
| Flag | Description | Required |
|---|---|---|
--appstack-id | ID of the existing appStack to create a new version for | Yes |
-f, --file | Path to the Terraform state file | Yes |
--cloud-provider | Cloud provider (for example AWS, Azure, GCP) | Yes |
-m, --mode | replace or merge (default replace) | No |
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 -f /Users/abc/Downloads/terraform/terraform.tfstate --cloud-provider=aws