Skip to content

Commit

Permalink
docs: update unknown value example to use provider functions
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF committed Oct 2, 2024
1 parent a861de4 commit 7c69a98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ If you pass an unknown (known after apply) value into the module, it will not be
This may cause resources to be unnecessarily recreated.

Such unknown values include resource ids. For example, if you are creating a resource and passing the id of the resource group to the module, this will cause the issue.

Instead, use string interpolation to pass the values. For example:
Instead, use string interpolation or provider functions to pass the values. For example:

### Recommended

Expand All @@ -41,9 +40,17 @@ This is the recommended way to use this module:
> We assume that all variable inputs are literals.
```terraform
locals {
foo_resource_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.FooResourceProvider/${var.foo_resource_name}"
subscription_id = data.azapi_client_config.current.subscription_id
resource_group_name = "rg1"
resource_type = "Microsoft.Network/virtualNetworks"
resource_names = ["vnet1"]
my_resource_id = provider::azapi::resource_group_resource_id(
data.azapi_client_config.current.subscription_id,
local.resource_group_name,
local.resource_type,
local.resource_names
)
}
module "example" {
Expand All @@ -54,7 +61,7 @@ module "example" {
policy_assignments = {
mypolicy = {
parameters = {
parameterName = jsonencode({ value = local.foo_resource_id })
parameterName = jsonencode({ value = local.my_resource_id })
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions _header.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ If you pass an unknown (known after apply) value into the module, it will not be
This may cause resources to be unnecessarily recreated.

Such unknown values include resource ids. For example, if you are creating a resource and passing the id of the resource group to the module, this will cause the issue.

Instead, use string interpolation to pass the values. For example:
Instead, use string interpolation or provider functions to pass the values. For example:

### Recommended

Expand All @@ -40,12 +39,19 @@ This is the recommended way to use this module:
> We assume that all variable inputs are literals.
```terraform
locals {
foo_resource_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.FooResourceProvider/${var.foo_resource_name}"
subscription_id = data.azapi_client_config.current.subscription_id
resource_group_name = "rg1"
resource_type = "Microsoft.Network/virtualNetworks"
resource_names = ["vnet1"]
my_resource_id = provider::azapi::resource_group_resource_id(
data.azapi_client_config.current.subscription_id,
local.resource_group_name,
local.resource_type,
local.resource_names
)
}
module "example" {
source = "Azure/terraform-azurerm-avm-ptn-alz/azurerm"
Expand All @@ -54,7 +60,7 @@ module "example" {
policy_assignments = {
mypolicy = {
parameters = {
parameterName = jsonencode({ value = local.foo_resource_id })
parameterName = jsonencode({ value = local.my_resource_id })
}
}
}
Expand Down

0 comments on commit 7c69a98

Please sign in to comment.