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

User defined function does not render object keys after publish. #13663

Closed
MadsHT opened this issue Mar 20, 2024 · 2 comments · Fixed by #13665
Closed

User defined function does not render object keys after publish. #13663

MadsHT opened this issue Mar 20, 2024 · 2 comments · Fixed by #13665

Comments

@MadsHT
Copy link

MadsHT commented Mar 20, 2024

Bicep version

> az bicep version
Bicep CLI version 0.26.54 (5e20b29b58)

Describe the bug

I have a user defined function that is called "genModuleTags" and looks like this:

type moduleTags = {
  *: string
}

@export()
func genModuleTags(mdFileContent string, moduleName string, moduleRace string) moduleTags => {
  '${contains(moduleName, 'zoo') ? 'Zoo' : 'Genum'} name': moduleName
  '${contains(moduleName, 'zoo') ? 'Zoo' : 'Genum'} race': moduleRace
  '${contains(moduleName, 'zoo') ? 'Zoo' : 'Genum'} version': trim(split(
    filter(split(mdFileContent, '\n'), (item) => contains(item, 'Version:'))[0],
    ':'
  )[1])
}

If I deploy the following bicep file:

import * as sharedTypes from '../race1.bicep'

var moduleTags = sharedTypes.genModuleTags(
  loadTextContent('../races/race1/shared-types race1.md'),
  'shared-types',
  'race1'
)

output moduleTags object = moduleTags

I get the expected output:

"outputs": {
  "moduleTags": {
    "type": "Object",
    "value": {
      "Genum name": "shared-types",
      "Genum race": "race1",
      "Genum version": "1.1.0"
    }
  }
}

But if I publish the module to an ACR and run the same file but using the ACR module instead:

// import * as sharedTypes from '../race1.bicep'
import * as sharedTypes from 'br:<acrName>.azurecr.io/shared-types/race1:version_1.1.0'

var moduleTags = sharedTypes.genModuleTags(
  loadTextContent('../races/race1/shared-types race1.md'),
  'shared-types',
  'race1'
)

output moduleTags object = moduleTags

The output is malformed, the keys in the object not being rendered correctly:

"outputs": {
  "moduleTags": {
    "type": "Object",
    "value": {
      "[format('{0} name', if(contains(parameters('moduleName'), 'zoo'), 'Zoo', 'Genum'))]": "shared-types",
      "[format('{0} race', if(contains(parameters('moduleName'), 'zoo'), 'Zoo', 'Genum'))]": "race1",
      "[format('{0} version', if(contains(parameters('moduleName'), 'zoo'), 'Zoo', 'Genum'))]": "1.1.0"
    }
  }
}

To Reproduce

  1. Make a bicep file that contains the following function:
type moduleTags = {
  *: string
}

@export()
func genModuleTags(moduleName string) moduleTags => {
  '${contains(moduleName, 'name') ? 'name' : 'noName '} name': moduleName
}
  1. Publish it to an container registry.

Make another file that can reference the function using imports:

import * as sharedTypes from 'br:<url to the module>'

var moduleTags = sharedTypes.genModuleTags('name')

output moduleTags object = moduleTags

And run the bicep file that imports the function, the result should be that the resulting objects keys has not been rendered correctly.

"outputs": {
  "moduleTags": {
    "type": "Object",
    "value": {
      "[format('{0} name', if(contains(parameters('moduleName'), 'name'), 'name', 'noName '))]": "name"
    }
  }
}
@anthony-c-martin
Copy link
Member

Thanks for reporting this! Looks like we have a bug in how we read back ARM expressions in object keys - I've submitted a fix.

@MadsHT
Copy link
Author

MadsHT commented Mar 20, 2024

Awesome, thank you for the quick work and response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants