Provisioning commercetools projects with Pulumi
TechSeptember 21, 2021

Provisioning commercetools projects with Pulumi

This article introduces the commercetools Pulumi plugin ๐Ÿš€. This plugin allows you to provision commercetools resources, such as project settings, product types and integrations in common programming languages like C#, TypeScript, Go & Python.

Infrastructure as Code

At Aviva Solutions we have been using Cloud Infrastructure from the start, specifically Microsoft Azure. One thing we learned from the start is that it's crucial to automate provisioning of everything. This makes it a lot easier to spin up extra resources when needed or to spin up temporary development/test environments. It also makes sure you can do these things in a repetitive way.

โ€œ

Infrastructure as code (IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools Wikipedia

Pulumi

There are a lot of provisioning tools out there and most of them use configuration files or some proprietary language. Pulumi is a fairly new tool that allows you to provision your cloud infrastructure using a programming language. Pulumi supports using TypeScript, C#, GO and Python. We don't have a dedicated DevOps role in our team and the developers also take care of provisioning the infrastructure. Using Pulumi allows them to use the language they know. Using a typed language like C# or TypeScript also gives you code completion and high discoverability. Another big advantage is that your provisioning code gets compiled and errors get spotted right away. This is what provisioning a new Azure Storage Account looks like with Pulumi:

// Create an Azure Resource Group
var resourceGroup = new ResourceGroup("storefront-integration");

// Create an Azure Storage Account
var storageAccount = new Account("storage", new AccountArgs
{
    ResourceGroupName = resourceGroup.Name,
    AccountReplicationType = "LRS",
    AccountTier = "Standard"
});

commercetools

commercetools is a headless e-commerce platform that is ranked as a leader in Digital Commerce by Gartner and Forrester. We use commercetools because of its maturity and the high quality of the API's and documentation. Instead of adding feature after feature, commercetools seems to focus on making sure they get the core commerce features right and everything else you can do through extensibility. In our experience it's a really flexible platform. It's also Cloud Native, so no need to manage your own infrastructure.

We were already provisioning all the Azure resources, but we still needed to manually configure the integration in commercetools. For example, we have a Azure function that updates a search index whenever a product changes in commercetools. This Azure function listens to a queue in Azure. commercetools has this concept of Subscriptions, which can be used to automatically deliver a message to an Azure, Amazon Web Services, or Google Cloud Platform queue. Subscriptions can be configured through the commercetools API. There was also a lot of other commercetools configuration that was still created by hand, like project settings, product definitions, etc.

We were already provisioning all the Azure resources, but we still needed to manually configure the integration in commercetools

The folks over at Lab Digital๐Ÿ‘‹ saw the same need as us ๐Ÿ™ and they have created a high quality Terraform provider for commercetools. Terraform is a provisioning tool that uses a proprietary language: HashiCorp Configuration Language (HCL). As we mentioned before, we prefer to use a language like C# or TypeScript. Fortunately, it's possible to create a Pulumi plugin that acts as a bridge to a Terraform provider. So, thats exactly what we did.

The Pulumi commercetools plugin uses the Lab Digital Terraform provider under the hood. We can now provision commercetools resources using our language of choice. For example, this is how we provision a commercetools Subscription. The Connection string used is the output of the Azure Queue we created in the same project:

new Pulumi.commercetools.Subscription("Index update", new Pulumi.commercetools.SubscriptionArgs
{
    Key = "index-update",
    Destination = new SubscriptionDestinationArgs
    {
        Type = "azure_servicebus",
        ConnectionString = IndexUpdateConnectionString,
        Region = "not_used",
        Uri = "http://notused.com",
    },
    Messages = new List<SubscriptionMessageArgs>
    {
        new SubscriptionMessageArgs
        {
            ResourceTypeId = "product",
            Types = new List<string>
            {
                "ProductPublished"
            }
        }
    },
});

Get started

Instructions on how to get started can be found in the Github repository. Please let us know what you think.

Jonne Kats
Written by Jonne Kats
On September 21, 2021