Generate Infrastructure as Code (IaC)
The stackgen generate
command is used to generate Infrastructure as Code (IaC) files for a project. This command helps automate and streamline deployment workflows by generating IaC for cloud infrastructure based on the code you are working with.
Usage
stackgen generate [flags]
Flags
Flag | Description |
---|---|
--cleanup | Cleanup the cloud components after the command is run. Defaults to false . |
-c, --cloud string | The cloud provider for which the IaC is to be generated. Must be one of [aws, gcp, azure] . Defaults to aws . |
-d, --deployment-type string | The type of deployment to generate. Must be one of [k8s, aws-ecs, aws-lambda, aks-tf] . Defaults to k8s . |
-h, --help | Displays help information for the generate command. |
-l, --lang string | The programming language of the code to scan (e.g., JAVA , PYTHON ). |
-m, --mode string | The mode used to run CLI. Options are local , ci , and mock . Defaults to local . |
-o, --output string | The directory to output the deployment files. Defaults to the current working directory (/home/user ). |
--scanpath string | The code path to scan. Defaults to the current working directory (/home/user ). |
--skip-export | Skip exporting the generated IaC to a pre-configured Git destination. |
Examples
Usage 1: Generate IaC for AWS
stackgen generate --cloud aws --deployment-type k8s --scanpath ./project-directory --output ./iac-output
The above command will:
- Generate IaC for the AWS cloud provider.
- Set the deployment type to Kubernetes (
k8s
). - Scan the code in the specified directory (
./project-directory
). - Save the generated IaC files to the
./iac-output
directory.
Usage 2: Generate IaC for Azure with Cleanup
stackgen generate --cloud azure --deployment-type aws-ecs --cleanup --output ./iac-output
The above command will:
- Generate IaC for the Azure cloud provider.
- Set the deployment type to AWS ECS (
aws-ecs
). - Cleanup cloud components after the command is executed.
- Output the IaC files to the
./iac-output
directory.
Usage 3: Generate IaC for GCP in CI Mode
stackgen generate --cloud gcp --mode ci --scanpath ./src-code --skip-export
The above command will:
- Generate IaC for the GCP cloud provider.
- Run the CLI in CI mode.
- Scan the code in the
./src-code
directory. - Skip exporting the generated IaC to the pre-configured Git destination.