Skip to content

[FEATURE] Support for hashicorp/random #3773

Description

@BernieWhite

Your suggestion

Investigate emulating common hashicorp terraform providers functions like random_string from hashicorp/random that are likely to be encountered by customers.

For example, the following code would not work currently if var.container_registry_name is not set because random_string.acr_name.result is calculated at apply time so the result is an empty name field. The current implementation will skip a resource if the name is set to an empty string.

resource "random_string" "acr_name" {
  length  = 10
  special = false
  upper   = false
  numeric = false
}

# Manage a container registry resource.
resource "azapi_resource" "example" {
  type      = "Microsoft.ContainerRegistry/registries@2020-11-01-preview"
  name      = coalesce(var.container_registry_name, random_string.acr_name.result)
  parent_id = azurerm_resource_group.rg.id

  location = azurerm_resource_group.rg.location
  identity {
    type         = "SystemAssigned, UserAssigned"
    identity_ids = [azurerm_user_assigned_identity.example.id]
  }

  body = {
    sku = {
      name = "Standard"
    }
    properties = {
      adminUserEnabled = true
    }
  }
}

While the intent is that the name is random (the first apply), for testing with PSRule it may make sense to make this appear random but deterministic taking parameters from the resource definition name to seed then getting the N'th variation based on how many times it's called. Otherwise subsequent runs would report a different name.

Alternatives

n/a

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codefeature: pre-flight-expansionIssues relating to expansion of ARM and Bicep.feature: terraformSupport for expansion with Terraform.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions