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

Empty string in resource name fails, even when the resourse will not be used. #15632

Open
chambersDon opened this issue Nov 18, 2024 · 1 comment
Assignees
Milestone

Comments

@chambersDon
Copy link

chambersDon commented Nov 18, 2024

Bicep version
Bicep CLI version 0.31.92 (b065093)

Describe the bug
Optional parameters that default to empty string cause the error below, even though an if condition would cause the resource not to be used:
The template reference 'existingSubnet' is not valid: could not find template resource or resource copy with this name

To Reproduce
run this bicep:

param location string = 'CentralUS'
param resourceGroupForVnet string = ''
param vnetName string = ''
param subnetName string = ''
param allowPublicAccess bool = true


var blobPrivateEndpointName = 'pe-testendpoint'


resource existingSubnet 'Microsoft.Network/virtualNetworks/subnets@2022-05-01' existing = if(!allowPublicAccess) {
  name: '${vnetName}/${subnetName}'
  scope: resourceGroup(resourceGroupForVnet)
}

resource thePE 'Microsoft.Network/privateEndpoints@2022-11-01' = if(!allowPublicAccess){
  name: blobPrivateEndpointName
  location: location
  properties: {
    subnet: {
      id: existingSubnet.id
    }
  }
}


type grantType = {}

With version 0.31.92 you will get this error:

Additional context
I was getting this error when uses version 0.29.45. I upgraded to 0.31.34 and the error went away. Last week, I upgraded to 0.31.92 and the error has returned.

If I remove the thePE resource OR the type defintion then I don't get the error.

@github-project-automation github-project-automation bot moved this to Todo in Bicep Nov 18, 2024
@chambersDon chambersDon changed the title Empty string in resource name fails, eveb when the resourse will not be used. Empty string in resource name fails, even when the resourse will not be used. Nov 18, 2024
@jeskew
Copy link
Contributor

jeskew commented Nov 18, 2024

@chambersDon The fix in 0.31.34 had to be reverted but should be back for v0.32. There's some more context in the description of #15580 if you're curious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

3 participants