Cloud to Code Global Flags
You can apply global flags with the cloud2code import command to customise resource imports, including logging, filtering, and the output settings.
Usage
cloud2code import <provider> [options] [global flags]
Available Flags
| Flag | Description | Required |
|---|---|---|
--log-level or -l | Sets the logging level (debug, info, warn, error, panic, fatal). | No |
--log-type | Sets the logging output format (console, json). | No |
--tags | Filters resources by specified tags. | No |
--include | Includes only the specified resource types. | No |
--exclude | Excludes specific resource types from import. | No |
--output-dir or -o | Specifies the output directory for Terraform state files (default: current directory). | No |
--auto-import | Automatically create discovery on StackGen (default true). | No |
--name | Name that you want to use for the discovery. If a discovery with the given name already exists, it will be updated instead of creating a new one. | No |
--project | StackGen Project Id. Can also be set via STACKGEN_TEAM or PROJECT environment variables, or in ~/.stackgen/config.yaml. | No |
StackGen Configuration
Cloud2Code can connect to your StackGen tenant using environment variables or a configuration file at ~/.stackgen/config.yaml.
Configuration File
Create a file at ~/.stackgen/config.yaml with the following format:
url: https://customer.cloud.stackgen.com
token: stackgen_******
project: <stackgen-project-id>
Environment Variables
Alternatively, you can set the following environment variables:
| Variable | Description |
|---|---|
STACKGEN_URL | URL of the StackGen server |
STACKGEN_TOKEN | StackGen authentication token |
STACKGEN_TEAM | StackGen Project Id |
PROJECT | StackGen Project Id (alternative) |
Precedence
When multiple sources are configured, the following precedence applies:
- StackGen URL:
STACKGEN_URLenv var >~/.stackgen/config.yamlurlfield - StackGen Token:
STACKGEN_TOKENenv var >~/.stackgen/config.yamltokenfield - Project Id:
--projectflag >STACKGEN_TEAMenv var >PROJECTenv var >~/.stackgen/config.yamlprojectfield
If no project is specified through any of these sources, the discovery will be created in your personal workspace.
Examples
Usage
cloud2code import aws --region us-east-1 --include aws_s3_bucket,aws_instance --log-level debug --output-dir ./terraform
The above command will:
- Import S3 buckets and EC2 instances from AWS (
us-east-1). - Log details at debug level.
- Save the Terraform files in the
./terraformdirectory.
Usage
cloud2code import azure --subscription-id <subscription_id> --resource-group my-rg --exclude azure_vm --name my-azure-discovery
The above command will:
- Import all resources from an Azure Resource Group, except VMs.
- Automatically create a discovery on StackGen (since
--auto-importdefaults totrue) with the namemy-azure-discovery. - Connect to StackGen using environment variables or
~/.stackgen/config.yaml(see StackGen Configuration). - If
--projectis not specified, the discovery will be created in your personal workspace.
Usage
cloud2code import gcp --project-id <project-id> --region us-central1 --credentials <creds> --project <stackgen-project-id> --include google_storage_bucket --name my-gcp-discovery
The above command will:
- Import all the Google Storage Bucket resources present in
us-central1region. - Create a discovery named
my-gcp-discoveryon StackGen under the specified project. - Connect to StackGen using environment variables or
~/.stackgen/config.yaml(see StackGen Configuration).