terraform-provider-azapi icon indicating copy to clipboard operation
terraform-provider-azapi copied to clipboard

Provider feature: automatically generate resource names based on default naming convention

Open ms-henglu opened this issue 3 years ago • 3 comments

Thanks @Nepomuceno for this great suggestion https://github.com/Azure/terraform-provider-azapi/issues/154!

This feature is about generating resource names based on some naming convention, here's an example:

(The fields and naming pattern are not finalized, just want to show how it works)

provider "azapi" {
  default_naming = {
    name       = "team1"
    prefix     = "dev"
    postfix    = "001"
    max_length = 18
  }
}

resource "azurerm_resource_group" "test" {
  name     = "example-rg"
  location = "westus"
}

resource "azapi_resource" "test" {
  type      = "Microsoft.Automation/automationAccounts@2021-06-22"
  parent_id = azurerm_resource_group.test.id
  // the resource name is auto generated based on the naming convention defined in provider block
  // name = "dev-team1-001-wxyz"
}

This feature is similar with default location and tags which are already supported, it's also possible to override the default generated name in each resource.

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

ms-henglu avatar Aug 15 '22 07:08 ms-henglu

Hi @grayzu , what do you think?

ms-henglu avatar Aug 15 '22 07:08 ms-henglu

Would be great if you could have an output or datas our e for the resource itself imagine that you might want to use this name for non azapi resources I could reference for example

data.azapi_name.default.resource_group and this would output a resource group name

Nepomuceno avatar Aug 15 '22 07:08 Nepomuceno

Looks fantastic @ms-henglu!

What @Nepomuceno is referencing, is interesting as well but gets a bit more complex, I think. @Nepomuceno, let's use your original issue (#154 ) to track this ask.

grayzu avatar Aug 17 '22 23:08 grayzu