Azure / arm-ttk

Azure Resource Manager Template Toolkit
https://aka.ms/arm-ttk
MIT License
441 stars 188 forks source link

Bug with "Parameter Types Should Be Consistent" test #738

Closed edwardsp closed 9 months ago

edwardsp commented 1 year ago

I am naming a resource using a property of an object passed as an input parameter to an ARM template and it is causing the 'Parameter Types Should Be Consistent' test to fail.

mainTemplate.bicep

targetScope = 'resourceGroup'

param input object

module module1 './mymodule.bicep' = {
  name: input.module_one // setting to 'moduleOne' works correctly
  params: {
    intext: 'hello'
  }
}

module module2 './mymodule.bicep' = {
  name: 'moduleTwo'
  params: {
    intext: module1.outputs.outtext
  }
}

mymodule.bicep

targetScope = 'resourceGroup'

param intext string

output outtext string = intext

This is the output from arm-ttk:

  Parameter Types Should Be Consistent                                                                    
    [-] Parameter Types Should Be Consistent (65 ms)                                                      
        Type Mismatch: Parameter 'intext' in nested template 'moduleTwo' is defined as string, but the pa 
rent template defines it as object). Line: 81, Column: 14                                                 
                                                                Parameter Types Should Be Consistent                                                                    
    [-] Parameter Types Should Be Consistent (65 ms)                                                      
        Type Mismatch: Parameter 'intext' in nested template 'moduleTwo' is defined as string, but the pa 
rent template defines it as object). Line: 81, Column: 14                                                 

Setting the name as a string will fix this. But, in my case I am actually setting a resourceGroup name based on an json input.

edwardsp commented 1 year ago

A workaround for this issue is to create a variable first, e.g.

var module_one = input.module_one

Then use the module_one variable when setting the module name.