Azure / Azure/PSRule.Rules.Azure

[FEATURE] Support for hashicorp/random

Open
#3,773 4 comments 0 reactions 0 assignees View on GitHub
.NET feature: pre-flight-expansion feature: terraform
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.