Components

Component is a core concept in Microtica which allow developers to create and release their cloud infrastructure in a standardized way. Once the component is created, it can be reused in any number of projects and environments.

Think about Components like Docker containers for infrastructure. You can package them, deploy them and combine with each other to build complex solutions.

Component uses AWS CloudFormation templates with additional added values:

  • much easier to distribute on different cloud accounts and regions
  • integrated with the powerful Microtica Pipelines
  • optimized for promotion from one to another environment (dev -> test -> production)
  • self-contained. Pipeline definition, validation schema and infrastructure templates all in one package which makes the distribution of the infrastructure much easier

#Define your custom infrastructure

The way to define an infrastructure in components is by using CloudFormation templates.

Component is not yet another wrapper of CloudFormation, so you don’t have to learn new syntax in order to provision cloud infrastructure. Anything that CloudFormation supports is immediately available in components as well.

Below is an example of a template that defines one EC2 instance with instance type provided as an input parameter. The template should be stored somewhere in your Git repository.

cfn-template.json

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "My Custom Component",
    "Parameters": {
        "natInstanceType": {
            "Type": "String",
            "Description": "Type of the EC2 instance"
        }
    },
    "Resources": {
        "NATInstance": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "InstanceType": {
                    "Ref": "natInstanceType"
                }
            }
        }
    },
    "Outputs": {
        "accessDomain": {
            "Value": {
                "Fn::GetAtt": "NATInstance.PublicDnsName"
            },
            "Description": "Public domain to access the EC2 instance"
        }
    }
}

In the next section you will se how you can use this template and prepare it for deployment.

#Prepare the Component for deployment

To make component ready for deployment we need to setup a proper automation pipeline.

<IMAGE_OF_PIPELINE_CREATION_PAGE>

Microtica provides a built-in pipeline step that will package test and prepare artifacts for deployment. You just have to specify the path to your CloudFormation template and everything else will be handled by Microtica.

You can define a pipeline either directly in Microtica Portal or add microtica.yaml file in your source code root path.

Below is an example of a pipeline that will prepare the component for deployment.

microtica.yaml

steps:
  Clone:
    type: git-clone
    title: Clone Git repository

  ComponentPackage:
    type: cfn-component
    title: Package my component
    # path to CloudFormation template relative to the source code root dir
    cfn_template: path/to/cfn-template.json

The pipeline consists of two steps. The first step clones the code from your Git repository, specified while creating the pipeline. The second step is a built-in component step that packages the component. You just have to specify the path to the CloudFormation template cfn_template and Microtica will do the rest.

#Make the Component configurable

Now that we’ve defined the pipeline, we are ready to use the component to compose our infrastructure solution.

To make components easy to reuse we enable you to define their custom schema for what component should receive as an input and give as an output. The schema is then validated each time you configure the component or trigger a deployment.

To define the component schema we use already established standard known as JSON Schema. Microtica will automatically generate this schema by parsing your CloudFormation input/output parameters. If you need a custom schema then just create a schema.json file in the source code root path.

Below is one example of a custom schema that defines one required input parameter named as natInstanceType of type enum and one output parameter named as accessDomain.

schema.json

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "schema://microtica/component-schema.json",
    "title": "Component Schema",
    "type": "object",
    "properties": {
        "inputs": {
            "type": "object",
            "properties": {
                "natInstanceType": {
                    "type": "string",
                    "enum": [
                        "t2.micro",
                        "t2.medium",
                        "t2.large"
                    ]
                }
            },
            "required": [
                "natInstanceType"
            ],
            "additionalProperties": false
        },
        "parameters": {
            "type": "object",
            "properties": {
                "natInstanceType": {
                    "type": "string"
                }
            }
        },
        "outputs": {
            "type": "object",
            "properties": {
                "accessDomain": {
                    "type": "string"
                }
            }
        }
    },
    "additionalProperties": false
}

The schema is rendered in Microtica GUI as defined in the schema.json, so when you want to use and configure this component you can choose from predefined enums (t2.micro, t2.medium, t2.large), for the natInstanceType input property, from a dropdown list.

Component configuration modal

For Microtica to use the custom schema we need to extend the pipeline by adding additional step parameter schema and specify the path to the schema file.

microtica.yaml

steps:
  Clone:
    type: git-clone
    title: Clone Git repository

  ComponentPackage:
    type: cfn-component
    title: Package my component
    # path to CloudFormation template relative to the source code root dir
    cfn_template: path/to/cfn-template.json
    # path to JSON schema relative to the source code root dir (optional)
    schema: path/to/schema.json

#Deploy the Component

To deploy the component you need to first create a new environment or use an existing one. Then just add the component in the environment and hit on Create Plan button in the top right to start the deployment process.

If you instead want a step by step guide to create a new environment and use the component we’ve just created, please follow our infrastructure getting started guide.