-
Notifications
You must be signed in to change notification settings - Fork 1
how to create a Terraform module
Creating a Terraform Module for building block
This guide will walk you through the process of creating a Terraform module that you can use as a building block within meshStack. For additional information on how to create a building block in meshStack using a Terraform module, please consult this guide.
To ensure simplicity and ease of understanding, it is recommended that you organize your project files as follows:
- Main Code: Store your primary Terraform configuration code in a dedicated file.
- Variables: Maintain variable definitions in a separate file.
- Outputs: Manage output configurations in their own file.
- Terraform and Provider Configuration: Keep your Terraform configuration settings in a distinct file.
- Backend Configuration: As the backend configuration contains environment-specific information, it's best to provide this as an input parameter.
Here's an example file structure:
![image](https://private-user-images.githubusercontent.com/96071919/269597066-5b162e01-5cba-4ef2-87c3-a64e14939b82.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMyNzAxNTUsIm5iZiI6MTcyMzI2OTg1NSwicGF0aCI6Ii85NjA3MTkxOS8yNjk1OTcwNjYtNWIxNjJlMDEtNWNiYS00ZWYyLTg3YzMtYTY0ZTE0OTM5YjgyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEwVDA2MDQxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThmOWU4OTQ4NjBiOWVjNDRkODVlYmQ0MjczNTYzYmYyOWE2MTUxNzU4M2YzOTE1MDM2NmRiMWRlM2FmZjhlMDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Mg3C11EowtNtGbj2mIqDJFArkIzNTjI2L3kynvXnRMI)
For configuring the backend, please refer to this guide. It is essential to customize the backend settings according to your environment-specific requirements.
We are going to create this module based on the example given in Terraform registry
main.tf
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_storage_account" "example" {
name = "storageaccountname"
resource_group_name = azurerm_resource_group.example.name
location = var.storage_account_location
account_tier = "Standard"
account_replication_type = var.replication_type
tags = {
environment = "staging"
}
}
provider.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.73.0"
}
}
}
provider "azurerm" {
# Configuration options
}
variables.tf
variable "storage_account_location" {
type = string
description = "The region where storage account will be deployed"
default = "westeurope"
}
variable "replication_type" {
type = string
description = "Possible values like LRS, ZRS, GRS"
default = "GRS"
}
outputs.tf
output "account_kind" {
value = azurerm_storage_account.example.account_kind
}
backend.tf Please refer to this guide