-
Notifications
You must be signed in to change notification settings - Fork 774
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
Import of variable object fails with BCP338 #13997
Comments
@johndikeibm Is this something that happens repeatedly for you? I haven't been able to reproduce with the snippets included in the description, but I can tell from the screenshots the snippet is taken from a larger file. There were a couple of bugs fixed in earlier releases that had similar error messages to the one reported. VS Code may be using an older version of Bicep (it has its own copy and doesn't use the same one as the az CLI). Could you verify that VS Code is using 0.26.170? This is reported on the extension page in VS Code: |
@jeskew No, it's not something that happens frequently because this is the first time I am using imports. // sampleModule.bicep
@export()
var subscriptions = {
prod: 'subscriptions/13452556764478374367/'
dev: 'subscrptions/453465765756756776877/'
} That way I could do import {subscrption} from sampleModule.bicep
var someNewVar = subscriptions.prod //This works.
// The problem occurs when I try to reference the object using dot-notation inside of a List [ ] or array.
// The second screenshot shows that the value of the object property can be seen in the pop up.
// Still it shows the error message and lints the line with an error.
param resourceList = [
{
name: 'resource-1'
sub: subscriptions.prod
}
{
name: 'resource-2'
sub: subscriptions.dev
}
{
name: 'resource-3'
sub: subscriptions.prod
}
] |
@johndikeibm Sorry for the miscommunication, by "is this something that happens repeatedly for you?" I meant, "does this happen every time you view the file?" (vs an error that only happens sporadically or unpredictably). Could you share a bit more about your environment (OS and architecture)? I am not seeing the same error with the new snippets either, although I can only easily test on Windows and Linux x64. There shouldn't be any differences across environments, but that info might help repro the error: |
@jeskew I attempted to make a gif-like video, like you did, but couldn't. The video I recorded was too large for github. How did you make yours? This is a Windows machine. Error Message in main.bicepparam [Directory Structure)
{
// See https://aka.ms/bicep/config for more information on Bicep configuration options
// Press CTRL+SPACE/CMD+SPACE at any location to see Intellisense suggestions
"analyzers": {
"core": {
"rules": {
"no-unused-params": {
"level": "warning"
}
}
},
"experimentalFeaturesEnabled": {
"compileTimeImports": true,
"userDefinedFunctions": true,
"extensibility": true
}
}
}
targetScope = 'subscription'
param date string = utcNow()
param appServiceList array
param location string
module appService '../modules/appService.bicep'= [ for appServiceItem in appServiceList: {
name: '${appServiceItem.name}-${date}'
scope: resourceGroup(appServiceItem.resourceGroup)
params: {
appServiceName: appServiceItem.name
location: location
kind: appServiceItem.?kind
plan: appServiceItem.plan
siteConfig: appServiceItem.?stackConfig
}
}]
using 'main.bicep'
import { appStacks } from '../modules/appService.bicep'
param location = 'someLocation'
var aspItems = {
prod: '/subscriptions/245633435/'
dev: '/subscriptions/234567832/'
}
param appServiceList = [
{
name: 'resource-1'
plan: aspItems.prod
resourceGroup: 'resource-group-1'
stackConfig: appStacks.aspDotNet4
}
{
name: 'resource-2'
plan: aspItems.dev
resourceGroup: 'resource-group-2'
stackConfig: appStacks.dotNet8
}
{
name: 'resource-3'
plan: aspItems.prod
resourceGroup: 'resource-group-3'
stackConfig: appStacks.dotNet8
}
]
param appServiceName string
param location string
param plan string
@description('App service kind defaults to Windows Web app')
param kind string = 'app'
@description('Optional: Application sepcifica configuration')
param siteConfig object?
@export()
var appStacks = {
dotNet8: {
metadata:[
{
name: 'CURRENT_STACK'
value: 'dotnet'
}
]
netFrameworkVersion: 'v8.0'
}
aspDotNet4: {
metadata: [
{
name: 'CURRENT_STACK'
value: 'dotnet'
}
]
netFrameworkVersion: 'v4.8'
}
dotNet8Func: {
netFrameworkVersion: 'v8.0'
appSettings: [
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'dotnet-isolated'
}
]
}
}
resource appService 'Microsoft.Web/sites@2020-06-01' = {
name: appServiceName
location: location
kind: kind
properties: siteConfig
} |
Thanks for the thorough repro! This is a bug in how .bicepparam files handle variable imports from .bicep files; basically, if the .bicep file has any required parameters, you will see that error. You can work around this by moving the variable into a .bicep file without any declared parameters, but this is definitely something that should be fixed. I use ScreenToGif for the screenshots, but Window's built-in screenshot function (win + shift + s) can also take videos. |
Thank you very much. I did just that and it fixed the error. Snipping tool is how I got the screenshots to you. Sadly, recording a 30 second video provided a file too large for GitHub uploads. That's how I settled for screenshots. I look forward to the official fix for this bug. In the meantime, I'll use this workaround. |
Resolves #13997 Resolves #14069 This PR updates the `ParameterAssignmentEvaluator` to only evaluate the portions of imported templates that are used. This will allow imports from Bicep templates that have required parameters, which is not supported today. ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/14070)
Bicep version
Bicep CLI version 0.26.170 (e9abaf1)
Describe the bug
To Reproduce
bicepConfig.json
module.bicep
mainbicep.bicepparam
Additional context

Same screenshot while hovering over

locationOptions.location1
The text was updated successfully, but these errors were encountered: