@@ -23,27 +23,17 @@ var tags = {
2323 repo : 'https://github.com/azure-samples/cosmos-db-table-python-quickstart'
2424}
2525
26- var tableName = 'cosmicworks-products'
27-
28- module keyVault 'br/public:avm/res/key-vault/vault:0.10.2' = {
29- name : 'key-vault'
26+ module managedIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.4.0' = {
27+ name : 'user-assigned-identity'
3028 params : {
31- name : 'key-vault -${resourceToken }'
29+ name : 'managed-identity -${resourceToken }'
3230 location : location
33- sku : 'standard'
34- enablePurgeProtection : false
35- enableSoftDelete : false
36- publicNetworkAccess : 'Enabled'
37- enableRbacAuthorization : true
38- secrets : [
39- {
40- name : 'key-vault-secret-azure-cosmos-db-table-key'
41- value : ''
42- }
43- ]
31+ tags : tags
4432 }
4533}
4634
35+ var tableName = 'cosmicworks-products'
36+
4737module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.8.1' = {
4838 name : 'cosmos-db-account'
4939 params : {
@@ -57,8 +47,8 @@ module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.8.1' =
5747 }
5848 ]
5949 tags : tags
60- disableKeyBasedMetadataWriteAccess : false
61- disableLocalAuth : false
50+ disableKeyBasedMetadataWriteAccess : true
51+ disableLocalAuth : true
6252 networkRestrictions : {
6353 publicNetworkAccess : 'Enabled'
6454 ipRules : []
@@ -68,13 +58,25 @@ module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.8.1' =
6858 'EnableServerless'
6959 'EnableTable'
7060 ]
71- secretsExportConfiguration : {
72- keyVaultResourceId : keyVault .outputs .resourceId
73- primaryWriteKeySecretName : 'key-vault-secret-azure-cosmos-db-table-key'
74- }
61+ sqlRoleDefinitions : [
62+ {
63+ name : 'table-data-plane-contributor'
64+ dataAction : [
65+ 'Microsoft.DocumentDB/databaseAccounts/readMetadata' // Read account metadata
66+ 'Microsoft.DocumentDB/databaseAccounts/tables/*' // Manage tables
67+ 'Microsoft.DocumentDB/databaseAccounts/tables/containers/entities/*' // Create entities
68+ ]
69+ }
70+ ]
71+ sqlRoleAssignmentsPrincipalIds : union (
72+ [
73+ managedIdentity .outputs .principalId
74+ ],
75+ !empty (deploymentUserPrincipalId ) ? [deploymentUserPrincipalId ] : []
76+ )
7577 tables : [
7678 {
77- name : tableName
79+ name : tableName
7880 }
7981 ]
8082 }
@@ -127,34 +129,8 @@ module containerAppsEnvironment 'br/public:avm/res/app/managed-environment:0.8.0
127129 }
128130}
129131
130- module managedIdentity 'br/public:avm/res/managed-identity/user-assigned-identity:0.4.0' = {
131- name : 'user-assigned-identity'
132- params : {
133- name : 'managed-identity-${resourceToken }'
134- location : location
135- tags : tags
136- }
137- }
138-
139- var keyVaultRole = subscriptionResourceId (
140- 'Microsoft.Authorization/roleDefinitions' ,
141- '4633458b-17de-408a-b874-0445c86b69e6'
142- ) // Key Vault Secrets User built-in role
143-
144- module keyVaultAppAssignment 'br/public:avm/ptn/authorization/resource-role-assignment:0.1.1' = {
145- name : 'key-vault-role-assignment-secrets-user'
146- params : {
147- principalId : managedIdentity .outputs .principalId
148- resourceId : keyVault .outputs .resourceId
149- roleDefinitionId : keyVaultRole
150- }
151- }
152-
153132module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
154133 name : 'container-apps-app'
155- dependsOn : [
156- keyVaultAppAssignment // Need to wait for the role assignment to complete before creating the container app
157- ]
158134 params : {
159135 name : 'container-app-${resourceToken }'
160136 environmentResourceId : containerAppsEnvironment .outputs .resourceId
@@ -185,13 +161,8 @@ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
185161 value : 'https://${cosmosDbAccount .outputs .name }.table.cosmos.azure.com:443/'
186162 }
187163 {
188- name : 'azure-cosmos-db-table-account-name'
189- value : cosmosDbAccount .outputs .name
190- }
191- {
192- identity : managedIdentity .outputs .resourceId
193- name : 'azure-cosmos-db-table-write-key'
194- keyVaultUrl : cosmosDbAccount .outputs .exportedSecrets ['key-vault-secret-azure-cosmos-db-table-key' ].secretUri
164+ name : 'user-assigned-managed-identity-client-id'
165+ value : managedIdentity .outputs .clientId
195166 }
196167 ]
197168 }
@@ -204,37 +175,27 @@ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
204175 memory : '.5Gi'
205176 }
206177 env : [
207- {
208- name : 'CONFIGURATION__AZURECOSMOSDB__ACCOUNTNAME'
209- secretRef : 'azure-cosmos-db-table-account-name'
210- }
211178 {
212179 name : 'CONFIGURATION__AZURECOSMOSDB__ENDPOINT'
213180 secretRef : 'azure-cosmos-db-table-endpoint'
214181 }
215- {
216- name : 'CONFIGURATION__AZURECOSMOSDB__KEY'
217- secretRef : 'azure-cosmos-db-table-write-key'
218- }
219182 {
220183 name : 'CONFIGURATION__AZURECOSMOSDB__TABLENAME'
221184 value : tableName
222185 }
186+ {
187+ name : 'AZURE_CLIENT_ID'
188+ secretRef : 'user-assigned-managed-identity-client-id'
189+ }
223190 ]
224191 }
225192 ]
226193 }
227194}
228195
229196// Azure Cosmos DB for Table outputs
230- output CONFIGURATION__AZURECOSMOSDB__ACCOUNTNAME string = cosmosDbAccount .outputs .name
231197output CONFIGURATION__AZURECOSMOSDB__ENDPOINT string = 'https://${cosmosDbAccount .outputs .name }.table.cosmos.azure.com:443/'
232- #disable-next-line outputs-should-not-contain-secrets // This secret is required
233- output CONFIGURATION__AZURECOSMOSDB__KEY string = listKeys (
234- resourceId ('Microsoft.DocumentDB/databaseAccounts' , 'cosmos-db-table-${resourceToken }' ),
235- '2021-04-15'
236- ).primaryMasterKey
237198output CONFIGURATION__AZURECOSMOSDB__TABLENAME string = tableName
238199
239200// Azure Container Registry outputs
240- output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry .outputs .loginServer
201+ output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry .outputs .loginServer
0 commit comments