diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 2745b06d32ad9..f877867e7dfa1 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -135,6 +135,7 @@ + diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs index 5b126a9da8dcf..208632baf28f2 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.net6.0.cs @@ -186,6 +186,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource + { + public EventHub(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHubsNamespace? parent = null, string name = "hub", string version = "2021-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)) { } + protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + public static Azure.Provisioning.EventHubs.EventHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHubsNamespace parent) { throw null; } + } + public partial class EventHubsConsumerGroup : Azure.Provisioning.Resource + { + public EventHubsConsumerGroup(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHub? parent = null, string name = "hub", string version = "2021-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)) { } + protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + public static Azure.Provisioning.EventHubs.EventHubsConsumerGroup FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHub parent) { throw null; } + } + public partial class EventHubsNamespace : Azure.Provisioning.Resource + { + public EventHubsNamespace(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.EventHubs.Models.EventHubsSku? sku = null, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "eh", string version = "2021-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)) { } + public static Azure.Provisioning.EventHubs.EventHubsNamespace 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.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource diff --git a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs index 5b126a9da8dcf..208632baf28f2 100644 --- a/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs +++ b/sdk/provisioning/Azure.Provisioning/api/Azure.Provisioning.netstandard2.0.cs @@ -186,6 +186,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource + { + public EventHub(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHubsNamespace? parent = null, string name = "hub", string version = "2021-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)) { } + protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + public static Azure.Provisioning.EventHubs.EventHub FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHubsNamespace parent) { throw null; } + } + public partial class EventHubsConsumerGroup : Azure.Provisioning.Resource + { + public EventHubsConsumerGroup(Azure.Provisioning.IConstruct scope, Azure.Provisioning.EventHubs.EventHub? parent = null, string name = "hub", string version = "2021-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)) { } + protected override Azure.Provisioning.Resource? FindParentInScope(Azure.Provisioning.IConstruct scope) { throw null; } + public static Azure.Provisioning.EventHubs.EventHubsConsumerGroup FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.EventHubs.EventHub parent) { throw null; } + } + public partial class EventHubsNamespace : Azure.Provisioning.Resource + { + public EventHubsNamespace(Azure.Provisioning.IConstruct scope, Azure.ResourceManager.EventHubs.Models.EventHubsSku? sku = null, Azure.Provisioning.ResourceManager.ResourceGroup? parent = null, string name = "eh", string version = "2021-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)) { } + public static Azure.Provisioning.EventHubs.EventHubsNamespace 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.KeyVaults { public partial class KeyVault : Azure.Provisioning.Resource diff --git a/sdk/provisioning/Azure.Provisioning/assets.json b/sdk/provisioning/Azure.Provisioning/assets.json index 26812293b8320..2c2bec94c584b 100644 --- a/sdk/provisioning/Azure.Provisioning/assets.json +++ b/sdk/provisioning/Azure.Provisioning/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/provisioning/Azure.Provisioning", - "Tag": "net/provisioning/Azure.Provisioning_b877da6a2b" + "Tag": "net/provisioning/Azure.Provisioning_a7f71bfdc6" } \ No newline at end of file diff --git a/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj b/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj index 9cb64328a4134..f09c67408f2dc 100644 --- a/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj +++ b/sdk/provisioning/Azure.Provisioning/src/Azure.Provisioning.csproj @@ -23,6 +23,7 @@ + diff --git a/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs index 2fe41bf6ef8a6..9bdcf3e069092 100644 --- a/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs +++ b/sdk/provisioning/Azure.Provisioning/src/authorization/RoleDefinition.cs @@ -48,6 +48,11 @@ public RoleDefinition(string value) /// public static RoleDefinition ServiceBusDataOwner { get; } = new RoleDefinition("090c5cfd-751d-490a-894a-3ce6f1109419"); + /// + /// Event Hubs data owner role. + /// + public static RoleDefinition EventHubsDataOwner { get; } = new RoleDefinition("f526a384-b230-433a-b45c-95f59c4a2dec"); + /// /// App configuration data owner role. /// diff --git a/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHub.cs b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHub.cs new file mode 100644 index 0000000000000..8cf79f3345a82 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHub.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.ResourceManager.EventHubs; +using Azure.ResourceManager.EventHubs.Models; + +namespace Azure.Provisioning.EventHubs +{ + /// + /// Represents an Event Hub. + /// + public class EventHub : Resource + { + private const string ResourceTypeName = "Microsoft.EventHub/namespaces/eventhubs"; + private static readonly Func Empty = (name) => ArmEventHubsModelFactory.EventHubData(); + + /// + /// Initializes a new instance of the . + /// + /// The scope. + /// The parent. + /// The name. + /// The version. + /// The location. + public EventHub(IConstruct scope, EventHubsNamespace? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, AzureLocation? location = default) + : this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubData( + name: name, + resourceType: ResourceTypeName, + location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) + { + } + + private EventHub(IConstruct scope, EventHubsNamespace? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, bool isExisting = true, Func? creator = null) + : base(scope, parent, name, ResourceTypeName, EventHubsNamespace.DefaultVersion, creator ?? Empty, isExisting) + { + } + + /// + /// Creates a new instance of the class referencing an existing instance. + /// + /// The scope. + /// The resource name. + /// The resource group. + /// The KeyVault instance. + public static EventHub FromExisting(IConstruct scope, string name, EventHubsNamespace parent) + => new EventHub(scope, parent: parent, name: name, isExisting: true); + + /// + protected override Resource? FindParentInScope(IConstruct scope) + { + return scope.GetSingleResource() ?? new EventHubsNamespace(scope); + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsConsumerGroup.cs b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsConsumerGroup.cs new file mode 100644 index 0000000000000..269b0cafafde6 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsConsumerGroup.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.ResourceManager.EventHubs; +using Azure.ResourceManager.EventHubs.Models; + +namespace Azure.Provisioning.EventHubs +{ + /// + /// Represents an Event Hub consumer group. + /// + public class EventHubsConsumerGroup : Resource + { + private const string ResourceTypeName = "Microsoft.EventHub/namespaces/eventhubs/consumergroups"; + private static readonly Func Empty = (name) => ArmEventHubsModelFactory.EventHubsConsumerGroupData(); + + /// + /// Initializes a new instance of the . + /// + /// The scope. + /// The parent. + /// The name. + /// The version. + /// The location. + public EventHubsConsumerGroup(IConstruct scope, EventHub? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, AzureLocation? location = default) + : this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubsConsumerGroupData( + name: name, + resourceType: ResourceTypeName, + location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS)) + { + } + + private EventHubsConsumerGroup(IConstruct scope, EventHub? parent = null, string name = "hub", string version = EventHubsNamespace.DefaultVersion, bool isExisting = true, Func? creator = null) + : base(scope, parent, name, ResourceTypeName, EventHubsNamespace.DefaultVersion, creator ?? Empty, isExisting) + { + } + + /// + /// Creates a new instance of the class referencing an existing instance. + /// + /// The scope. + /// The resource name. + /// The resource group. + /// The KeyVault instance. + public static EventHubsConsumerGroup FromExisting(IConstruct scope, string name, EventHub parent) + => new EventHubsConsumerGroup(scope, parent: parent, name: name, isExisting: true); + + /// + protected override Resource? FindParentInScope(IConstruct scope) + { + return scope.GetSingleResource() ?? new EventHub(scope); + } + } +} diff --git a/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsNamespace.cs b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsNamespace.cs new file mode 100644 index 0000000000000..dd236c76beeb2 --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHubsNamespace.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using Azure.Core; +using Azure.Provisioning.ResourceManager; +using Azure.ResourceManager.EventHubs; +using Azure.ResourceManager.EventHubs.Models; + +namespace Azure.Provisioning.EventHubs +{ + /// + /// Represents an EventHubsNamespace. + /// + public class EventHubsNamespace : Resource + { + private const string ResourceTypeName = "Microsoft.EventHub/namespaces"; + private static readonly Func Empty = (name) => ArmEventHubsModelFactory.EventHubsNamespaceData(); + internal const string DefaultVersion = "2021-11-01"; + + /// + /// Initializes a new instance of the . + /// + /// The scope. + /// The sku. + /// The parent. + /// The name. + /// The version. + /// The location. + public EventHubsNamespace(IConstruct scope, EventHubsSku? sku = default, ResourceGroup? parent = null, string name = "eh", string version = DefaultVersion, AzureLocation? location = default) + : this(scope, parent, name, version, false, (name) => ArmEventHubsModelFactory.EventHubsNamespaceData( + name: name, + resourceType: ResourceTypeName, + location: location ?? Environment.GetEnvironmentVariable("AZURE_LOCATION") ?? AzureLocation.WestUS, + sku: sku ?? new EventHubsSku(EventHubsSkuName.Standard), + minimumTlsVersion: EventHubsTlsVersion.Tls1_2)) + { + AssignProperty(data => data.Name, GetAzureName(scope, name)); + } + + private EventHubsNamespace(IConstruct scope, ResourceGroup? parent = null, string name = "eh", string version = DefaultVersion, bool isExisting = true, Func? creator = null) + : base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting) + { + } + + /// + /// Creates a new instance of the class referencing an existing instance. + /// + /// The scope. + /// The resource name. + /// The resource group. + /// The KeyVault instance. + public static EventHubsNamespace FromExisting(IConstruct scope, string name, ResourceGroup? parent = null) + => new EventHubsNamespace(scope, parent: parent, name: name, isExisting: true); + + /// + protected override string GetAzureName(IConstruct scope, string resourceName) => GetGloballyUniqueName(resourceName); + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/EventHubs/main.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/EventHubs/main.bicep new file mode 100644 index 0000000000000..94011544d227a --- /dev/null +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/EventHubs/main.bicep @@ -0,0 +1,42 @@ +targetScope = 'resourceGroup' + +@description('') +param location string = resourceGroup().location + + +resource eventHubsNamespace_LmeDkjUWO 'Microsoft.EventHub/namespaces@2021-11-01' = { + name: toLower(take(concat('eh', uniqueString(resourceGroup().id)), 24)) + location: location + sku: { + name: 'Standard' + } + properties: { + minimumTlsVersion: '1.2' + } +} + +resource eventHub_ELtptvi1s 'Microsoft.EventHub/namespaces/eventhubs@2021-11-01' = { + parent: eventHubsNamespace_LmeDkjUWO + name: 'hub' + location: location + properties: { + } +} + +resource eventHubConsumerGroup_gMkCNeWuK 'Microsoft.EventHub/namespaces/eventhubs/consumergroups@2021-11-01' = { + parent: eventHub_ELtptvi1s + name: 'hub' + location: location + properties: { + } +} + +resource roleAssignment_oj7e7rOUf 'Microsoft.Authorization/roleAssignments@2022-04-01' = { + scope: eventHubsNamespace_LmeDkjUWO + name: guid(eventHubsNamespace_LmeDkjUWO.id, '00000000-0000-0000-0000-000000000000', subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'f526a384-b230-433a-b45c-95f59c4a2dec')) + properties: { + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'f526a384-b230-433a-b45c-95f59c4a2dec') + principalId: '00000000-0000-0000-0000-000000000000' + principalType: 'ServicePrincipal' + } +} diff --git a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ExistingResources/resources/rg_TEST_module/rg_TEST_module.bicep b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ExistingResources/resources/rg_TEST_module/rg_TEST_module.bicep index 1442b84aacec2..433a03d8d550a 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ExistingResources/resources/rg_TEST_module/rg_TEST_module.bicep +++ b/sdk/provisioning/Azure.Provisioning/tests/Infrastructure/ExistingResources/resources/rg_TEST_module/rg_TEST_module.bicep @@ -73,6 +73,38 @@ resource appServicePlan_D5p3EVvRT 'Microsoft.Web/serverfarms@2021-02-01' existin name: 'existingAppServicePlan' } +resource serviceBusNamespace_0J6N7TWQp 'Microsoft.ServiceBus/namespaces@2021-11-01' existing = { + name: 'existingSbNamespace' +} + +resource serviceBusQueue_YWGfZ7Jp4 'Microsoft.ServiceBus/namespaces/queues@2021-11-01' existing = { + name: '${serviceBusNamespace_0J6N7TWQp}/existingSbQueue' +} + +resource serviceBusTopic_xubvxdBtk 'Microsoft.ServiceBus/namespaces/topics@2021-11-01' existing = { + name: '${serviceBusNamespace_0J6N7TWQp}/existingSbTopic' +} + +resource serviceBusSubscription_EnDkO3Vba 'Microsoft.ServiceBus/namespaces/topics/subscriptions@2021-11-01' existing = { + name: '${serviceBusTopic_xubvxdBtk}/existingSbSubscription' +} + +resource searchService_Szsp3FYvd 'Microsoft.Search/searchServices@2023-11-01' existing = { + name: 'existingSearch' +} + +resource eventHubsNamespace_dQTmc5DUS 'Microsoft.EventHub/namespaces@2021-11-01' existing = { + name: 'existingEhNamespace' +} + +resource eventHub_H6DI0xDvi 'Microsoft.EventHub/namespaces/eventhubs@2021-11-01' existing = { + name: '${eventHubsNamespace_dQTmc5DUS}/existingHub' +} + +resource eventHubsConsumerGroup_YKe70TLwz 'Microsoft.EventHub/namespaces/eventhubs/consumergroups@2021-11-01' existing = { + name: '${eventHub_H6DI0xDvi}/existingEhConsumerGroup' +} + resource applicationSettingsResource_6DtpuGITF 'Microsoft.Web/sites/config@2021-02-01' = { parent: webSite_C2Aq73IJb name: 'appsettings' diff --git a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs index 078c9d99560d8..82035563f6922 100644 --- a/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs +++ b/sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs @@ -20,6 +20,7 @@ using Azure.Provisioning.Authorization; using Azure.Provisioning.CognitiveServices; using Azure.Provisioning.CosmosDB; +using Azure.Provisioning.EventHubs; using Azure.Provisioning.PostgreSql; using Azure.Provisioning.Redis; using Azure.Provisioning.Search; @@ -386,6 +387,19 @@ public async Task ServiceBus() await ValidateBicepAsync(interactiveMode: true); } + [RecordedTest] + public async Task EventHubs() + { + TestInfrastructure infrastructure = new TestInfrastructure(configuration: new Configuration { UseInteractiveMode = true }); + var account = new EventHubsNamespace(infrastructure); + var hub = new EventHub(infrastructure, parent: account); + var consumerGroup = new EventHubsConsumerGroup(infrastructure, parent: hub); + account.AssignRole(RoleDefinition.EventHubsDataOwner, Guid.Empty); + infrastructure.Build(GetOutputPath()); + + await ValidateBicepAsync(interactiveMode: true); + } + [RecordedTest] public async Task Search() { @@ -723,6 +737,19 @@ public async Task ExistingResources() infra.AddResource(WebSiteConfigLogs.FromExisting(infra, "'existingWebSiteConfigLogs'", web)); infra.AddResource(WebSitePublishingCredentialPolicy.FromExisting(infra, "'existingWebSitePublishingCredentialPolicy'", web)); + var sb = ServiceBusNamespace.FromExisting(infra, "'existingSbNamespace'", rg); + infra.AddResource(ServiceBusQueue.FromExisting(infra, "'existingSbQueue'", sb)); + var topic = ServiceBusTopic.FromExisting(infra, "'existingSbTopic'", sb); + infra.AddResource(topic); + infra.AddResource(ServiceBusSubscription.FromExisting(infra, "'existingSbSubscription'", topic)); + + infra.AddResource(SearchService.FromExisting(infra, "'existingSearch'", rg)); + + var eh = EventHubsNamespace.FromExisting(infra, "'existingEhNamespace'", rg); + var hub = EventHub.FromExisting(infra, "'existingHub'", eh); + infra.AddResource(hub); + infra.AddResource(EventHubsConsumerGroup.FromExisting(infra, "'existingEhConsumerGroup'", hub)); + infra.Build(GetOutputPath()); await ValidateBicepAsync(BinaryData.FromObjectAsJson(