Skip to content

Commit 23b5d72

Browse files
authored
[Hub apps] Create the hub-vault module for saving secrets (#1497)
1 parent f96fa24 commit 23b5d72

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

Diff for: docs-mslearn/toolkit/changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following section lists features and enhancements that are currently in deve
3535
- Created a new bicep modules to support extensibility:
3636
- The **hub-app** module tracks telemetry when an app is deployed.
3737
- The **hub-storage** module creates containers in the hub storage account.
38+
- The **hub-vault** module adds secrets to the hub vault.
3839

3940
**Fixed**
4041
- Workaround subnets reordering and bicep limitation

Diff for: src/templates/finops-hub/modules/hub-vault.bicep

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
//==============================================================================
5+
// Parameters
6+
//==============================================================================
7+
8+
@description('Required. Name of the publisher-specific Key Vault instance.')
9+
param vaultName string
10+
11+
@description('Required. Name of the Key Vault secret to create or update.')
12+
param secretName string
13+
14+
@description('Required. Value of the Key Vault secret.')
15+
@secure()
16+
param secretValue string
17+
18+
@description('Optional. Value of the Key Vault secret expiration date (exp) property. This is represented as seconds since Jan 1, 1970.')
19+
param secretExpirationInSeconds int = -1
20+
21+
@description('Optional. Value of the Key Vault secret not before date (nbf) property. This is represented as seconds since Jan 1, 1970.')
22+
param secretNotBeforeInSeconds int = -1
23+
24+
25+
//==============================================================================
26+
// Resources
27+
//==============================================================================
28+
29+
resource vault 'Microsoft.KeyVault/vaults@2023-02-01' existing = {
30+
name: vaultName
31+
32+
resource secret 'secrets' = {
33+
name: secretName
34+
properties: {
35+
attributes: union({
36+
enabled: true
37+
}, secretExpirationInSeconds <= 0 ? {} : {
38+
exp: secretExpirationInSeconds
39+
}, secretNotBeforeInSeconds <= 0 ? {} : {
40+
nbf: secretNotBeforeInSeconds
41+
})
42+
value: secretValue
43+
}
44+
}
45+
}
46+
47+
48+
//==============================================================================
49+
// Outputs
50+
//==============================================================================
51+
52+
@description('Name of the Key Vault secret.')
53+
output secretName string = vault::secret.name

Diff for: src/templates/finops-hub/modules/keyVault.bicep

+9-10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var formattedAccessPolicies = [for accessPolicy in accessPolicies: {
6666
// Resources
6767
//==============================================================================
6868

69+
// TODO: Move vault creation to the hub-app module
6970
resource keyVault 'Microsoft.KeyVault/vaults@2023-02-01' = {
7071
name: keyVaultName
7172
location: location
@@ -100,16 +101,14 @@ resource keyVault_accessPolicies 'Microsoft.KeyVault/vaults/accessPolicies@2023-
100101
}
101102
}
102103

103-
resource keyVault_secret 'Microsoft.KeyVault/vaults/secrets@2023-02-01' = if (!empty(storageAccountKey)) {
104-
name: keyVaultSecretName
105-
parent: keyVault
106-
properties: {
107-
attributes: {
108-
enabled: true
109-
exp: 1702648632
110-
nbf: 10000
111-
}
112-
value: storageAccountKey
104+
module keyVault_secret 'hub-vault.bicep' = if (!empty(storageAccountKey)) {
105+
name: 'keyVault_secret'
106+
params: {
107+
vaultName: keyVault.name
108+
secretName: keyVaultSecretName
109+
secretValue: storageAccountKey
110+
secretExpirationInSeconds: 1702648632
111+
secretNotBeforeInSeconds: 10000
113112
}
114113
}
115114

0 commit comments

Comments
 (0)