Skip to content

Fix circular reference in vnet module #1743

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

MSBrett
Copy link
Contributor

@MSBrett MSBrett commented Jul 3, 2025

πŸ› οΈ Description

Fix circular reference in vnet module which was causing private network enabled deployments to fail.

Fixes #1735

πŸ“· Screenshots

πŸ“‹ Checklist

πŸ”¬ How did you test this change?

  • 🀏 Lint tests
  • 🀞 PS -WhatIf / az validate
  • πŸ‘ Manually deployed + verified
  • πŸ’ͺ Unit tests
  • πŸ™Œ Integration tests

πŸ™‹β€β™€οΈ Do any of the following that apply?

  • 🚨 This is a breaking change.
  • 🀏 The change is less than 20 lines of code.

πŸ“‘ Did you update docs/changelog.md?

  • βœ… Updated changelog (required for dev PRs)
  • ➑️ Will add log in a future PR (feature branch PRs only)
  • ❎ Log not needed (small/internal change)

πŸ“– Did you update documentation?

  • βœ… Public docs in docs (required for dev)
  • βœ… Internal dev docs in src (required for dev)
  • ➑️ Will add docs in a future PR (feature branch PRs only)
  • ❎ Docs not needed (small/internal change)

@MSBrett MSBrett requested a review from Copilot July 3, 2025 02:43
@MSBrett MSBrett self-assigned this Jul 3, 2025
@MSBrett MSBrett requested a review from arthurclares as a code owner July 3, 2025 02:43
@MSBrett MSBrett linked an issue Jul 3, 2025 that may be closed by this pull request
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR resolves a circular reference in the vNet module by switching name and ID lookups to the newly deployed vNet resource instead of the hub.routing outputs, ensuring private network–enabled deployments succeed.

  • Use vNetName for the NSG name to remove dependency on hub.routing.networkName
  • Swap hub.routing.networkId with vNet.id in private DNS zone resources
  • Reference subnets in script storage and endpoint resources via vNet::… child resource IDs
Comments suppressed due to low confidence (3)

src/templates/finops-hub/modules/infrastructure.bicep:216

  • Consider adding unit or integration tests to cover the updated private DNS zone attachment logic using vNet.id to prevent regressions when deploying with private networks.
        id: vNet.id

src/templates/finops-hub/modules/infrastructure.bicep:22

  • [nitpick] Add an inline comment explaining why the NSG name has been switched to use vNetName instead of hub.routing.networkName, to clarify the refactoring intent.
var nsgName = '${vNetName}-nsg'

src/templates/finops-hub/modules/infrastructure.bicep:203

  • [nitpick] There's a lot of duplicated code for private DNS zones (blob, dfs, queue, table). Consider parameterizing these definitions in a loop or extracting into a reusable module to reduce repetition and simplify future updates.
resource blobPrivateDnsZone 'Microsoft.Network/privateDnsZones@2024-06-01' = if (hub.options.privateRouting) {

@microsoft-github-policy-service microsoft-github-policy-service bot added Micro PR πŸ”¬ Very small PR that should be especially easy for newcomers Needs: Review πŸ‘€ PR that is ready to be reviewed labels Jul 3, 2025
@@ -213,7 +213,7 @@ resource blobPrivateDnsZone 'Microsoft.Network/privateDnsZones@2024-06-01' = if
properties: {
registrationEnabled: false
virtualNetwork: {
id: hub.routing.networkId
id: vNet.id
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI - I was on the fence whether to use an on-demand reference or the ID that we have to maintain anyway. I ran into issues using the reference in some cases so I tended to use the original ID to work around bicep dependency limitations. I'm not overly opinionated, however. Just wanted to share the reasoning behind it being an ID rather than a reference.

@@ -303,7 +303,7 @@ resource scriptStorageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = i
defaultAction: 'Deny'
virtualNetworkRules: [
{
id: hub.routing.subnets.scripts
id: vNet::scriptSubnet.id
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't recommend using this approach. While an on-demand reference sounds nice, nobody else can use that unless we document the names and treat them as an API that never changes. If we use the variable in hub.routing.subnets, then we can tell everyone to use that forever without worrying about the name, even if we change it. The reason for us to use that same variable is because if we don't, then there might be a latent bug if the variable gets out of sync. When we rely on the same variable customers will use for extensibility, then we're much less likely to ship a bug.

Suggested change
id: vNet::scriptSubnet.id
id: hub.routing.subnets.scripts

@@ -317,7 +317,7 @@ resource scriptEndpoint 'Microsoft.Network/privateEndpoints@2023-11-01' = if (hu
tags: getHubTags(hub, 'Microsoft.Network/privateEndpoints')
properties: {
subnet: {
id: hub.routing.subnets.storage
id: vNet::finopsHubSubnet.id
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

Suggested change
id: vNet::finopsHubSubnet.id
id: hub.routing.subnets.storage

@@ -19,7 +19,7 @@ param hub HubProperties
var safeHubName = replace(replace(toLower(hub.name), '-', ''), '_', '')
// cSpell:ignore vnet
var vNetName = '${safeHubName}-vnet-${hub.location}'
var nsgName = '${hub.routing.networkName}-nsg'
var nsgName = '${vNetName}-nsg'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would not recommend this change. The hub.routing.networkName property is available to all apps. We should use that as the source of truth. If that's the same as vNetName here, then remove vNetName.

Suggested change
var nsgName = '${vNetName}-nsg'
var nsgName = '${hub.routing.networkName}-nsg'

@@ -19,7 +19,7 @@ param hub HubProperties
var safeHubName = replace(replace(toLower(hub.name), '-', ''), '_', '')
// cSpell:ignore vnet
var vNetName = '${safeHubName}-vnet-${hub.location}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't make this part of the next suggestion, but this line is a duplicate. The source of truth is in hub-types.bicep.

Suggested change
var vNetName = '${safeHubName}-vnet-${hub.location}'

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention πŸ‘‹ Issue or PR needs to be reviewed by the author or it will be closed due to no activity and removed Needs: Review πŸ‘€ PR that is ready to be reviewed labels Jul 3, 2025

@@MSBrett: you have some new feedback!

Please review and resolve all comments and I'll let reviewers know by removing the Needs: Attention label. If I miss anything, just reply with #needs-review and I'll update the status.

@flanakin flanakin added this to the 2025-06 - June milestone Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Micro PR πŸ”¬ Very small PR that should be especially easy for newcomers Needs: Attention πŸ‘‹ Issue or PR needs to be reviewed by the author or it will be closed due to no activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deployments fail when private networking is enabled.
3 participants