Skip to content

Instantly share code, notes, and snippets.

@dustindortch
Created February 8, 2024 18:21
Show Gist options
  • Save dustindortch/c8945b7aa571e99b426a4c728dabbd19 to your computer and use it in GitHub Desktop.
Save dustindortch/c8945b7aa571e99b426a4c728dabbd19 to your computer and use it in GitHub Desktop.
Terraform Best Practices: Do Not Hard Code Values - Using References
variable "address_space" {
default = ["10.0.42.0/24"]
description = "Virtual Network address space"
type = list(string)
}
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)
}
variable "virtual_network_name" {
default = "vnet-eus-test-myvnet"
description = "Virtual Network name for deployment"
type = 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
}
resource "azurerm_virtual_network" "vnet" {
name = var.virtual_network_name
address_space = var.address_space
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment