Core Concepts
Components
Terraform
10min
terraform components in microtica are designed to provide flexibility and cloud agnostic infrastructure management these components allow you to define and deploy infrastructure across multiple cloud providers using terraform, a widely adopted infrastructure as code (iac) tool file structure microtica yaml the microtica yaml file defines the ci/cd pipeline for the terraform component within microtica it outlines the steps required to build and deploy the component steps clone type git clone package type terraform build deploycomponent type deploy target environment env id "env 123" partial create missing resources true resource version overrides "componentname" "{{mic pipeline execution id}}" in this configuration, the pipeline first clones the component's source code from the git repository, then builds the terraform component to ensure all necessary resources are prepared for deployment finally, the component is deployed to the specified environment main tf the main tf file is the primary terraform configuration file where the infrastructure resources are defined below is a simple example of a terraform configuration for an aws s3 bucket resource "aws s3 bucket" "my bucket" { bucket = var bucket name } this configuration defines an s3 bucket the bucket name is provided as an input variable, allowing for customization during deployment outputs tf the outputs tf file specifies the output values that terraform will generate after deployment these outputs can be referenced in other components output "bucket name" { value = aws s3 bucket my bucket bucket description = "the name of the s3 bucket" } in this example, the output returns the name of the s3 bucket that was created, making it available for use in other parts of your infrastructure or within microtica's deployment process variables tf the variables tf file contains variable definitions, allowing for dynamic and reusable configurations across different environments variable "bucket name" { type = string description = "the name of the s3 bucket" } this variable defines the bucket name parameter, which is used to specify the name of the s3 bucket the input parameters defined in the variables tf file will be visible in the microtica console, allowing users to easily configure the component during deployment this setup ensures that your terraform component is well organized, flexible, and ready for deployment through microtica, enabling you to manage infrastructure across multiple cloud providers efficiently custom input parameters when working with terraform components in microtica, you may need to add custom input parameters to make your components more configurable step 1 update the variable definitions (variables tf) first, define the new access control variable in the variables tf file this will allow users to specify the desired access control setting when deploying the terraform component here’s how you can update the variables tf file variable "bucket name" { type = string description = "the name of the s3 bucket" } variable "access control" { type = string description = "the access control setting for the s3 bucket" default = "private" validation { condition = contains(\["private", "public read"], var access control) error message = "access control must be either 'private' or 'public read'" } } in this update the access control variable is added, with a description and a default value of "private" a validation block is included to ensure that the provided value is either "private" or "public read" step 2 update the terraform configuration (main tf) next, update the main tf file to use the new access control variable when defining the s3 bucket here’s the updated main tf file resource "aws s3 bucket" "example" { bucket = var bucket name } resource "aws s3 bucket ownership controls" "example" { bucket = aws s3 bucket example id rule { object ownership = "bucketownerpreferred" } } resource "aws s3 bucket acl" "example" { depends on = \[aws s3 bucket ownership controls example] bucket = aws s3 bucket example id acl = var access control } in this update the acl property of the aws s3 bucket resource is set to the value of the access control variable, allowing the bucket's access control setting to be configured during deployment