Terraform
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.
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:
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.
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:
This configuration defines an S3 bucket. The bucket name is provided as an input variable, allowing for customization during deployment.
The outputs.tf file specifies the output values that Terraform will generate after deployment. These outputs can be referenced in other components:
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.
The variables.tf file contains variable definitions, allowing for dynamic and reusable configurations across different environments:
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.
When working with Terraform components in Microtica, you may need to add custom input parameters to make your components more configurable.
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:
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".
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:
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.