-
Notifications
You must be signed in to change notification settings - Fork 757
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
Ternary operator on module scope #10419
Comments
You can drop back to this syntax as the workaround for this for now. module storage 'modules/storage.bicep' = {
scope: resourceGroup(newResourceGroupRequired ? newResourceGroup.name : existingResourceGroup.name) // <-- workaround
name: 'storage'
params: {
location: location
storageAccountName: 'satestmikeb56'
}
} |
That worked perfectly, thanks very much! |
Just to add a comment and say I hit this earlier today too, but I got it on a variable that was a ternary of two resourcegroups so I think this might not be restricted to only scope functions. My bicep was like the below (Stripped down for a repro): param UseRGOfKeyVault bool = false
param KeyVaultId string = '' //ResourceId of a keyvault
var TheResourceGroup = UseRGOfKeyVault ? resourceGroup(split(KeyVaultId,'/')[4]) : resourceGroup()
module 'SubModule' submodule.bicep {
name: 'submodule'
scope: TheResourceGroup
} When compiled into ARM the TheResourceGroup variable looked like the below: "KeyVaultResourceGroup": "[if(parameters('UseRGOfKeyVault'), createObject(), resourceGroup())]", Hopefully this is something that can either be fixed or flagged in bicep as something that doesn't work |
Have created another minimal repro to see if it was to do with my use of Bicep: param TheCondition bool = true
param AResourceId string
var TheSpecificResourceGroup = split(AResourceId, '/')[4]
var BothDefaultResourceGroup = TheCondition ? resourceGroup() : resourceGroup()
var FirstHardcodedResourceGroup = TheCondition ? resourceGroup('testing-rg') : resourceGroup()
var FirstSpecificResourceGroup = TheCondition ? resourceGroup(split(AResourceId, '/')[4]) : resourceGroup()
var SecondSpecificResourceGroup = TheCondition ? resourceGroup() : resourceGroup(split(AResourceId, '/')[4])
var BothSpecificResourceGroup = TheCondition ? resourceGroup(split(AResourceId, '/')[4]) : resourceGroup(split(AResourceId, '/')[4]) ARM:
|
@anthony-c-martin can you please review above while looking at #10475 |
Good catch - yes these look like the same issue to me. |
Closing because of duplicate issue |
Discussed in #10417
Originally posted by TacticalNuclearSpud April 13, 2023
Is it possible to use the ternary operator on the scope tag of a bicep module? The template I have validates fine but fails on deployment.
I'd like to be able to specify if a new resource group is required, if it is, deploy it and subsequently deploy the module resources into it, but, if not, take the name of an existing resource group and deploy the resources to that.
I'm relatively new to bicep and really struggling to get my head round this one.
Current main.bicep
The deployment fails with
If I leave the
newResourceGroupRequired
value set as false and set the scope on the module declaration to reference thenewResourceGroup
resource directly, as below, it deploys fine.Same if I change the bool to true and set the scope to
existingResourceGroup
, the storage module deploys without issue.If used the ternary operator successfully on other parameters recently but I'm unable to do so in this case. Is there a another/better way to accomplish this?
Any help would be greatly appreciated!
It appears the nested deployment is not building correctly:
what it is building to:
what it should be building to:
The text was updated successfully, but these errors were encountered: