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

fix: Add key vault to search service - avm/res/search/search-service #1950

Merged
merged 38 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
764b13b
aisearchservice with adminkeys in keyvault
May 16, 2024
780d080
Merge branch 'Azure:main' into Aisearch_w_keyvault
mortenvpschmidt May 16, 2024
e4e0366
AISearchService with adminkeys in keyvault
May 16, 2024
59843fa
AiSearchService with AdminKeys in Keyvault
May 16, 2024
2c71c35
AiSearchService with AdminKeys in Keyvault
May 16, 2024
72e0aaf
Typo in main.test.bicep
May 16, 2024
6f92af0
Typo in main.test.bicep
May 16, 2024
46ba068
Revert "AISearchService with adminkeys in keyvault undo recurse"
May 17, 2024
4859142
Merge branch 'Azure:main' into Aisearch_w_keyvault
mortenvpschmidt May 17, 2024
0d4bc4f
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 14, 2024
46f0179
Updated to Secrets export
Agazoth Aug 14, 2024
2bc93c3
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 16, 2024
3044eaf
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 21, 2024
e8c43fe
Key valul exists bump name
Agazoth Aug 21, 2024
8e6f4ed
Added telemetry fix
Agazoth Aug 21, 2024
af24958
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 22, 2024
588b56b
Ran Set-AVMModule
Agazoth Aug 22, 2024
968329d
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Aug 22, 2024
386c182
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Sep 27, 2024
4475920
Short changed as agreed
Agazoth Sep 27, 2024
35f4820
Merge branch 'Aisearch_w_keyvault' of https://github.com/mortenvpschm…
Agazoth Sep 27, 2024
751c5ee
Fix readme bug
Agazoth Sep 27, 2024
157acfc
Merge branch 'main' into Aisearch_w_keyvault
eriqua Sep 29, 2024
726d5f8
Updated according to comment
Agazoth Sep 30, 2024
4b04e67
Updated according to comment
Agazoth Sep 30, 2024
bc2e35f
Readme updated
Agazoth Sep 30, 2024
9e0e703
Readme updated
Agazoth Sep 30, 2024
b78353c
fixed main.json
Agazoth Sep 30, 2024
61db651
Fixed the other readme
Agazoth Sep 30, 2024
9ebc1b0
Merge branch 'main' into Aisearch_w_keyvault
Agazoth Oct 1, 2024
b2b9bf7
Fixed Readme manually
Agazoth Oct 1, 2024
2dbe17a
Updated readme manually
Agazoth Oct 1, 2024
efc4b8a
Casing and plural manually updated
Agazoth Oct 1, 2024
b97485a
Strange place to camelCase - fixed manually
Agazoth Oct 1, 2024
5c921d9
A linebreak seems to be missing
Agazoth Oct 1, 2024
d0a875a
Too many linebreaks ...
Agazoth Oct 1, 2024
c21bb21
Added a linebreak
Agazoth Oct 1, 2024
945c1ed
More camelCase
Agazoth Oct 1, 2024
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
138 changes: 129 additions & 9 deletions avm/res/search/search-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This module deploys a Search Service.
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) |
| `Microsoft.KeyVault/vaults/secrets` | [2023-07-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.KeyVault/2023-07-01/vaults/secrets) |
| `Microsoft.Network/privateEndpoints` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-11-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-11-01/privateEndpoints/privateDnsZoneGroups) |
| `Microsoft.Search/searchServices` | [2024-03-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Search/2024-03-01-preview/searchServices) |
Expand All @@ -32,9 +33,10 @@ The following section provides usage examples for the module, which were used to
>**Note**: To reference the module, please use the following syntax `br/public:avm/res/search/search-service:<version>`.

- [Using only defaults](#example-1-using-only-defaults)
- [Using large parameter set](#example-2-using-large-parameter-set)
- [Private endpoint-enabled deployment](#example-3-private-endpoint-enabled-deployment)
- [WAF-aligned](#example-4-waf-aligned)
- [Deploying with a key vault reference to save secrets](#example-2-deploying-with-a-key-vault-reference-to-save-secrets)
- [Using large parameter set](#example-3-using-large-parameter-set)
- [Private endpoint-enabled deployment](#example-4-private-endpoint-enabled-deployment)
- [WAF-aligned](#example-5-waf-aligned)

### Example 1: _Using only defaults_

Expand Down Expand Up @@ -84,7 +86,83 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
</details>
<p>

### Example 2: _Using large parameter set_
### Example 2: _Deploying with a key vault reference to save secrets_

This instance deploys the module saving admin key secrets in a key vault.


<details>

<summary>via Bicep module</summary>

```bicep
module searchService 'br/public:avm/res/search/search-service:<version>' = {
name: 'searchServiceDeployment'
params: {
// Required parameters
name: 'kv-ref'
// Non-required parameters
authOptions: {
aadOrApiKey: {
aadAuthFailureMode: 'http401WithBearerChallenge'
}
}
disableLocalAuth: false
location: '<location>'
secretsExportConfiguration: {
keyVaultResourceId: '<keyVaultResourceId>'
primaryAdminKeyName: 'Primary-Admin-Key'
secondaryAdminKeyName: 'Secondary-Admin-Key'
}
}
}
```

</details>
<p>

<details>

<summary>via JSON Parameter file</summary>

```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"name": {
"value": "kv-ref"
},
// Non-required parameters
"authOptions": {
"value": {
"aadOrApiKey": {
"aadAuthFailureMode": "http401WithBearerChallenge"
}
}
},
"disableLocalAuth": {
"value": false
},
"location": {
"value": "<location>"
},
"secretsExportConfiguration": {
"value": {
"keyVaultResourceId": "<keyVaultResourceId>",
"primaryAdminKeyName": "Primary-Admin-Key",
"secondaryAdminKeyName": "Secondary-Admin-Key"
}
}
}
}
```

</details>
<p>

### Example 3: _Using large parameter set_

This instance deploys the module with most of its features enabled.

Expand Down Expand Up @@ -300,7 +378,7 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
</details>
<p>

### Example 3: _Private endpoint-enabled deployment_
### Example 4: _Private endpoint-enabled deployment_

This instance deploys the module with private endpoints.

Expand All @@ -314,7 +392,7 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
name: 'searchServiceDeployment'
params: {
// Required parameters
name: 'ssspe001'
name: 'ssspr001'
// Non-required parameters
location: '<location>'
privateEndpoints: [
Expand Down Expand Up @@ -383,7 +461,7 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
"parameters": {
// Required parameters
"name": {
"value": "ssspe001"
"value": "ssspr001"
},
// Non-required parameters
"location": {
Expand Down Expand Up @@ -452,7 +530,7 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
</details>
<p>

### Example 4: _WAF-aligned_
### Example 5: _WAF-aligned_

This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.

Expand Down Expand Up @@ -645,6 +723,7 @@ module searchService 'br/public:avm/res/search/search-service:<version>' = {
| [`publicNetworkAccess`](#parameter-publicnetworkaccess) | string | This value can be set to 'Enabled' to avoid breaking changes on existing customer resources and templates. If set to 'Disabled', traffic over public interface is not allowed, and private endpoint connections would be the exclusive access method. |
| [`replicaCount`](#parameter-replicacount) | int | The number of replicas in the search service. If specified, it must be a value between 1 and 12 inclusive for standard SKUs or between 1 and 3 inclusive for basic SKU. |
| [`roleAssignments`](#parameter-roleassignments) | array | Array of role assignments to create. |
| [`secretsExportConfiguration`](#parameter-secretsexportconfiguration) | object | Key vault reference and secret settings for the module's secrets export. |
| [`semanticSearch`](#parameter-semanticsearch) | string | Sets options that control the availability of semantic search. This configuration is only possible for certain search SKUs in certain locations. |
| [`sharedPrivateLinkResources`](#parameter-sharedprivatelinkresources) | array | The sharedPrivateLinkResources to create as part of the search Service. |
| [`sku`](#parameter-sku) | string | Defines the SKU of an Azure Cognitive Search Service, which determines price tier and capacity limits. |
Expand Down Expand Up @@ -1481,6 +1560,47 @@ The principal type of the assigned principal ID.
]
```

### Parameter: `secretsExportConfiguration`

Key vault reference and secret settings for the module's secrets export.

- Required: No
- Type: object

**Required parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`keyVaultResourceId`](#parameter-secretsexportconfigurationkeyvaultresourceid) | string | The key vault name where to store the API Admin keys generated by the modules. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`primaryAdminKeyName`](#parameter-secretsexportconfigurationprimaryadminkeyname) | string | The primaryAdminKey secret name to create. |
| [`secondaryAdminKeyName`](#parameter-secretsexportconfigurationsecondaryadminkeyname) | string | The secondaryAdminKey secret name to create. |

### Parameter: `secretsExportConfiguration.keyVaultResourceId`

The key vault name where to store the API Admin keys generated by the modules.

- Required: Yes
- Type: string

### Parameter: `secretsExportConfiguration.primaryAdminKeyName`

The primaryAdminKey secret name to create.

- Required: No
- Type: string

### Parameter: `secretsExportConfiguration.secondaryAdminKeyName`

The secondaryAdminKey secret name to create.

- Required: No
- Type: string

### Parameter: `semanticSearch`

Sets options that control the availability of semantic search. This configuration is only possible for certain search SKUs in certain locations.
Expand Down Expand Up @@ -1535,9 +1655,9 @@ Tags to help categorize the resource in the Azure portal.

| Output | Type | Description |
| :-- | :-- | :-- |
| `exportedSecrets` | | A hashtable of references to the secrets exported to the provided Key Vault. The key of each reference is each secret's name. |
| `location` | string | The location the resource was deployed into. |
| `name` | string | The name of the search service. |
| `privateEndpoints` | array | The private endpoints of the search service. |
| `resourceGroupName` | string | The name of the resource group the search service was created in. |
| `resourceId` | string | The resource ID of the search service. |
| `systemAssignedMIPrincipalId` | string | The principal ID of the system assigned identity. |
Expand Down
64 changes: 54 additions & 10 deletions avm/res/search/search-service/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ param sharedPrivateLinkResources array = []
])
param publicNetworkAccess string = 'Enabled'

@description('Optional. Key vault reference and secret settings for the module\'s secrets export.')
param secretsExportConfiguration secretsExportConfigurationType?

@description('Optional. The number of replicas in the search service. If specified, it must be a value between 1 and 12 inclusive for standard SKUs or between 1 and 3 inclusive for basic SKU.')
@minValue(1)
@maxValue(12)
Expand Down Expand Up @@ -324,6 +327,36 @@ module searchService_sharedPrivateLinkResources 'shared-private-link-resource/ma
}
]

module secretsExport 'modules/keyVaultExport.bicep' = if (secretsExportConfiguration != null) {
name: '${uniqueString(deployment().name, location)}-secrets-kv'
scope: resourceGroup(
split((secretsExportConfiguration.?keyVaultResourceId ?? '//'), '/')[2],
split((secretsExportConfiguration.?keyVaultResourceId ?? '////'), '/')[4]
)
params: {
keyVaultName: last(split(secretsExportConfiguration.?keyVaultResourceId ?? '//', '/'))
secretsToSet: union(
[],
contains(secretsExportConfiguration!, 'primaryAdminKeyName')
? [
{
name: secretsExportConfiguration!.primaryAdminKeyName
value: searchService.listAdminKeys().primaryKey
}
]
: [],
contains(secretsExportConfiguration!, 'secondaryAdminKeyName')
? [
{
name: secretsExportConfiguration!.secondaryAdminKeyName
value: searchService.listAdminKeys().secondaryKey
}
]
: []
)
}
}

// =========== //
// Outputs //
// =========== //
Expand All @@ -343,16 +376,10 @@ output systemAssignedMIPrincipalId string = searchService.?identity.?principalId
@description('The location the resource was deployed into.')
output location string = searchService.location

@description('The private endpoints of the search service.')
output privateEndpoints array = [
for (pe, i) in (!empty(privateEndpoints) ? array(privateEndpoints) : []): {
name: searchService_privateEndpoints[i].outputs.name
resourceId: searchService_privateEndpoints[i].outputs.resourceId
groupId: searchService_privateEndpoints[i].outputs.groupId
customDnsConfig: searchService_privateEndpoints[i].outputs.customDnsConfig
networkInterfaceIds: searchService_privateEndpoints[i].outputs.networkInterfaceIds
}
]
@description('A hashtable of references to the secrets exported to the provided Key Vault. The key of each reference is each secret\'s name.')
output exportedSecrets secretsOutputType = (secretsExportConfiguration != null)
? toObject(secretsExport.outputs.secretsSet, secret => last(split(secret.secretResourceId, '/')), secret => secret)
: {}

// =============== //
// Definitions //
Expand Down Expand Up @@ -530,3 +557,20 @@ type diagnosticSettingType = {
@description('Optional. The full ARM resource ID of the Marketplace resource to which you would like to send Diagnostic Logs.')
marketplacePartnerResourceId: string?
}[]?

type secretsExportConfigurationType = {
@description('Required. The key vault name where to store the API Admin keys generated by the modules.')
keyVaultResourceId: string

@description('Optional. The primaryAdminKey secret name to create.')
primaryAdminKeyName: string?

@description('Optional. The secondaryAdminKey secret name to create.')
secondaryAdminKeyName: string?
}

import { secretSetType } from 'modules/keyVaultExport.bicep'
type secretsOutputType = {
@description('An exported secret\'s references.')
*: secretSetType
}
Loading