Skip to content

pmaldera/commercetools-terraform-generator

Repository files navigation

Commercetools Terraform Generator

A CLI tool to generate Terraform Configuration files from existing Commercetools projects.

Usage

  1. npm i commercetools-terraform-generator
  2. 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.
  3. Run npx commercetools-terraform-generator.
  4. You can now use the generated .tf files from the output directory in your IaC setup using the labd commercetools terraform provider.

Configuration

IMPORT_RESOURCE - required

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:

Example:

  • "types,tax_category""
  • "types"
  • "all"

OUTPUT_DIR - required

The directory to generate the Terraform .tf files.

Examples:

  • "output"
  • "/home/user/terraform_files/"

CTP_AUTH_URL - required

Specifies the Commercetools auth url to use.

Example: "https://auth.europe-west1.gcp.commercetools.com/"

CTP_API_URL - required

Specifies the Commercetools api url to use.

Example: "https://api.europe-west1.gcp.commercetools.com/"

CTP_CLIENT_ID - required

Specifies the Commercetools API Client id to use, more info in the HTTP API autorization Commercetools documentation.

CTP_CLIENT_SECRET - required

Specifies the Commercetools API Client secret to use, more info in the HTTP API autorization Commercetools documentation.

CTP_PROJECT_KEY - required

Specifies the Commercetools project you want to import the resources from.

CTP_SCOPES - optional

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"

ENABLE_CTP_LOGS - optional

Specifies the Commercetools logger should be used.

Supported values: "true" or "false". "false" if not specified.

SEPERATE_RESOURCES - optional

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.

SANITIZE_RESOURCES_LABELS - optional

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 (-).

"All included" docker folder

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.

  1. Add your .env file in the folder.
  2. Install the npm package and init terraform: docker compose up
  3. Generate the terraform configuration files: sudo docker compose run --rm generator npx commercetools-terraform-generator
  4. Plan terraform changes: docker compose run --rm terraform plan
  5. Apply the changes: docker compose run --rm terraform apply

Todolist

About

A CLI tool to generate Terraform Configuration files from existing Commercetools projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published