PUT https://management.azure.com/subscriptions/Subscription/resourceGroups/ResourceGroup/providers/Microsoft.EventHub/namespaces/sdk-Namespace-6019/networkRuleSets/default?api-version=2024-01-01
{
"properties": {
"defaultAction": "Deny",
"virtualNetworkRules": [
{
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"
},
"ignoreMissingVnetServiceEndpoint": true
},
{
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"
},
"ignoreMissingVnetServiceEndpoint": false
},
{
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"
},
"ignoreMissingVnetServiceEndpoint": false
}
],
"ipRules": [
{
"ipMask": "1.1.1.1",
"action": "Allow"
},
{
"ipMask": "1.1.1.2",
"action": "Allow"
},
{
"ipMask": "1.1.1.3",
"action": "Allow"
},
{
"ipMask": "1.1.1.4",
"action": "Allow"
},
{
"ipMask": "1.1.1.5",
"action": "Allow"
}
]
}
}
import com.azure.resourcemanager.eventhubs.fluent.models.NetworkRuleSetInner;
import com.azure.resourcemanager.eventhubs.models.DefaultAction;
import com.azure.resourcemanager.eventhubs.models.NWRuleSetIpRules;
import com.azure.resourcemanager.eventhubs.models.NWRuleSetVirtualNetworkRules;
import com.azure.resourcemanager.eventhubs.models.NetworkRuleIpAction;
import com.azure.resourcemanager.eventhubs.models.Subnet;
import java.util.Arrays;
/**
* Samples for Namespaces CreateOrUpdateNetworkRuleSet.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/eventhub/resource-manager/Microsoft.EventHub/stable/2024-01-01/examples/NameSpaces/
* VirtualNetworkRule/EHNetworkRuleSetCreate.json
*/
/**
* Sample code: NameSpaceNetworkRuleSetCreate.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void nameSpaceNetworkRuleSetCreate(com.azure.resourcemanager.AzureResourceManager azure) {
azure.eventHubs().manager().serviceClient().getNamespaces().createOrUpdateNetworkRuleSetWithResponse(
"ResourceGroup", "sdk-Namespace-6019",
new NetworkRuleSetInner().withDefaultAction(DefaultAction.DENY).withVirtualNetworkRules(Arrays.asList(
new NWRuleSetVirtualNetworkRules().withSubnet(new Subnet().withId(
"/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"))
.withIgnoreMissingVnetServiceEndpoint(true),
new NWRuleSetVirtualNetworkRules().withSubnet(new Subnet().withId(
"/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"))
.withIgnoreMissingVnetServiceEndpoint(false),
new NWRuleSetVirtualNetworkRules().withSubnet(new Subnet().withId(
"/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"))
.withIgnoreMissingVnetServiceEndpoint(false)))
.withIpRules(
Arrays.asList(new NWRuleSetIpRules().withIpMask("1.1.1.1").withAction(NetworkRuleIpAction.ALLOW),
new NWRuleSetIpRules().withIpMask("1.1.1.2").withAction(NetworkRuleIpAction.ALLOW),
new NWRuleSetIpRules().withIpMask("1.1.1.3").withAction(NetworkRuleIpAction.ALLOW),
new NWRuleSetIpRules().withIpMask("1.1.1.4").withAction(NetworkRuleIpAction.ALLOW),
new NWRuleSetIpRules().withIpMask("1.1.1.5").withAction(NetworkRuleIpAction.ALLOW))),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.eventhub import EventHubManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-eventhub
# USAGE
python eh_network_rule_set_create.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = EventHubManagementClient(
credential=DefaultAzureCredential(),
subscription_id="Subscription",
)
response = client.namespaces.create_or_update_network_rule_set(
resource_group_name="ResourceGroup",
namespace_name="sdk-Namespace-6019",
parameters={
"properties": {
"defaultAction": "Deny",
"ipRules": [
{"action": "Allow", "ipMask": "1.1.1.1"},
{"action": "Allow", "ipMask": "1.1.1.2"},
{"action": "Allow", "ipMask": "1.1.1.3"},
{"action": "Allow", "ipMask": "1.1.1.4"},
{"action": "Allow", "ipMask": "1.1.1.5"},
],
"virtualNetworkRules": [
{
"ignoreMissingVnetServiceEndpoint": True,
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"
},
},
{
"ignoreMissingVnetServiceEndpoint": False,
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"
},
},
{
"ignoreMissingVnetServiceEndpoint": False,
"subnet": {
"id": "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"
},
},
],
}
},
)
print(response)
# x-ms-original-file: specification/eventhub/resource-manager/Microsoft.EventHub/stable/2024-01-01/examples/NameSpaces/VirtualNetworkRule/EHNetworkRuleSetCreate.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armeventhub_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/eventhub/armeventhub"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/b574e2a41acda14a90ef237006e8bbdda2b63c63/specification/eventhub/resource-manager/Microsoft.EventHub/stable/2024-01-01/examples/NameSpaces/VirtualNetworkRule/EHNetworkRuleSetCreate.json
func ExampleNamespacesClient_CreateOrUpdateNetworkRuleSet() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armeventhub.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewNamespacesClient().CreateOrUpdateNetworkRuleSet(ctx, "ResourceGroup", "sdk-Namespace-6019", armeventhub.NetworkRuleSet{
Properties: &armeventhub.NetworkRuleSetProperties{
DefaultAction: to.Ptr(armeventhub.DefaultActionDeny),
IPRules: []*armeventhub.NWRuleSetIPRules{
{
Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
IPMask: to.Ptr("1.1.1.1"),
},
{
Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
IPMask: to.Ptr("1.1.1.2"),
},
{
Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
IPMask: to.Ptr("1.1.1.3"),
},
{
Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
IPMask: to.Ptr("1.1.1.4"),
},
{
Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
IPMask: to.Ptr("1.1.1.5"),
}},
VirtualNetworkRules: []*armeventhub.NWRuleSetVirtualNetworkRules{
{
IgnoreMissingVnetServiceEndpoint: to.Ptr(true),
Subnet: &armeventhub.Subnet{
ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"),
},
},
{
IgnoreMissingVnetServiceEndpoint: to.Ptr(false),
Subnet: &armeventhub.Subnet{
ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"),
},
},
{
IgnoreMissingVnetServiceEndpoint: to.Ptr(false),
Subnet: &armeventhub.Subnet{
ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"),
},
}},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.NetworkRuleSet = armeventhub.NetworkRuleSet{
// Name: to.Ptr("default"),
// Type: to.Ptr("Microsoft.EventHub/Namespaces/NetworkRuleSet"),
// ID: to.Ptr("/subscriptions/854d368f-1828-428f-8f3c-f2affa9b2f7d/resourceGroups/resourcegroupid/providers/Microsoft.EventHub/namespaces/sdk-Namespace-9659/networkruleset/default"),
// Properties: &armeventhub.NetworkRuleSetProperties{
// DefaultAction: to.Ptr(armeventhub.DefaultActionDeny),
// IPRules: []*armeventhub.NWRuleSetIPRules{
// {
// Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
// IPMask: to.Ptr("1.1.1.1"),
// },
// {
// Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
// IPMask: to.Ptr("1.1.1.2"),
// },
// {
// Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
// IPMask: to.Ptr("1.1.1.3"),
// },
// {
// Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
// IPMask: to.Ptr("1.1.1.4"),
// },
// {
// Action: to.Ptr(armeventhub.NetworkRuleIPActionAllow),
// IPMask: to.Ptr("1.1.1.5"),
// }},
// VirtualNetworkRules: []*armeventhub.NWRuleSetVirtualNetworkRules{
// {
// IgnoreMissingVnetServiceEndpoint: to.Ptr(true),
// Subnet: &armeventhub.Subnet{
// ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"),
// },
// },
// {
// IgnoreMissingVnetServiceEndpoint: to.Ptr(false),
// Subnet: &armeventhub.Subnet{
// ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"),
// },
// },
// {
// IgnoreMissingVnetServiceEndpoint: to.Ptr(false),
// Subnet: &armeventhub.Subnet{
// ID: to.Ptr("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"),
// },
// }},
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { EventHubManagementClient } = require("@azure/arm-eventhub");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update NetworkRuleSet for a Namespace.
*
* @summary Create or update NetworkRuleSet for a Namespace.
* x-ms-original-file: specification/eventhub/resource-manager/Microsoft.EventHub/stable/2024-01-01/examples/NameSpaces/VirtualNetworkRule/EHNetworkRuleSetCreate.json
*/
async function nameSpaceNetworkRuleSetCreate() {
const subscriptionId = process.env["EVENTHUB_SUBSCRIPTION_ID"] || "Subscription";
const resourceGroupName = process.env["EVENTHUB_RESOURCE_GROUP"] || "ResourceGroup";
const namespaceName = "sdk-Namespace-6019";
const parameters = {
defaultAction: "Deny",
ipRules: [
{ action: "Allow", ipMask: "1.1.1.1" },
{ action: "Allow", ipMask: "1.1.1.2" },
{ action: "Allow", ipMask: "1.1.1.3" },
{ action: "Allow", ipMask: "1.1.1.4" },
{ action: "Allow", ipMask: "1.1.1.5" },
],
virtualNetworkRules: [
{
ignoreMissingVnetServiceEndpoint: true,
subnet: {
id: "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2",
},
},
{
ignoreMissingVnetServiceEndpoint: false,
subnet: {
id: "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3",
},
},
{
ignoreMissingVnetServiceEndpoint: false,
subnet: {
id: "/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6",
},
},
],
};
const credential = new DefaultAzureCredential();
const client = new EventHubManagementClient(credential, subscriptionId);
const result = await client.namespaces.createOrUpdateNetworkRuleSet(
resourceGroupName,
namespaceName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.EventHubs.Models;
using Azure.ResourceManager.EventHubs;
// Generated from example definition: specification/eventhub/resource-manager/Microsoft.EventHub/stable/2024-01-01/examples/NameSpaces/VirtualNetworkRule/EHNetworkRuleSetCreate.json
// this example is just showing the usage of "Namespaces_CreateOrUpdateNetworkRuleSet" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this EventHubsNetworkRuleSetResource created on azure
// for more information of creating EventHubsNetworkRuleSetResource, please refer to the document of EventHubsNetworkRuleSetResource
string subscriptionId = "Subscription";
string resourceGroupName = "ResourceGroup";
string namespaceName = "sdk-Namespace-6019";
ResourceIdentifier eventHubsNetworkRuleSetResourceId = EventHubsNetworkRuleSetResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, namespaceName);
EventHubsNetworkRuleSetResource eventHubsNetworkRuleSet = client.GetEventHubsNetworkRuleSetResource(eventHubsNetworkRuleSetResourceId);
// invoke the operation
EventHubsNetworkRuleSetData data = new EventHubsNetworkRuleSetData()
{
DefaultAction = EventHubsNetworkRuleSetDefaultAction.Deny,
VirtualNetworkRules =
{
new EventHubsNetworkRuleSetVirtualNetworkRules()
{
SubnetId = new ResourceIdentifier("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet2"),
IgnoreMissingVnetServiceEndpoint = true,
},new EventHubsNetworkRuleSetVirtualNetworkRules()
{
SubnetId = new ResourceIdentifier("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet3"),
IgnoreMissingVnetServiceEndpoint = false,
},new EventHubsNetworkRuleSetVirtualNetworkRules()
{
SubnetId = new ResourceIdentifier("/subscriptions/subscriptionid/resourcegroups/resourcegroupid/providers/Microsoft.Network/virtualNetworks/myvn/subnets/subnet6"),
IgnoreMissingVnetServiceEndpoint = false,
}
},
IPRules =
{
new EventHubsNetworkRuleSetIPRules()
{
IPMask = "1.1.1.1",
Action = EventHubsNetworkRuleIPAction.Allow,
},new EventHubsNetworkRuleSetIPRules()
{
IPMask = "1.1.1.2",
Action = EventHubsNetworkRuleIPAction.Allow,
},new EventHubsNetworkRuleSetIPRules()
{
IPMask = "1.1.1.3",
Action = EventHubsNetworkRuleIPAction.Allow,
},new EventHubsNetworkRuleSetIPRules()
{
IPMask = "1.1.1.4",
Action = EventHubsNetworkRuleIPAction.Allow,
},new EventHubsNetworkRuleSetIPRules()
{
IPMask = "1.1.1.5",
Action = EventHubsNetworkRuleIPAction.Allow,
}
},
};
ArmOperation<EventHubsNetworkRuleSetResource> lro = await eventHubsNetworkRuleSet.CreateOrUpdateAsync(WaitUntil.Completed, data);
EventHubsNetworkRuleSetResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
EventHubsNetworkRuleSetData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue