Defining the structure of Managed services template

The Managed services supported Terraform template is made up of datatypes, modules, metadata files and .tf files. This section provides you with the structure of the template so that you can build a new Terraform template from scratch.

Using the locally installed Template Designer, you can create templates in a user friendly way, however, it does not support some of the content types and is limited in scope. For more information about the locally installed Template Designer, see Managed services local Template Designer.

The following block depicts the structure of a template:

- License
- README.md
- main.tf
- variables.tf
- output.tf
- camtemplate.json
- camvariables.json
- datatypes/
  - datatype.json
  - ...
- modules
  - moduleA/
    - LICENSE
    - main.tf
    - output.tf
    - scripts
      - script.sh
    - variables.tf
  - moduleB/
    - ...
- examples/
  - exampleA
    - main.tf
  - exampleB
    - main.tf
  - ...
- scripts
  - script.sh
  - ...

The following table describes the different components of a template structure:

Component Description
cam_template_structure This is the repository name or root folder of the template.
License The license under which the template is made available.
README.md This file contains a description of the template, expected usage, and variables required.
main.tf The main entry point for the template.
variables.tf Provides information and defaults of variables that are needed to execute the template.
output.tf Provides information on important variables, which can be queried after deployment through Terraform and Managed services user interface.
camtemplate.json A metadata file which provides information such as the short/long name, description, version and more for presentation in the Managed services Catalog.
camvariables.json A metadata file describing how each variable is presented in the Managed services user interface. This creates an improved deployment experience with features such as: optional drop-downs, secure (masking), regex validation and descriptions.
datatypes directory Directory contains json files to be loaded into Managed services Shared Parameters.
datatypes/datatype.json Contains information about the Data Types which can be used by templates to facilitate dynamic binding at deployment time.
modules directory This is optional and only used if nested Modules are included. Nested Modules allow you to break up complexity to provide more flexible configuration options.
modules/module Directory for a specific nested Module. It must at least include a main.tf, output.tf and variables.tf.
modules/moduleA/main.tf / variables.tf / output.tf Files are scoped to Module execution only but have the same definition as the preceding definition.
modules/moduleA/scripts directory Directory contains scripts or files used by the Module.
scripts Directory contains scripts or files used by the template.
examples Directory containing an example(s) of additional configurations.

Modules

Modules are Terraform files in a folder. Even the working directory of a Terraform configuration where you run "Terraform apply" is considered as a root Module.

The Terraform Module is achieved by abstracting common configuration as building blocks, which can be reused by you and the rest of the organization. The Terraform configuration is by itself a Module sourcing other common building blocks (Modules) all with the right level of abstraction to enable reuse. The Terraform Modules provide developers with a structure to define reusable building blocks. You can define reusable configuration to meet industry guidelines and/or certify against your organization’s unique standards. Large organizations can take advantage of structuring Terraform Modules by specialties like networking, security or by team ownership. When developing Terraform, use the Modules approach.

The following block depicts the structure of a module:

- modules
  - moduleA/
    - LICENSE
    - main.tf
    - output.tf
    - scripts
      - script.sh
    - variables.tf
  - moduleB/
    - ...

Tags module

For more information about system tags and user tags, see Tags module.

Managed services JSON files

You can create camtemplate.json and camvariables.json files for your template. It is not mandatory to have them in the template but its presence simplifies the deployment process.

Datatypes folder

Datatypes are yet another Managed services specific metadata.

Datatypes

Administrator defined connection is required as the templates that are defined in Managed services need access to external systems that are not necessarily backed up by a Managed services instance. The Data Types and Data Objects are two admin constructs that are used to capture these shared configurations.

You must define the datatypes for a template under the datatypes folder or else they get ignored by the import code:

{
   "name": "Name of the datatype",
   "label": "Lable of the datatype",
   "description": "Description of the datatype",
   "attributes": [
    {
      "name": "Name of the attribute",
      "type": "type of the attribute",
      "description": "Description of the attribute",
      "label": "Label of the attribute",
      "required": "Is it a mandatory attribute",
      "secured": "Is it a secured attribute",
      "immutable": "Is it immutable",
      "hidden": "Is it hidden",
      "default": "The default value of the attribute",
      "options": Options of the attribute.
     },
     {
       ...
       ...
     }
    ]
}

For a sample datatype, see GitHub repository External link icon.

For more information about shared parameters, see Shared parameters.

Terraform files

The template can have main.tf and variables.tf terraform files.

Template lifecycle through branches

It is a best practice to use dedicated repository in Git for templates and auxiliary files. Whenever you make a change, create a branch at the repository level and not at the folder level. You can have multiple templates in the same repository and multiple versions of the same template. Whenever changes do not break compatibility with older versions, you can use the same branch and merge the changes. If you have changes that break compatibility, then use a new branch. In Managed services, import the new branch and make it the default. You can run a plan and apply that upgrade instances to the new configuration.

By using the Template Designer, you can manage branches effectively. For the procedure to create a branch for a template from Template Designer, see Creating a template.