Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update unknown value example to use provider functions #124

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading