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

Add search resource #42610

Merged
merged 5 commits into from
Mar 12, 2024
Merged
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
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<PackageReference Update="Azure.ResourceManager.PostgreSql" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Redis" Version="1.4.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Resources" Version="1.8.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Search" Version="1.3.0-alpha.20240311.4" />
<PackageReference Update="Azure.ResourceManager.ServiceBus" Version="1.1.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Sql" Version="1.3.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Storage" Version="1.3.0-alpha.20240310.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
public static Azure.Provisioning.Authorization.RoleDefinition AppConfigurationDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchIndexDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchServiceContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition ServiceBusDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageQueueDataContributor { get { throw null; } }
Expand Down Expand Up @@ -350,6 +352,15 @@ public partial class DeploymentScript : Azure.Provisioning.Resource<Azure.Resour
public static Azure.Provisioning.Resources.DeploymentScript FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
}
}
namespace Azure.Provisioning.Search
{
public partial class SearchService : Azure.Provisioning.Resource<Azure.ResourceManager.Search.SearchServiceData>
{
public SearchService(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Search.Models.SearchSkuName? sku = default(Azure.ResourceManager.Search.Models.SearchSkuName?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "search", string version = "2023-11-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.Search.SearchServiceData>)) { }
public static Azure.Provisioning.Search.SearchService FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.ServiceBus
{
public partial class ServiceBusNamespace : Azure.Provisioning.Resource<Azure.ResourceManager.ServiceBus.ServiceBusNamespaceData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
public static Azure.Provisioning.Authorization.RoleDefinition AppConfigurationDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchIndexDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition SearchServiceContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition ServiceBusDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageQueueDataContributor { get { throw null; } }
Expand Down Expand Up @@ -350,6 +352,15 @@ public partial class DeploymentScript : Azure.Provisioning.Resource<Azure.Resour
public static Azure.Provisioning.Resources.DeploymentScript FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
}
}
namespace Azure.Provisioning.Search
{
public partial class SearchService : Azure.Provisioning.Resource<Azure.ResourceManager.Search.SearchServiceData>
{
public SearchService(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.Search.Models.SearchSkuName? sku = default(Azure.ResourceManager.Search.Models.SearchSkuName?), Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "search", string version = "2023-11-01", Azure.Core.AzureLocation? location = default(Azure.Core.AzureLocation?)) : base (default(Azure.Provisioning.IConstruct), default(Azure.Provisioning.Resource), default(string), default(Azure.Core.ResourceType), default(string), default(System.Func<string, Azure.ResourceManager.Search.SearchServiceData>)) { }
public static Azure.Provisioning.Search.SearchService FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null) { throw null; }
protected override string GetAzureName(Azure.Provisioning.IConstruct scope, string resourceName) { throw null; }
}
}
namespace Azure.Provisioning.ServiceBus
{
public partial class ServiceBusNamespace : Azure.Provisioning.Resource<Azure.ResourceManager.ServiceBus.ServiceBusNamespaceData>
Expand Down
2 changes: 1 addition & 1 deletion sdk/provisioning/Azure.Provisioning/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "net",
"TagPrefix": "net/provisioning/Azure.Provisioning",
"Tag": "net/provisioning/Azure.Provisioning_2e6e26284c"
"Tag": "net/provisioning/Azure.Provisioning_b877da6a2b"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Azure.ResourceManager.CosmosDB" />
<PackageReference Include="Azure.ResourceManager.CognitiveServices" />
<PackageReference Include="Azure.ResourceManager.ServiceBus" />
<PackageReference Include="Azure.ResourceManager.Search" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public RoleDefinition(string value)
/// </summary>
public static RoleDefinition AppConfigurationDataOwner { get; } = new RoleDefinition("5ae67dd6-50cb-40e7-96ff-dc2bfa4b606b");

/// <summary>
/// Search service contributor role.
/// </summary>
public static RoleDefinition SearchServiceContributor { get; } = new RoleDefinition("7ca78c08-252a-4471-8644-bb5ff32d4ba0");

/// <summary>
/// Search index data contributor role.
/// </summary>
public static RoleDefinition SearchIndexDataContributor { get; } = new RoleDefinition("8ebe5a00-799e-43f5-93ac-243d3dce84a7");

/// <summary> Converts a string to a <see cref="RoleDefinition"/>. </summary>
public static implicit operator RoleDefinition(string value) => new RoleDefinition(value);

Expand Down
58 changes: 58 additions & 0 deletions sdk/provisioning/Azure.Provisioning/src/search/SearchService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core;
using Azure.Provisioning.Redis;
using Azure.Provisioning.ResourceManager;
using Azure.ResourceManager.Search;
using Azure.ResourceManager.Search.Models;

namespace Azure.Provisioning.Search
{
/// <summary>
/// Represents a search service resource.
/// </summary>
public class SearchService : Resource<SearchServiceData>
{
private const string ResourceTypeName = "Microsoft.Search/searchServices";
private static readonly Func<string, SearchServiceData> Empty = (name) => ArmSearchModelFactory.SearchServiceData();
internal const string DefaultVersion = "2023-11-01";

/// <summary>
/// Creates a new instance of the <see cref="SearchService"/> class.
/// </summary>
/// <param name="scope"></param>
/// <param name="sku"></param>
/// <param name="parent"></param>
/// <param name="name"></param>
/// <param name="version"></param>
/// <param name="location"></param>
public SearchService(IConstruct scope, SearchSkuName? sku = default, ResourceGroup? parent = default, string name = "search", string version = DefaultVersion, AzureLocation? location = default)
: this(scope, sku, parent, name, version, false, (name) => ArmSearchModelFactory.SearchServiceData(
name: name,
location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS,
skuName: sku ?? SearchSkuName.Basic))
{
AssignProperty(data => data.Name, GetAzureName(scope, name));
}

private SearchService(IConstruct scope, SearchSkuName? sku = default, ResourceGroup? parent = default, string name = "search", string version = DefaultVersion, bool isExisting = false, Func<string, SearchServiceData>? creator = null)
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="RedisCache"/> class referencing an existing instance.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="name">The resource name.</param>
/// <param name="parent">The resource group.</param>
/// <returns>The KeyVault instance.</returns>
public static SearchService FromExisting(IConstruct scope, string name, ResourceGroup? parent = null)
=> new SearchService(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
targetScope = 'resourceGroup'

@description('')
param location string = resourceGroup().location


resource searchService_cwdgn2HGu 'Microsoft.Search/searchServices@2023-11-01' = {
name: toLower(take(concat('search', uniqueString(resourceGroup().id)), 24))
location: location
sku: {
name: 'standard'
}
properties: {
replicaCount: 1
partitionCount: 1
hostingMode: 'default'
disableLocalAuth: true
}
}

resource roleAssignment_dcgUqp8kp 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: searchService_cwdgn2HGu
name: guid(searchService_cwdgn2HGu.id, '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7ca78c08-252a-4471-8644-bb5ff32d4ba0'))
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7ca78c08-252a-4471-8644-bb5ff32d4ba0')
principalId: '00000000-0000-0000-0000-000000000000'
principalType: 'ServicePrincipal'
}
}

resource roleAssignment_1CP5SnX3w 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
scope: searchService_cwdgn2HGu
name: guid(searchService_cwdgn2HGu.id, '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8ebe5a00-799e-43f5-93ac-243d3dce84a7'))
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8ebe5a00-799e-43f5-93ac-243d3dce84a7')
principalId: '00000000-0000-0000-0000-000000000000'
principalType: 'ServicePrincipal'
}
}

output connectionString string = 'Endpoint=https://${searchService_cwdgn2HGu.name}.search.windows.net'
20 changes: 20 additions & 0 deletions sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
using Azure.Provisioning.CosmosDB;
using Azure.Provisioning.PostgreSql;
using Azure.Provisioning.Redis;
using Azure.Provisioning.Search;
using Azure.Provisioning.ServiceBus;
using Azure.ResourceManager.Authorization.Models;
using Azure.ResourceManager.CognitiveServices.Models;
using Azure.ResourceManager.CosmosDB.Models;
using Azure.ResourceManager.PostgreSql.FlexibleServers.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Resources.Models;
using Azure.ResourceManager.Search.Models;
using Azure.ResourceManager.Storage.Models;
using Azure.ResourceManager.TestFramework;
using CoreTestEnvironment = Azure.Core.TestFramework.TestEnvironment;
Expand Down Expand Up @@ -384,6 +386,24 @@ public async Task ServiceBus()
await ValidateBicepAsync(interactiveMode: true);
}

[RecordedTest]
public async Task Search()
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
{
TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true });
var search = new SearchService(infrastructure, sku: SearchSkuName.Standard);
search.AssignRole(RoleDefinition.SearchServiceContributor, Guid.Empty);
search.AssignRole(RoleDefinition.SearchIndexDataContributor, Guid.Empty);
search.AssignProperty(data => data.ReplicaCount, "1");
search.AssignProperty(data => data.PartitionCount, "1");
search.AssignProperty(data => data.HostingMode, "'default'");
search.AssignProperty(data => data.IsLocalAuthDisabled, "true");

search.AddOutput("connectionString", "'Endpoint=https://${{{0}}}.search.windows.net'", data => data.Name);
infrastructure.Build(GetOutputPath());

await ValidateBicepAsync(interactiveMode: true);
}

[RecordedTest]
public async Task WebSiteUsingL2()
{
Expand Down