diff --git a/modules/container-instance/container-group/main.bicep b/modules/container-instance/container-group/main.bicep index 7479f3b30b..c6ae9e6363 100644 --- a/modules/container-instance/container-group/main.bicep +++ b/modules/container-instance/container-group/main.bicep @@ -116,14 +116,13 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena } } -resource cmkKeyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = if (!empty(cMKKeyVaultResourceId)) { - name: last(split(cMKKeyVaultResourceId, '/'))! - scope: resourceGroup(split(cMKKeyVaultResourceId, '/')[2], split(cMKKeyVaultResourceId, '/')[4]) -} +resource cMKKeyVault 'Microsoft.KeyVault/vaults@2021-10-01' existing = if (!empty(cMKKeyVaultResourceId)) { + name: last(split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : 'dummyVault'), '/'))! + scope: resourceGroup(split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : '//'), '/')[2], split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : '////'), '/')[4]) -resource cMKKeyVaultKey 'Microsoft.KeyVault/vaults/keys@2021-10-01' existing = if (!empty(cMKKeyVaultResourceId) && !empty(cMKKeyName)) { - name: '${last(split(cMKKeyVaultResourceId, '/'))}/${cMKKeyName}'! - scope: resourceGroup(split(cMKKeyVaultResourceId, '/')[2], split(cMKKeyVaultResourceId, '/')[4]) + resource cMKKey 'keys@2023-02-01' existing = if (!empty(cMKKeyName)) { + name: !empty(cMKKeyName) ? cMKKeyName : 'dummyKey' + } } resource containergroup 'Microsoft.ContainerInstance/containerGroups@2022-09-01' = { @@ -136,8 +135,8 @@ resource containergroup 'Microsoft.ContainerInstance/containerGroups@2022-09-01' encryptionProperties: !empty(cMKKeyName) ? { identity: cMKUserAssignedIdentityResourceId keyName: cMKKeyName - keyVersion: !empty(cMKKeyVersion) ? cMKKeyVersion : last(split(cMKKeyVaultKey.properties.keyUriWithVersion, '/')) - vaultBaseUrl: cmkKeyVault.properties.vaultUri + keyVersion: !empty(cMKKeyVersion) ? cMKKeyVersion : last(split(cMKKeyVault::cMKKey.properties.keyUriWithVersion, '/')) + vaultBaseUrl: cMKKeyVault.properties.vaultUri } : null imageRegistryCredentials: imageRegistryCredentials initContainers: initContainers