Core Concepts
Components

CloudFormation

12min
cloudformation (cfn) components in microtica provide a robust framework for managing and deploying aws infrastructure these components are tightly integrated into the microtica platform, allowing for seamless automation of infrastructure deployment below, you'll find a detailed explanation of each key file involved in a typical cfn component setup file structure index json the index json file is the core of your cloudformation component it defines the aws resources that will be created or managed using cloudformation index json { "awstemplateformatversion" "2010 09 09", "description" "aws s3 bucket custom component", "parameters" { "bucketname" { "type" "string", "default" "", "description" "the name of the s3 bucket" } }, "resources" { "s3bucket" { "type" "aws s3 bucket", "properties" { "bucketname" { "ref" "bucketname" } } } }, "outputs" { "bucketname" { "value" { "ref" "s3bucket" }, "description" "name of the s3 bucket" } } } parameters defines user configurable input parameters for the cloudformation template in this example, the bucketname parameter allows users to specify the name of the s3 bucket resources the section where aws resources are defined outputs specifies the outputs of the template after deployment, the name of the s3 bucket is returned microtica yaml the microtica yaml file outlines the ci/cd pipeline steps that microtica will execute during the deployment process microtica yaml steps package type build title build app/resource commands \ npm install \ npm test \ npm prune production artifacts files package zip / microtica/ schema json / microtica/schema json cache false deploycomponent type deploy target environment env id "env 123" partial create missing resources true resource version overrides "componentname" "{{mic pipeline execution id}}" index js the index js file is the entry point for managing the lifecycle of the component within microtica it uses the microtica sdk to interact with cloudformation index js const path = require("path"); const { nestedcomponent } = require("@microtica/component") awscloud; const component = new nestedcomponent( path join( dirname, "index json"), path join( dirname, "schema json"), handlecreateorupdate, handlecreateorupdate ); async function handlecreateorupdate() { // here you can specify additional properties which will be provided as input parameters // in the cfn template during deployment these properties are used during the initial // resource deployment process return {}; } module exports = component; schema json the schema json file defines the schema for the component, specifying input parameters and ensuring that they conform to the expected structure and types the input parameters defined in the schema will be visible in the microtica console, allowing users to easily configure the component during deployment { "$schema" "http //json schema org/draft 07/schema#", "$id" "schema //microtica/component aws s3 json", "title" "component schema", "type" "object", "properties" { "inputs" { "type" "object", "properties" { "bucketname" { "type" "string", "description" "the name of the bucket " } }, "required" \[ "bucketname" ], "additionalproperties" false } }, "additionalproperties" false } all the files mentioned above should be placed within the microtica folder at the root of your git repository component yaml the component yaml file is a specification file for a microtica cloudformation component it provides metadata and configuration details about the component, including its name, description, and paths to the necessary cloudformation and schema files component yaml # microtica component spec name comp description microtica custom component spec cfn path index json schema path schema json for a full example, checkout our complete template this setup ensures that your cloudformation component is well organized, easy to manage, and ready for deployment through microtica, providing a streamlined way to automate infrastructure management on aws custom input parameters when working with cloudformation components in microtica, you may find the need to add custom input parameters to your templates these parameters can help make your components more flexible and configurable step 1 update the json schema (schema json) first, you need to define the new accesscontrol parameter in the schema json file this will ensure that the parameter is visible and configurable in the microtica console here is how you can update the schema json file { "$schema" "http //json schema org/draft 07/schema#", "$id" "schema //microtica/component aws s3 json", "title" "component schema", "type" "object", "properties" { "inputs" { "type" "object", "properties" { "bucketname" { "type" "string", "description" "the name of the bucket " }, "accesscontrol" { "type" "string", "description" "the access control setting for the s3 bucket ", "enum" \["private", "publicread"] } }, "required" \[ "bucketname", "accesscontrol" ], "additionalproperties" false } }, "additionalproperties" false } in this update the accesscontrol parameter is added under properties with the description and two allowed values ( enum ) "private" and "publicread" the parameter is also included in the required array to ensure it must be provided during deployment step 2 update the cloudformation template (index json) next, you need to update the index json file to include the new accesscontrol parameter in the cloudformation template this parameter will be used to set the appropriate access control policy on the s3 bucket here’s the updated index json file { "awstemplateformatversion" "2010 09 09", "description" "aws s3 bucket custom component", "parameters" { "bucketname" { "type" "string", "default" "", "description" "the name of the s3 bucket" }, "accesscontrol" { "type" "string", "description" "the access control setting for the s3 bucket ", "allowedvalues" \["private", "publicread"], "default" "private" } }, "resources" { "s3bucket" { "type" "aws s3 bucket", "properties" { "bucketname" { "ref" "bucketname" }, "accesscontrol" { "ref" "accesscontrol" } } } }, "outputs" { "bucketname" { "value" { "ref" "s3bucket" }, "description" "name of the s3 bucket" } } } in this update the accesscontrol parameter is added under parameters , with allowed values "private" and "publicread" the default value is set to "private" the accesscontrol property is referenced in the s3bucket resource definition, linking it to the corresponding parameter value provided during deployment