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
Flag | Description |
---|---|
--cleanup | Clean up cloud components after the command runs (default: false). |
-c, --cloud | Cloud provider for IaC generation (e.g., aws, gcp, azure). Default is aws. |
-d, --deployment-type | Deployment type for the IaC (e.g., k8s, aws-ecs, aws-lambda). Default is k8s. |
-h, --help | Displays help information. |
-l, --lang | Language of the code to scan (e.g., PYTHON, JAVA). |
-m, --mode | CLI mode to run: local, ci, or mock. Default is local. |
-o, --output | Directory for IaC output (default is current working directory). |
--scanpath | Path to scan for application code (default is current directory). |
--skip-export | Skip 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.