Skip to content

Use implicit dependency instead of depends_on#622

Merged
magodo merged 5 commits intoAzure:mainfrom
gerrytan:gerrytan/implicit-dependency
May 12, 2025
Merged

Use implicit dependency instead of depends_on#622
magodo merged 5 commits intoAzure:mainfrom
gerrytan:gerrytan/implicit-dependency

Conversation

@gerrytan
Copy link
Copy Markdown
Member

@gerrytan gerrytan commented May 7, 2025

Improved export logic such that when resourceId-valued attribute is matched against a dependency resource, use implicit TF address instead of depends_on syntax.

Config exported in previous behaviour:

// The id of this resource is "/subscription/123/resourceGroup/123/providers/Foo/foo/foo1"
resource "azurerm_foo_resource" "example" {
  name = "foo1"
}

resource "azurerm_bar_resource" "example" {
  name = "bar1"
  foo_id = "/subscription/123/resourceGroup/123/providers/Foo/foo/foo1"
  depends_on = [
    azurerm_foo_resource.example
  ]
}

Config exported in the new behaviour:

resource "azurerm_foo_resource" "example" {
  name = "foo1"
}

resource "azurerm_bar_resource" "example" {
  name = "bar1"
  foo_id = azurerm_foo_resource.example.id
}

If no such value is found, it will still fall-back to depends_on.
The replacement is done in recursive manner. Values nested in children blocks will also be replaced.

@gerrytan gerrytan marked this pull request as ready for review May 9, 2025 00:19
@gerrytan
Copy link
Copy Markdown
Member Author

e2e test passes: go test -v -run ^TestVnet$ github.com/Azure/aztfexport/internal/test/resourcegroup

--- PASS: TestVnet (185.54s)
PASS
ok      github.com/Azure/aztfexport/internal/test/resourcegroup 185.801s

@magodo magodo merged commit d4de677 into Azure:main May 12, 2025
7 checks passed
@magodo magodo added the enhancement New feature or request label May 12, 2025
@gerrytan gerrytan deleted the gerrytan/implicit-dependency branch May 12, 2025 01:25
magodo added a commit to magodo/aztfy that referenced this pull request May 29, 2025
…endency (via reference) when there is a ID reference (Azure#622)"

This reverts commit d4de677.
magodo added a commit that referenced this pull request May 29, 2025
…endency (via reference) when there is a ID reference (#622)" (#628)

This reverts commit d4de677.
gerrytan pushed a commit to gerrytan/aztfexport that referenced this pull request Jun 6, 2025
…endency (via reference) when there is a ID reference (Azure#622)" (Azure#628)

This reverts commit d4de677.
gerrytan added a commit to gerrytan/aztfexport that referenced this pull request Jun 6, 2025
…pendency (via reference) when there is a ID reference (Azure#622)" (Azure#628)

This reverts commit 130e84a.
gerrytan added a commit to gerrytan/aztfexport that referenced this pull request Jun 6, 2025
…pendency (via reference) when there is a ID reference (Azure#622)" (Azure#628)

This reverts commit 130e84a.
magodo added a commit that referenced this pull request Jun 13, 2025
* Reapply "Convert explict dependency (via `depends_on`) to implicit dependency (via reference) when there is a ID reference (#622)" (#628)

This reverts commit 130e84a.

* Replace transitive dependencies with TF address

* Big refactor of dependency handling logic

* PR review cycle 2

- Refactor config_info model, avoid redundant types
- Shorten variable names
- Avoid strong string types

* Minor changes

* Add parentChildDep even if already exist as ambiguousRefDep

---------

Co-authored-by: magodo <wztwcy@gmail.com>
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.

2 participants