Skip to content

Commit

Permalink
Updated reg
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Oct 20, 2023
1 parent 4cf5872 commit 5fcd5ec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
18 changes: 11 additions & 7 deletions modules/container-registry/registry/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,18 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena
}
}

resource cMKUserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = if (!empty(cMKUserAssignedIdentityResourceId)) {
name: last(split(cMKUserAssignedIdentityResourceId, '/'))!
scope: resourceGroup(split(cMKUserAssignedIdentityResourceId, '/')[2], split(cMKUserAssignedIdentityResourceId, '/')[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 cMKKey 'keys@2023-02-01' existing = if (!empty(cMKKeyName)) {
name: !empty(cMKKeyName) ? cMKKeyName : 'dummyKey'
}
}

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 cMKUserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = if (!empty(cMKUserAssignedIdentityResourceId)) {
name: last(split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : 'dummyMsi'), '/'))!
scope: resourceGroup(split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : '//'), '/')[2], split((!empty(cMKKeyVaultResourceId) ? cMKKeyVaultResourceId : '////'), '/')[4])
}

resource registry 'Microsoft.ContainerRegistry/registries@2023-06-01-preview' = {
Expand All @@ -247,7 +251,7 @@ resource registry 'Microsoft.ContainerRegistry/registries@2023-06-01-preview' =
status: 'enabled'
keyVaultProperties: {
identity: cMKUserAssignedIdentity.properties.clientId
keyIdentifier: !empty(cMKKeyVersion) ? '${cMKKeyVaultKey.properties.keyUri}/${cMKKeyVersion}' : cMKKeyVaultKey.properties.keyUriWithVersion
keyIdentifier: !empty(cMKKeyVersion) ? '${cMKKeyVault::cMKKey.properties.keyUri}/${cMKKeyVersion}' : cMKKeyVault::cMKKey.properties.keyUriWithVersion
}
} : null
policies: {
Expand Down
44 changes: 28 additions & 16 deletions modules/container-registry/registry/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"_generator": {
"name": "bicep",
"version": "0.22.6.54827",
"templateHash": "15598884416180127975"
"templateHash": "12613913283174213145"
},
"name": "Azure Container Registries (ACR)",
"description": "This module deploys an Azure Container Registry (ACR).",
Expand Down Expand Up @@ -406,6 +406,18 @@
"enableReferencedModulesTelemetry": false
},
"resources": {
"cMKKeyVault::cMKKey": {
"condition": "[and(not(empty(parameters('cMKKeyVaultResourceId'))), not(empty(parameters('cMKKeyName'))))]",
"existing": true,
"type": "Microsoft.KeyVault/vaults/keys",
"apiVersion": "2023-02-01",
"subscriptionId": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '//'), '/')[2]]",
"resourceGroup": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '////'), '/')[4]]",
"name": "[format('{0}/{1}', last(split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), 'dummyVault'), '/')), if(not(empty(parameters('cMKKeyName'))), parameters('cMKKeyName'), 'dummyKey'))]",
"dependsOn": [
"cMKKeyVault"
]
},
"defaultTelemetry": {
"condition": "[parameters('enableDefaultTelemetry')]",
"type": "Microsoft.Resources/deployments",
Expand All @@ -420,23 +432,23 @@
}
}
},
"cMKKeyVault": {
"condition": "[not(empty(parameters('cMKKeyVaultResourceId')))]",
"existing": true,
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2021-10-01",
"subscriptionId": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '//'), '/')[2]]",
"resourceGroup": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '////'), '/')[4]]",
"name": "[last(split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), 'dummyVault'), '/'))]"
},
"cMKUserAssignedIdentity": {
"condition": "[not(empty(parameters('cMKUserAssignedIdentityResourceId')))]",
"existing": true,
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2018-11-30",
"subscriptionId": "[split(parameters('cMKUserAssignedIdentityResourceId'), '/')[2]]",
"resourceGroup": "[split(parameters('cMKUserAssignedIdentityResourceId'), '/')[4]]",
"name": "[last(split(parameters('cMKUserAssignedIdentityResourceId'), '/'))]"
},
"cMKKeyVaultKey": {
"condition": "[and(not(empty(parameters('cMKKeyVaultResourceId'))), not(empty(parameters('cMKKeyName'))))]",
"existing": true,
"type": "Microsoft.KeyVault/vaults/keys",
"apiVersion": "2021-10-01",
"subscriptionId": "[split(parameters('cMKKeyVaultResourceId'), '/')[2]]",
"resourceGroup": "[split(parameters('cMKKeyVaultResourceId'), '/')[4]]",
"name": "[format('{0}/{1}', last(split(parameters('cMKKeyVaultResourceId'), '/')), parameters('cMKKeyName'))]"
"apiVersion": "2023-01-31",
"subscriptionId": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '//'), '/')[2]]",
"resourceGroup": "[split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), '////'), '/')[4]]",
"name": "[last(split(if(not(empty(parameters('cMKKeyVaultResourceId'))), parameters('cMKKeyVaultResourceId'), 'dummyMsi'), '/'))]"
},
"registry": {
"type": "Microsoft.ContainerRegistry/registries",
Expand All @@ -451,7 +463,7 @@
"properties": {
"anonymousPullEnabled": "[parameters('anonymousPullEnabled')]",
"adminUserEnabled": "[parameters('acrAdminUserEnabled')]",
"encryption": "[if(not(empty(parameters('cMKKeyName'))), createObject('status', 'enabled', 'keyVaultProperties', createObject('identity', reference('cMKUserAssignedIdentity').clientId, 'keyIdentifier', if(not(empty(parameters('cMKKeyVersion'))), format('{0}/{1}', reference('cMKKeyVaultKey').keyUri, parameters('cMKKeyVersion')), reference('cMKKeyVaultKey').keyUriWithVersion))), null())]",
"encryption": "[if(not(empty(parameters('cMKKeyName'))), createObject('status', 'enabled', 'keyVaultProperties', createObject('identity', reference('cMKUserAssignedIdentity').clientId, 'keyIdentifier', if(not(empty(parameters('cMKKeyVersion'))), format('{0}/{1}', reference('cMKKeyVault::cMKKey').keyUri, parameters('cMKKeyVersion')), reference('cMKKeyVault::cMKKey').keyUriWithVersion))), null())]",
"policies": {
"azureADAuthenticationAsArmPolicy": {
"status": "[parameters('azureADAuthenticationAsArmPolicyStatus')]"
Expand All @@ -477,7 +489,7 @@
"zoneRedundancy": "[if(equals(parameters('acrSku'), 'Premium'), parameters('zoneRedundancy'), null())]"
},
"dependsOn": [
"cMKKeyVaultKey",
"cMKKeyVault",
"cMKUserAssignedIdentity"
]
},
Expand Down

0 comments on commit 5fcd5ec

Please sign in to comment.