Skip to content

Conversation

@magodo
Copy link
Collaborator

@magodo magodo commented Jul 28, 2025

The dependency injection logic now also add supports for replacing the top level resource_group_name's value by a reference to the resource's name attribute if that resource's name has the same value, and that resource is a resource group.

This is almost only relevant to azurerm provider as azapi provider has no such top level attribute.

Note that we support for resource_group_name based on the fact that this is a well known attribute in azurerm to represent the residing resource group's name of the current resource. That's also the reason why we only support it at the top level, since there can be resources who has nested block, that also expose a resource_group_name and a subscription_id (e.g. azurerm_data_share_dataset_blob_storage), in which case the actual resource group can be different than the resource group in the current exported resource list (i.e. they have the same name, but from the different subscriptions).

Example

Before

resource "azurerm_resource_group" "res-0" {
  location = "westus2"
  name     = "magodo-test-vnet"
}
resource "azurerm_virtual_network" "res-1" {
  address_space       = ["10.0.0.0/16"]
  location            = "westus2"
  name                = "magodo-test"
  resource_group_name = "magodo-test-vnet"
  depends_on = [
    azurerm_resource_group.res-0
  ]
}

Now

resource "azurerm_resource_group" "res-0" {
  location = "westus2"
  name     = "magodo-test-vnet"
}
resource "azurerm_virtual_network" "res-1" {
  address_space       = ["10.0.0.0/16"]
  location            = "westus2"
  name                = "magodo-test"
  resource_group_name = azurerm_resource_group.res-0.name
}

Fix #131

magodo added 3 commits July 25, 2025 12:43
…attribute.

The dependency injection logic now also add supports for replacing the top level `resource_group_name`'s value by a reference to the resource's `name` attribute if that resource's name has the same value, and that resource is a resource group. This is almost only relevant to `azurerm` provider as `azapi` provider has no such top level attribute.

Note that we support for `resource_group_name` based on the fact that this is a well known attribute in `azurerm` to represent the residing resource group's name of the current resource. That's also the reason why we only support it at the top level, since there can be resources who has nested block, that also expose a `resource_group_name` and a `subscription_id` (e.g. `azurerm_data_share_dataset_blob_storage`), in which case the actual resource group can be different than the resource group in the current exported resource list (i.e. they have the same name, but from the different subscriptions).
@magodo magodo requested a review from gerrytan July 28, 2025 05:50
@magodo magodo added the enhancement New feature or request label Jul 28, 2025
Copy link
Member

@gerrytan gerrytan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left some minor comments. Otherwise this PR is good to go in.

Copy link
Member

@gerrytan gerrytan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I left some minor comments. Otherwise this PR is good to go in.

@magodo
Copy link
Collaborator Author

magodo commented Jul 29, 2025

Thanks @gerrytan! I've resolved all the comments, pls take another look!

@magodo magodo merged commit b150a88 into Azure:main Jul 29, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support implicit dependencies

2 participants