Terratag: Manage your cloud resource tags efficiently across terraform modules in Azure

Credit: Damian Flynn

Introduction

What is Terratag ?

# modules/resource_group/main.tf
#-------------------------
# Create a resource group
#-------------------------
resource "azurerm_resource_group" "rg" {
name = "DEV-RG01"
location = "East US"
}
# modules/network_security_group/main.tf
#-------------------------------------------------------
# network security group configuration is specified here.
#-------------------------------------------------------
resource "azurerm_network_security_group" "nsg1" {
name = "NetworkSecurityGroup1"
location = "East US"
resource_group_name = "DEV-RG01"
security rule {
name = "port_80"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
# modules/virtual_network/main.tf
#-------------------------------------------------
# virtual network configuration is specified here.
#--------------------------------------------------
resource "azurerm_virtual_network" "vnet" {
name = "prod-vnet1"
address_space = ["10.30.0.0/16"]
location = "East US"
resource_group_name = "DEV-RG01"
}
resource "azurerm_subnet" "internal" {
name = "internal_subnet"
address_prefixes = ["10.30.2.0/24"]
resource_group_name = "DEV-RG01"
virtual_network_name = azurerm_virtual_network.vnet.name
}
resource "azurerm_subnet_network_security_group_association" "nsga1" {
subnet_id = azurerm_subnet.internal.id
network_security_group_id = var.nsg_id
depends on = [azurerm_subnet.internal]
}
terratag -tags='{"ENV": "DEV"}' -rename=false

Senior Cloud Engineer | 6× Azure, Terraform Associate