Sudipta Mukherjee
Sudipta Mukherjee

Reputation: 111

Terraform with Azure - Issue enforcing unique names for resources

I am using Terraform for creating resources within Azure and attaching current time-stamp for enforcing unique names for resources like storage account, key vault etc in the .tf file.

Problem is, for existing resources, when you expect Terraform apply to do nothing, these resources are being destroyed and recreated since the time-stamp has changed between last execution and the current one!

Wondering what's the best strategy to enforce uniqueness, dynamically.

The initial texts for these resources come from Azure Pipeline variables and I'm appending current time-stamp for adding uniqueness.

Upvotes: 1

Views: 798

Answers (1)

GeralexGR
GeralexGR

Reputation: 3582

According to Cloud Adoption framework you could define a convention like the one shown below.

enter image description here

Terraform example

name = "${local.prefix}-${var.location}-app-plan"

https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming

I also suggest you to look the naming azure plugin which can help you create unique names across resources

https://registry.terraform.io/modules/Azure/naming/azurerm/latest

Upvotes: 1

Related Questions