configPath @ Terraform Custom Provider For MongoDB OPS Manager

configPath @ Terraform Custom Provider For MongoDB OPS Manager

In this second article about the Terraform Custom Provider For MongoDB OPS Manager, I'm going to show how it was designed to be flexible.

When the customopsmanager provider is declared, we have to inform 3 attributes: datacenter, opsenv and configpath.

1.00

Let's dive into the configPath, it's a directory in the file system where template files and json files are expected, as the following image.

1.00

In simple words, each file in the config path will be mapped into its respective struct, giving us flexibility to deploy resources that can fit different standards.

For example, at "{configPath}/common/replicaSetMember/secondary.json.tmpl" we have a template of json file that will be mapped into the opsmngr.Member struct. So, we are able to set the priority of secondary nodes as needed. By this time, 5 types of member templates are available: primary, secondary, arbiter, hidden, and delayed. The type of each member is informed in the inventory, but I'll explain it with more details in a separated article.

As important as the common directory, this plugin was designed to allow N "data centers" {dataCenter} and N "environments" {environment} in the configPath. In each "{configPath}/{dataCenter}/{environment}" directory template files and json files can be defined, and, as well, each one will be mapped into its respective struct.

A {dataCenter} could be explained as a entity that requires a strict standard, and inside this entity it's possible to define several environments. And there is no direct relation with Organizations at OPS Manager. A *Replica Set resource* has as attributes {dataCenter} and {environment}, so, the plugin will follow the standard defined into the path: "{configPath}/{dataCenter}/{environment}". To help with understanding, I'm going to use an example with MotoGP Constructors as {dataCenter}/{environment}:

```
ducati/sviluppo
ducati/prova
ducati/omologazione
ducati/produzione
Aprilia/Svil
Aprilia/Collaudo
Aprilia/Prod
KTM/DEV
KTM/TEST
KTM/PROD
Honda/Dev
Honda/Test
Honda/PreProd
Honda/Production
yamaha/lab
yamaha/test
yamaha/race
```

As you can see in the example, each {dataCenter} can have as many {environment} as needed, given us the possibility to predefine multiples standards. *I used a different kinds of case for each Constructor just to show that each entity can follow a specific standard, in a real case, in the configPath I would use the same kind of case for all entities. ;)

In the next article I'm going to share more details about this provider.


By Danilo Pala, 10/10/2025