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
Your suggestion
Investigate emulating common hashicorp terraform providers functions like
random_stringfromhashicorp/randomthat are likely to be encountered by customers.For example, the following code would not work currently if
var.container_registry_nameis not set becauserandom_string.acr_name.resultis 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.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