Skip to content

Instantly share code, notes, and snippets.

@dustindortch
Created February 8, 2024 18:19
Show Gist options
  • Save dustindortch/440c5be1a2906444939afc0a693ad824 to your computer and use it in GitHub Desktop.
Save dustindortch/440c5be1a2906444939afc0a693ad824 to your computer and use it in GitHub Desktop.
Terraform Best Practices: Do Not Hard Code Values - Use Locals
variable "location" {
default = "eastus"
description = "Azure deployment region"
type = string
}
variable "resource_group_name" {
default = "rg-eus-test-myrg"
description = "Resource Group name for deployment"
type = string
}
variable "tags" {
default = {
Environment = "test"
}
description = "Supplied Resource Group tags"
type = map(string)
}
locals {
mandatory_tags = {
CreatedBy = "Terraform"
}
tags = merge(var.tags, local.mandatory_tags)
}
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
tags = local.tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment