Skip to content
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

feat: Added CMK schema & introduced type import #1683

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/content/specs-defs/specs/shared/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ In Terraform, locks become part of the resource graph and suitable `depends_on`

{{< tabs "cmk" >}}
{{< tab "Bicep User Defined Type, Parameter & Resource Example" >}}
{{< include file="/static/includes/interfaces/int.cmk.udt.schema.bicep" language="bicep" options="linenos=false" >}}
{{< expand "➕ Variant 1: The resource does not support auto-key-rotation" "expand/collapse" >}}
{{< include file="/static/includes/interfaces/int.cmk.udt.schema1.bicep" language="bicep" options="linenos=false" >}}
{{< /expand >}}
{{< expand "➕ Variant 2: The resource does support auto-key-rotation" "expand/collapse" >}}
{{< include file="/static/includes/interfaces/int.cmk.udt.schema2.bicep" language="bicep" options="linenos=false" >}}
{{< /expand >}}
{{< /tab >}}
{{< tab "Bicep Input Example with Values" >}}
{{< include file="/static/includes/interfaces/int.cmk.input.bicep" language="bicep" options="linenos=false" >}}
Expand Down
63 changes: 0 additions & 63 deletions docs/static/includes/interfaces/int.cmk.udt.schema.bicep

This file was deleted.

61 changes: 61 additions & 0 deletions docs/static/includes/interfaces/int.cmk.udt.schema1.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// ============== //
// Parameters //
// ============== //

import { customerManagedKeyType } from 'br/public:avm/utl/types/avm-common-types:0.4.0'
@description('Optional. The customer managed key definition.')
param customerManagedKey customerManagedKeyType?

// ============= //
// Resources //
// ============= //

resource cMKKeyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId)) {
name: last(split((customerManagedKey.?keyVaultResourceId ?? 'dummyVault'), '/'))
scope: resourceGroup(
split((customerManagedKey.?keyVaultResourceId ?? '//'), '/')[2],
split((customerManagedKey.?keyVaultResourceId ?? '////'), '/')[4]
)

resource cMKKey 'keys@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId) && !empty(customerManagedKey.?keyName)) {
name: customerManagedKey.?keyName ?? 'dummyKey'
}
}

resource cMKUserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = if (!empty(customerManagedKey.?userAssignedIdentityResourceId)) {
name: last(split(customerManagedKey.?userAssignedIdentityResourceId ?? 'dummyMsi', '/'))
scope: resourceGroup(
split((customerManagedKey.?userAssignedIdentityResourceId ?? '//'), '/')[2],
split((customerManagedKey.?userAssignedIdentityResourceId ?? '////'), '/')[4]
)
}

resource >singularMainResourceType< '>providerNamespace</>resourceType<@>apiVersion<' = {
name: '>exampleResource<'
properties: {
... // other properties
encryption: !empty(customerManagedKey)
? {
keySource: 'Microsoft.KeyVault'
keyVaultProperties: {
keyVaultUri: cMKKeyVault.properties.vaultUri
keyName: customerManagedKey!.keyName
keyVersion: !empty(customerManagedKey.?keyVersion ?? '')
? customerManagedKey!.keyVersion
: last(split(cMKKeyVault::cMKKey.properties.keyUriWithVersion, '/'))
keyIdentifier: !empty(customerManagedKey.?keyVersion ?? '')
? '${cMKKeyVault::cMKKey.properties.keyUri}/${customerManagedKey!.keyVersion}'
: cMKKeyVault::cMKKey.properties.keyUriWithVersion
identityClientId: !empty(customerManagedKey.?userAssignedIdentityResourceId ?? '')
? cMKUserAssignedIdentity.properties.clientId
: null
identity: !empty(customerManagedKey.?userAssignedIdentityResourceId)
? {
userAssignedIdentity: cMKUserAssignedIdentity.id
}
: null
}
}
: null
}
}
64 changes: 64 additions & 0 deletions docs/static/includes/interfaces/int.cmk.udt.schema2.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// ============== //
// Parameters //
// ============== //
import { customerManagedKeyWithAutoRotateType } from 'br/public:avm/utl/types/avm-common-types:0.4.0'
@description('Optional. The customer managed key definition.')
param customerManagedKey customerManagedKeyWithAutoRotateType?

// ============= //
// Resources //
// ============= //

resource cMKKeyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId)) {
name: last(split((customerManagedKey.?keyVaultResourceId ?? 'dummyVault'), '/'))
scope: resourceGroup(
split((customerManagedKey.?keyVaultResourceId ?? '//'), '/')[2],
split((customerManagedKey.?keyVaultResourceId ?? '////'), '/')[4]
)

resource cMKKey 'keys@2023-02-01' existing = if (!empty(customerManagedKey.?keyVaultResourceId) && !empty(customerManagedKey.?keyName)) {
name: customerManagedKey.?keyName ?? 'dummyKey'
}
}

resource cMKUserAssignedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = if (!empty(customerManagedKey.?userAssignedIdentityResourceId)) {
name: last(split(customerManagedKey.?userAssignedIdentityResourceId ?? 'dummyMsi', '/'))
scope: resourceGroup(
split((customerManagedKey.?userAssignedIdentityResourceId ?? '//'), '/')[2],
split((customerManagedKey.?userAssignedIdentityResourceId ?? '////'), '/')[4]
)
}

resource >singularMainResourceType< '>providerNamespace</>resourceType<@>apiVersion<' = {
name: '>exampleResource<'
properties: {
... // other properties
encryption: !empty(customerManagedKey)
? {
keySource: 'Microsoft.KeyVault'
keyVaultProperties: {
keyVaultUri: cMKKeyVault.properties.vaultUri
keyName: customerManagedKey!.keyName
keyVersion: !empty(customerManagedKey.?keyVersion ?? '')
? customerManagedKey!.keyVersion
: (customerManagedKey.?autoRotationEnabled ?? true)
? null
: last(split(cMKKeyVault::cMKKey.properties.keyUriWithVersion, '/'))
keyIdentifier: !empty(customerManagedKey.?keyVersion ?? '')
? '${cMKKeyVault::cMKKey.properties.keyUri}/${customerManagedKey!.keyVersion}'
: (customerManagedKey.?autoRotationEnabled ?? true)
? cMKKeyVault::cMKKey.properties.keyUri
: cMKKeyVault::cMKKey.properties.keyUriWithVersion
identityClientId: !empty(customerManagedKey.?userAssignedIdentityResourceId ?? '')
? cMKUserAssignedIdentity.properties.clientId
: null
identity: !empty(customerManagedKey.?userAssignedIdentityResourceId)
? {
userAssignedIdentity: cMKUserAssignedIdentity.id
}
: null
}
}
: null
}
}
51 changes: 2 additions & 49 deletions docs/static/includes/interfaces/int.diag.udt.schema.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Parameters //
// ============== //

import { diagnosticSettingFullType } from 'br/public:avm/utl/types/avm-common-types:0.3.0'
@description('Optional. The diagnostic settings of the service.')
param diagnosticSettings diagnosticSettingType
param diagnosticSettings diagnosticSettingFullType[]?

// ============= //
// Resources //
Expand Down Expand Up @@ -32,51 +33,3 @@ resource >singularMainResourceType<_diagnosticSettings 'Microsoft.Insights/diagn
}
scope: >singularMainResourceType<
}]

// =============== //
// Definitions //
// =============== //

type diagnosticSettingType = {
@description('Optional. The name of diagnostic setting.')
name: string?

@description('Optional. The name of logs that will be streamed. "allLogs" includes all possible logs for the resource. Set to `[]` to disable log collection.')
logCategoriesAndGroups: {
@description('Optional. Name of a Diagnostic Log category for a resource type this setting is applied to. Set the specific logs to collect here.')
category: string?

@description('Optional. Name of a Diagnostic Log category group for a resource type this setting is applied to. Set to `allLogs` to collect all logs.')
categoryGroup: string?

@description('Optional. Enable or disable the category explicitly. Default is `true`.')
enabled: bool?
}[]?

@description('Optional. The name of metrics that will be streamed. "allMetrics" includes all possible metrics for the resource. Set to `[]` to disable metric collection.')
metricCategories: {
@description('Required. Name of a Diagnostic Metric category for a resource type this setting is applied to. Set to `AllMetrics` to collect all metrics.')
category: string

@description('Optional. Enable or disable the category explicitly. Default is `true`.')
enabled: bool?
}[]?

@description('Optional. A string indicating whether the export to Log Analytics should use the default destination type, i.e. AzureDiagnostics, or use a destination type.')
logAnalyticsDestinationType: ('Dedicated' | 'AzureDiagnostics')?

@description('Optional. Resource ID of the diagnostic log analytics workspace. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
workspaceResourceId: string?

@description('Optional. Resource ID of the diagnostic storage account. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
storageAccountResourceId: string?

@description('Optional. Resource ID of the diagnostic event hub authorization rule for the Event Hubs namespace in which the event hub should be created or streamed to.')
eventHubAuthorizationRuleResourceId: string?

@description('Optional. Name of the diagnostic event hub within the namespace to which logs are streamed. Without this, an event hub is created for each log category. For security reasons, it is recommended to set diagnostic settings to send data to either storage account, log analytics workspace or event hub.')
eventHubName: string?

@description('Optional. The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic Logs.')
marketplacePartnerResourceId: string?
}[]?
15 changes: 2 additions & 13 deletions docs/static/includes/interfaces/int.locks.udt.schema.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Parameters //
// ============== //

import { lockType } from 'br/public:avm/utl/types/avm-common-types:0.3.0'
@description('Optional. The lock settings of the service.')
param lock lockType
param lock lockType?

// ============= //
// Resources //
Expand All @@ -18,15 +19,3 @@ resource >singularMainResourceType<_lock 'Microsoft.Authorization/locks@2020-05-
}
scope: >singularMainResourceType<
}

// =============== //
// Definitions //
// =============== //

type lockType = {
@description('Optional. Specify the name of lock.')
name: string?

@description('Optional. Specify the type of lock.')
kind: ('CanNotDelete' | 'ReadOnly' | 'None')?
}?
17 changes: 3 additions & 14 deletions docs/static/includes/interfaces/int.mi.udt.schema.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// Parameters //
// ============== //

import { managedIdentityAllType } from 'br/public:avm/utl/types/avm-common-types:0.3.0'
@description('Optional. The managed identity definition for this resource.')
param managedIdentities managedIdentitiesType
param managedIdentities managedIdentityAllType?

// ============= //
// Variables //
Expand Down Expand Up @@ -33,16 +34,4 @@ resource >singularMainResourceType< '>providerNamespace</>resourceType<@>apiVers
// =========== //

@description('The principal ID of the system assigned identity.')
output systemAssignedMIPrincipalId string = >singularMainResourceType<.?identity.?principalId ?? ''

// =============== //
// Definitions //
// =============== //

type managedIdentitiesType = {
@description('Optional. Enables system assigned managed identity on the resource.')
systemAssigned: bool?

@description('Optional. The resource ID(s) to assign to the resource. Required if a user assigned identity is used for encryption.')
userAssignedResourceIds: string[]?
}?
output systemAssignedMIPrincipalId string? = >singularMainResourceType<.?identity.?principalId
Loading