Simple Terraform Wrapper Module for Deploying an Azure Blockchain Service

Itay Podhajcer
Microsoft Azure
Published in
2 min readFeb 15, 2021

Azure Blockchain Service, Microsoft Azure’s managed blockchain offering, delivers a simple deployment of a multi-node blockchain solution, without the hustle of defining and managing the underlying virtual machines, storage and network.

As the service is still in preview, at least at the moment, some scenarios that are common with cloud resources that are already in general availability, are not available for the Azure Blockchain Service. One of those scenarios, deploying the resource using Terraform, can be overcome by wrapping the existing Azure Resource Manager (ARM) template for the service with a simple Terraform module, and that is exactly what this article will be covering.

The Source Code

A complete implementation of the module, including two examples of how to use the module can be found in this GitHub repository:

Additionally, the module was also published to the Terraform Registry, and can be consumed directly from there. You can follow the provisioning instructions for blockchain-service-wrapper to use it in your scripts.

The Script

The module will be constructed by two smaller modules, each wrapping an ARM template required for deploying an Azure Blockchain Service:

The member module wraps the root template of the service using a parameterized template file:

Which is loaded and populated by the member module’s main Terraform file:

For brevity, the variables files, which are straight forward, won’t be covered by the article, but can be found in the source code’s repo.

The transaction module does the same thing for transaction node ARM template:

And the module’s main Terraform file that loads and populates it:

Note that this module doesn’t create a resource, but instead, just populates a variable with the result of the processed template file and creates an output from that variable:

This is related to the structure of the ARM templates, where transaction nodes resource templates are sub-resources of the member resource templates (see resoruces field in the documentation), so the Terraform modules need to enable that same hierarchy to be constructed.

Deployment Testing

Once we have both our modules, testing it is just a matter of adding it to a Terraform script, making sure that transaction node modules are create before member modules and passed to the member as argument values, in the following manner (taken from the source code’s repo):

Conclusion

Although this solution is a great workaround for not having an official Terraform resource at the moment, it is still recommended to keep checking whether an official has been released and update the scripts that use the workaround when possible.

--

--

Itay Podhajcer
Microsoft Azure

Tech expert with 20+ years’ experience as CTO, Chief Architect, and Consultant. 3x Microsoft MVP award winner. Passionate blogger and open-source contributor