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 EventHubs resources #42636

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -135,6 +135,7 @@
<PackageReference Update="Azure.ResourceManager.Authorization" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.CognitiveServices" Version="1.4.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.CosmosDB" Version="1.4.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.EventHubs" Version="1.1.0-alpha.20240311.3" />
<PackageReference Update="Azure.ResourceManager.KeyVault" Version="1.3.0-alpha.20240310.2" />
<PackageReference Update="Azure.ResourceManager.PostgreSql" Version="1.2.0-alpha.20240309.1" />
<PackageReference Update="Azure.ResourceManager.Redis" Version="1.4.0-alpha.20240309.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
private readonly int _dummyPrimitive;
public RoleDefinition(string value) { throw null; }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition EventHubsDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition ServiceBusDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } }
Expand Down Expand Up @@ -252,6 +253,27 @@ public partial class CosmosDBSqlDatabase : Azure.Provisioning.Resource<Azure.Res
public static Azure.Provisioning.CosmosDB.CosmosDBSqlDatabase FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.CosmosDB.CosmosDBAccount parent) { throw null; }
}
}
namespace Azure.Provisioning.EventHubs
{
public partial class EventHub : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubData>)) { }
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<Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>)) { }
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<Azure.ResourceManager.EventHubs.EventHubsNamespaceData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubsNamespaceData>)) { }
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<Azure.ResourceManager.KeyVault.KeyVaultData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public partial class RoleAssignment : Azure.Provisioning.Resource<Azure.Resource
private readonly int _dummyPrimitive;
public RoleDefinition(string value) { throw null; }
public static Azure.Provisioning.Authorization.RoleDefinition CognitiveServicesOpenAIContributor { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition EventHubsDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition KeyVaultAdministrator { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition ServiceBusDataOwner { get { throw null; } }
public static Azure.Provisioning.Authorization.RoleDefinition StorageBlobDataContributor { get { throw null; } }
Expand Down Expand Up @@ -252,6 +253,27 @@ public partial class CosmosDBSqlDatabase : Azure.Provisioning.Resource<Azure.Res
public static Azure.Provisioning.CosmosDB.CosmosDBSqlDatabase FromExisting(Azure.Provisioning.IConstruct scope, string name, Azure.Provisioning.CosmosDB.CosmosDBAccount parent) { throw null; }
}
}
namespace Azure.Provisioning.EventHubs
{
public partial class EventHub : Azure.Provisioning.Resource<Azure.ResourceManager.EventHubs.EventHubData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubData>)) { }
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<Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubsConsumerGroupData>)) { }
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<Azure.ResourceManager.EventHubs.EventHubsNamespaceData>
{
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<string, Azure.ResourceManager.EventHubs.EventHubsNamespaceData>)) { }
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<Azure.ResourceManager.KeyVault.KeyVaultData>
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_a7f71bfdc6"
}
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.EventHubs" />
<PackageReference Include="System.ClientModel" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public RoleDefinition(string value)
/// </summary>
public static RoleDefinition ServiceBusDataOwner { get; } = new RoleDefinition("090c5cfd-751d-490a-894a-3ce6f1109419");

/// <summary>
/// Event Hubs data owner role.
/// </summary>
public static RoleDefinition EventHubsDataOwner { get; } = new RoleDefinition("f526a384-b230-433a-b45c-95f59c4a2dec");

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

Expand Down
56 changes: 56 additions & 0 deletions sdk/provisioning/Azure.Provisioning/src/eventhubs/EventHub.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an Event Hub.
/// </summary>
public class EventHub : Resource<EventHubData>
{
private const string ResourceTypeName = "Microsoft.EventHub/namespaces/eventhubs";
private static readonly Func<string, EventHubData> Empty = (name) => ArmEventHubsModelFactory.EventHubData();

/// <summary>
/// Initializes a new instance of the <see cref="EventHub"/>.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="parent">The parent.</param>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <param name="location">The location.</param>
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<string, EventHubData>? creator = null)
: base(scope, parent, name, ResourceTypeName, EventHubsNamespace.DefaultVersion, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="EventHub"/> 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 EventHub FromExisting(IConstruct scope, string name, EventHubsNamespace parent)
=> new EventHub(scope, parent: parent, name: name, isExisting: true);

/// <inheritdoc/>
protected override Resource? FindParentInScope(IConstruct scope)
{
return scope.GetSingleResource<EventHubsNamespace>() ?? new EventHubsNamespace(scope);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Represents an EventHubsNamespace.
/// </summary>
public class EventHubsNamespace : Resource<EventHubsNamespaceData>
{
private const string ResourceTypeName = "Microsoft.EventHub/namespaces";
private static readonly Func<string, EventHubsNamespaceData> Empty = (name) => ArmEventHubsModelFactory.EventHubsNamespaceData();
internal const string DefaultVersion = "2021-11-01";

/// <summary>
/// Initializes a new instance of the <see cref="EventHubsNamespace"/>.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="sku">The sku.</param>
/// <param name="parent">The parent.</param>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
/// <param name="location">The location.</param>
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<string, EventHubsNamespaceData>? creator = null)
: base(scope, parent, name, ResourceTypeName, version, creator ?? Empty, isExisting)
{
}

/// <summary>
/// Creates a new instance of the <see cref="EventHubsNamespace"/> 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 EventHubsNamespace FromExisting(IConstruct scope, string name, ResourceGroup? parent = null)
=> new EventHubsNamespace(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,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'
}
}
14 changes: 14 additions & 0 deletions sdk/provisioning/Azure.Provisioning/tests/ProvisioningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.ServiceBus;
Expand Down Expand Up @@ -384,6 +385,19 @@ public async Task ServiceBus()
await ValidateBicepAsync(interactiveMode: true);
}

[RecordedTest]
public async Task EventHubs()
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
{
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 WebSiteUsingL2()
{
Expand Down