A CLI tool to generate Terraform Configuration files from existing Commercetools projects.
npm i commercetools-terraform-generator- Use the different env values to configure the generator (see Configuration). If a .env is provided at the root of your project it will be used.
- Run
npx commercetools-terraform-generator. - You can now use the generated
.tffiles from the output directory in your IaC setup using the labd commercetools terraform provider.
The resources to import from the commercetools project and transform into terraform files, separated by commas. Values should correspond to at least one of the resources of labd commercetools terraform provider.
Supported values:
"channel": Commercetools channels - resource name will be the channel's key."type": Commercetools Types - resource name will be the type's key"tax_category": Commercetools tax category including their tax rates and sub rates - resource name will be the category's key and the tax rate's id (subrate don't have any unique identifier.)"all": All of the supported values above.
Example:
"types,tax_category"""types""all"
The directory to generate the Terraform .tf files.
Examples:
"output""/home/user/terraform_files/"
Specifies the Commercetools auth url to use.
Example: "https://auth.europe-west1.gcp.commercetools.com/"
Specifies the Commercetools api url to use.
Example: "https://api.europe-west1.gcp.commercetools.com/"
Specifies the Commercetools API Client id to use, more info in the HTTP API autorization Commercetools documentation.
Specifies the Commercetools API Client secret to use, more info in the HTTP API autorization Commercetools documentation.
Specifies the Commercetools project you want to import the resources from.
Specifies the scopes you want to use, separated by spaces. If not specified all scopes defined for the API Client will be used.
Examples:
"manage_types:myproject""manage_types:myproject manage_tax_categories:myproject"
Specifies the Commercetools logger should be used.
Supported values: "true" or "false". "false" if not specified.
Specifies if the generated terraform configuration files should be grouped in resource type folder.
Supported values: "true" or "false". "false" if not specified, meaning all files will be generated in the directory specified by OUTPUT_DIR.
Specifies if the data used to generate resources' labels should be sanitized.
Enabling this parameter makes sure a resource name/label starts with a letter or underscore (by adding an underscore to the value used for the label if the rule is not respected) and it contains only letters, digits, underscores and dashes (by replacing any character not respecting the rule by a dash).
Supported values: "true" or "false". "false" if not specified, meaning characters which are not letters, digits, underscores or dashes won't be replaced by a dash (-).
The docker folder in this package's github repository contains the docker compose file and the provider.tf to run both this npm package and the labd commercetools terraform provider with terraform in a docker image.
- Add your
.envfile in the folder. - Install the npm package and init terraform:
docker compose up - Generate the terraform configuration files:
sudo docker compose run --rm generator npx commercetools-terraform-generator - Plan terraform changes:
docker compose run --rm terraform plan - Apply the changes:
docker compose run --rm terraform apply
- Generate terraform's
importcommands to facilitate state import. - Create tests to ensure compatibility with upcoming updates.
- Support all types supported by the labd commercetools terraform provider.
- Add prettier/linter
- Add comments