Azure / Azure/PSRule.Rules.Azure
[FEATURE] Support for hashicorp/random
- Dominant language
- PowerShell
- Stars
- 447
- Forks
- 109
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 23
Description
### 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.
```terraform
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
- https://learn.microsoft.com/en-us/azure/developer/terraform/get-started-azapi-resource?tabs=azure-cli
Contributor guide
Assessment
This issue has not been assessed yet.