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

Generate IaC from Code

The stackgen generate command generates Infrastructure as Code (IaC) based on the application code you're working with. It's ideal for automating IaC generation for cloud infrastructure directly from your project, making deployment simpler and faster.

Usage

stackgen generate [flags]

Flags

FlagDescription
--cleanupClean up cloud components after the command runs (default: false).
-c, --cloudCloud provider for IaC generation (e.g., aws, gcp, azure). Default is aws.
-d, --deployment-typeDeployment type for the IaC (e.g., k8s, aws-ecs, aws-lambda). Default is k8s.
-h, --helpDisplays help information.
-l, --langLanguage of the code to scan (e.g., PYTHON, JAVA).
-m, --modeCLI mode to run: local, ci, or mock. Default is local.
-o, --outputDirectory for IaC output (default is current working directory).
--scanpathPath to scan for application code (default is current directory).
--skip-exportSkip exporting IaC to pre-configured Git destination.

Examples

Usage 1: Generate IaC for AWS

stackgen generate --cloud aws --deployment-type k8s --scanpath ./project-directory --output ./iac-output

This command will:

  • Generate IaC for the AWS cloud provider.
  • Set the deployment type to Kubernetes.
  • Scan the ./project-directory for code.
  • Output the IaC files to ./iac-output.

Usage 2: Generate IaC for Azure with Cleanup

This command will:

  • Generate IaC for the Azure cloud provider.
  • Set the deployment type to AWS ECS.
  • Clean up cloud components after execution.
  • Output the IaC files to ./iac-output.

Usage 3: Generate IaC for GCP in CI Mode

stackgen generate --cloud gcp --mode ci --scanpath ./src-code --skip-export

This command will:

  • Generate IaC for the GCP cloud provider.
  • Run the command in CI mode.
  • Scan the code in ./src-code.
  • Skip exporting to Git.