Skip to content

Instantly share code, notes, and snippets.

@geekzter
Last active March 24, 2021 08:35
Show Gist options
  • Select an option

  • Save geekzter/83495fa3ed3bb43d158e5a8a47c28f83 to your computer and use it in GitHub Desktop.

Select an option

Save geekzter/83495fa3ed3bb43d158e5a8a47c28f83 to your computer and use it in GitHub Desktop.
Terraform instrumentation to enable teardown
# variables.tf
variable resource_suffix {
description = "The suffix to put at the end of resource names created"
default = "" # Empty string triggers a random suffix
}
variable run_id {
type = string
default = ""
}
# main.tf
# Random resource suffix, this will prevent name collisions when creating resources in parallel
resource random_string suffix {
length = 4
upper = false
lower = true
number = false
special = false
}
locals {
suffix = var.resource_suffix != "" ? lower(var.resource_suffix) : random_string.suffix.result
tags = map(
"provisioner", "terraform",
"repository", "terraform-demo",
"runid", var.run_id,
"workspace", terraform.workspace
)
}
resource azurerm_resource_group synapse {
name = "terraform-demo-${terraform.workspace}-${local.suffix}"
location = "westeurope"
tags = local.tags
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment