A demo provisioner for commercetools as a Terraform Module

Demo: How to use the LabDigital Terraform commercetools provider to deploy a defined configuration with one single file

Willem Haring
Willem Haring
Sales Engineer, commercetools
Published 08 January 2024
Estimated reading time minutes

Terraform allows you to manage your infrastructure as code, which is a great solution if you want to manage PaaS or SaaS solutions. And with the release of the LabDigital Terraform provider for commercetools, you can manage the configuration of your commercetools projects. For pre-sales activities, I wanted to see if I could take this a step further and deploy a defined configuration with one single configuration file. My goal was to always have a defined setup with languages, countries, zones, tax rates, shipment methods and stores so that I could immediately start adding products to a cart and succeed with a checkout. In this article, I describe the published terraform module, the options for the various regions (EMEA, APAC and the US) and explain how to use it.

A demo provisioner for commercetools as a Terraform Module

The challenge

When preparing for a demo, it is nice to have a common dataset to work from, especially if the demo is for an international audience. If switching between languages and countries is easy, you can align your demo story around the capabilities of the platform that will resonate most with the customer. 

When looking at commercetools, it provides a large number of capabilities out of the box that can be used to illustrate the benefits of the platform, but all of them need to be configured. Configuring commercetools is not that complicated, but can be time-consuming and is repetitive work that can be avoided. 

A couple of months ago, commercetools improved its 60-day Free Trial. Now, when you sign up you can choose a defined setup that allows you to start with sample data. This is a huge time saver and is very useful in helping evaluate commercetools.

A demo provisioner for commercetools as a Terraform Module

Instead of choosing “start from scratch,” select the option to start with sample data. Hit continue and a project is created for you.

A demo provisioner for commercetools as a Terraform Module

After a few seconds, your project is created, including a full “good store” dataset, customers, promotions and multiple international settings.

A demo provisioner for commercetools as a Terraform Module

As a result, you’ll see a catalog with 117 products along with several categories, 6 customers, 2 product discounts and 2 cart discounts. This is an ideal starting point for an evaluation of commercetools!

In the preparation for a demo, you sometimes want to go a bit further. You want to be able to set up a defined international configuration that is tailored to the configuration of a specific customer. To make this happen, I used LabDigital’s Terraform commercetools provider to create a demo.

The end results

When I started experimenting with the provider, I immediately saw the benefits of being able to create a configuration baseline. It allowed me to create a recipe that completely describes what a configuration should look like. That recipe can have several dependencies within itself. For instance, when setting up a store, that store can depend on a supply channel, and that supply channel will need to have some countries and languages configured.

For each country, I wanted to specify a country code, the languages, the currencies and tax rates, so that it would automatically provision an environment with one distribution channel and one supply channel for that country.

A demo provisioner for commercetools as a Terraform Module

By using naming conventions, this could then simply become:

A demo provisioner for commercetools as a Terraform Module

After a couple of experiments to figure out how Terraform modules work, I was able to create a reusable module to always produce a standard international setup. The only thing I had to provide was a starting script to tell Terraform to load the module:

module "demoprovisioner" {
source = "commercetools-demo/demoprovisioner/commercetools"
configfile = "./ct-config-emea.yml"
envpath = "./../.env" /* path to .env file, defaults to .env */
}

# register the terraform provider, this needs to happen in the root module
terraform {
  required_providers {
     commercetools = {
      source = "labd/commercetools"
    }
  }
}


provider "commercetools" {
   client_id = module.demoprovisioner.config.client.client_id
   client_secret = module.demoprovisioner.config.client.client_secret
   project_key = module.demoprovisioner.config.client.project_key
   token_url = module.demoprovisioner.config.client.auth_url
   api_url = module.demoprovisioner.config.client.api_url
   scopes = module.demoprovisioner.config.client.scopes
}

Couple of things to note here:

  • The config file points to a .yaml file that holds the configuration you would like to provision.

  • The envpath points to a .env file that holds the client credentials to the commercetools project.

  • I also added support for shipment methods and configured a zone setup so that multiple zones are available for shipment methods, with shipment rates for the configured zones.

With this, you can provision an environment simply by performing the following actions:

terraform init

This will load all the dependencies from the Terraform registry, including the demo provisioned.

terraform plan

This will compare the actual configuration with the desired configuration, and will show what will be changes in the target when applied.

terraform apply

This will apply the configuration to the target, leading to a fully configured commercetools project setup.

On GitHub, the following starting configurations are available:


The terraform module is published here: https://registry.terraform.io/modules/commercetools-demo/demoprovisioner/commercetools/latest 

To explore all of the amazing capabilities of commecetools Composable Commerce solutions and experiment with the Terraform provider, sign up for our 60-Day Free Trial today.

Willem Haring
Willem Haring
Sales Engineer, commercetools

Willem has been working in retail technology since the beginning of 2000. He has worked with several technology companies and with clients on point of sales, stores infrastructure, reporting and dashboarding. He has been a participating member on the ARTS committee for the data warehouse chapter under ARTS XML. At commercetools, Willem works with clients, prospects and customers to translate complicated use cases to workable eCommerce solutions based on commercetools.

Related Blog Posts