Problem with If, and getSecret function #1441
Replies: 2 comments 4 replies
-
Thanks for raising your first issue, the team appreciates the time you have taken 😉 |
Beta Was this translation helpful? Give feedback.
-
@PoborcaMaciej Thanks for raising the issue. It may depend on what your goal is with the condition that either returning a secret or I assume a dummy value. If you goal is to provide a test with a dummy value because you don't want to expose a secret in code then you shouldn't need to add the condition, you can just reference // ----------
// REFERENCES
// ----------
resource kv 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = {
name: 'kv-001'
}
resource ag 'Microsoft.Insights/actionGroups@2021-09-01' existing = {
name: 'ag-001'
}
resource vnet 'Microsoft.Network/virtualNetworks@2021-05-01' existing = {
name: 'vnet-001'
}
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2021-05-01' existing = {
parent: vnet
name: 'subnet-001'
}
// ---------
// RESOURCES
// ---------
// Test a basic VM
module test_vm_with_no_disks '../main.bicep' = {
name: 'test_vm_with_no_disks'
params: {
name: 'vm001'
adminUsername: kv.getSecret('vm-username')
adminPassword: kv.getSecret('vm-password')
subnetId: subnet.id
size: 'Standard_D2s_v3'
imageSKU: '2019-Datacenter-Core'
actionGroupId: ag.id
}
} PSRule for Azure will automatically use a placeholder value during expansion. Since this is more a question, I'm going to move it to discussion so that it might help someone else in the community out. I hope that helps. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have a problem with implementing tests for Bicep where I am using if conditions together with getSecret function. Do you know how I can solve it or if it is something that is not possible to omit?
Example of code that generates error
Exception calling "GetBicepResources" with "3" argument(s): "Unable to expand resources because the source file 'd:\agents\agent_work\24\s/tests/environments/test.bicep' was not valid. The template parameter 'test' does not use the required format."
Beta Was this translation helpful? Give feedback.
All reactions