From 9c4277f07708c41bb3939063e511d9d15e2d230a Mon Sep 17 00:00:00 2001 From: Rodge Fu Date: Sat, 8 Jul 2023 21:19:00 +0800 Subject: [PATCH 1/2] add sample --- .../Azure.ResourceManager.sln | 6 + .../Azure.ResourceManager.Samples.csproj | 10 + .../samples/autorest.tests.md | 13 + .../Sample_DataPolicyManifestCollection.cs | 144 +++ .../Sample_DataPolicyManifestResource.cs | 48 + .../Samples/Sample_FeatureCollection.cs | 119 +++ .../Samples/Sample_FeatureResource.cs | 112 +++ .../Sample_ManagementGroupCollection.cs | 441 +++++++++ ...nagementGroupPolicyDefinitionCollection.cs | 200 ++++ ...ManagementGroupPolicyDefinitionResource.cs | 155 ++++ ...ementGroupPolicySetDefinitionCollection.cs | 282 ++++++ ...agementGroupPolicySetDefinitionResource.cs | 234 +++++ .../Samples/Sample_ManagementGroupResource.cs | 265 ++++++ .../Sample_ManagementLockCollection.cs | 149 +++ .../Samples/Sample_ManagementLockResource.cs | 109 +++ .../Sample_PolicyAssignmentCollection.cs | 872 ++++++++++++++++++ .../Sample_PolicyAssignmentResource.cs | 382 ++++++++ .../Samples/Sample_ResourceGroupCollection.cs | 55 ++ .../Samples/Sample_ResourceGroupResource.cs | 145 +++ .../Sample_ResourceProviderCollection.cs | 116 +++ .../Sample_ResourceProviderResource.cs | 108 +++ .../Samples/Sample_SubscriptionCollection.cs | 110 +++ ..._SubscriptionPolicyDefinitionCollection.cs | 286 ++++++ ...le_SubscriptionPolicyDefinitionResource.cs | 239 +++++ ...bscriptionPolicySetDefinitionCollection.cs | 293 ++++++ ...SubscriptionPolicySetDefinitionResource.cs | 246 +++++ .../Samples/Sample_SubscriptionResource.cs | 138 +++ .../generated/Samples/Sample_TagResource.cs | 283 ++++++ .../Samples/Sample_TenantCollection.cs | 47 + ...Sample_TenantPolicyDefinitionCollection.cs | 110 +++ .../Sample_TenantPolicyDefinitionResource.cs | 48 + ...ple_TenantPolicySetDefinitionCollection.cs | 110 +++ ...ample_TenantPolicySetDefinitionResource.cs | 48 + .../Samples/Sample_TenantResource.cs | 45 + 34 files changed, 5968 insertions(+) create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/Azure.ResourceManager.Samples.csproj create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/autorest.tests.md create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TagResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionCollection.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionResource.cs create mode 100644 sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantResource.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager/Azure.ResourceManager.sln b/sdk/resourcemanager/Azure.ResourceManager/Azure.ResourceManager.sln index 2dd06ec4a9302..dc181b5f7efe1 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/Azure.ResourceManager.sln +++ b/sdk/resourcemanager/Azure.ResourceManager/Azure.ResourceManager.sln @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.Perf" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{AD397048-D114-4A32-8F35-64E5C72A4697}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.Samples", "samples\Azure.ResourceManager.Samples.csproj", "{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {AD397048-D114-4A32-8F35-64E5C72A4697}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD397048-D114-4A32-8F35-64E5C72A4697}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD397048-D114-4A32-8F35-64E5C72A4697}.Release|Any CPU.Build.0 = Release|Any CPU + {0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/Azure.ResourceManager.Samples.csproj b/sdk/resourcemanager/Azure.ResourceManager/samples/Azure.ResourceManager.Samples.csproj new file mode 100644 index 0000000000000..153d0d172d6eb --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/Azure.ResourceManager.Samples.csproj @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/autorest.tests.md b/sdk/resourcemanager/Azure.ResourceManager/samples/autorest.tests.md new file mode 100644 index 0000000000000..9a6619db028b0 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/autorest.tests.md @@ -0,0 +1,13 @@ +# Generated code configuration + +Run `dotnet build /t:GenerateTests` to generate code. + +# Azure.ResourceManager.Tests + +> see https://aka.ms/autorest +``` yaml +require: ../src/autorest.md +include-x-ms-examples-original-file: true +testgen: + sample: true +``` diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestCollection.cs new file mode 100644 index 0000000000000..a90c4cb5a8d15 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestCollection.cs @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_DataPolicyManifestCollection + { + // Retrieve a data policy manifest by policy mode + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveADataPolicyManifestByPolicyMode() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json + // this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this DataPolicyManifestResource + DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests(); + + // invoke the operation + string policyMode = "Microsoft.KeyVault.Data"; + DataPolicyManifestResource result = await collection.GetAsync(policyMode); + + // 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 + DataPolicyManifestData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a data policy manifest by policy mode + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveADataPolicyManifestByPolicyMode() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json + // this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this DataPolicyManifestResource + DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests(); + + // invoke the operation + string policyMode = "Microsoft.KeyVault.Data"; + bool result = await collection.ExistsAsync(policyMode); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List data policy manifests + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListDataPolicyManifests() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json + // this example is just showing the usage of "DataPolicyManifests_List" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this DataPolicyManifestResource + DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests(); + + // invoke the operation and iterate over the result + await foreach (DataPolicyManifestResource item in collection.GetAllAsync()) + { + // the variable item 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 + DataPolicyManifestData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // List data policy manifests with namespace filter + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListDataPolicyManifestsWithNamespaceFilter() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json + // this example is just showing the usage of "DataPolicyManifests_List" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this DataPolicyManifestResource + DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests(); + + // invoke the operation and iterate over the result + string filter = "namespace eq 'Microsoft.KeyVault'"; + await foreach (DataPolicyManifestResource item in collection.GetAllAsync(filter: filter)) + { + // the variable item 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 + DataPolicyManifestData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestResource.cs new file mode 100644 index 0000000000000..7de44219c4b87 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_DataPolicyManifestResource.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_DataPolicyManifestResource + { + // Retrieve a data policy manifest by policy mode + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveADataPolicyManifestByPolicyMode() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json + // this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" 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 DataPolicyManifestResource created on azure + // for more information of creating DataPolicyManifestResource, please refer to the document of DataPolicyManifestResource + string policyMode = "Microsoft.KeyVault.Data"; + ResourceIdentifier dataPolicyManifestResourceId = DataPolicyManifestResource.CreateResourceIdentifier(policyMode); + DataPolicyManifestResource dataPolicyManifest = client.GetDataPolicyManifestResource(dataPolicyManifestResourceId); + + // invoke the operation + DataPolicyManifestResource result = await dataPolicyManifest.GetAsync(); + + // 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 + DataPolicyManifestData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureCollection.cs new file mode 100644 index 0000000000000..edc447e1fc8d2 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureCollection.cs @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_FeatureCollection + { + // List provider Features + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListProviderFeatures() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listProviderFeatures.json + // this example is just showing the usage of "Features_List" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "subid"; + string resourceProviderNamespace = "Resource Provider Namespace"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // get the collection of this FeatureResource + FeatureCollection collection = resourceProvider.GetFeatures(); + + // invoke the operation and iterate over the result + await foreach (FeatureResource item in collection.GetAllAsync()) + { + // the variable item 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 + FeatureData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // Get feature + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetFeature() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json + // this example is just showing the usage of "Features_Get" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "subid"; + string resourceProviderNamespace = "Resource Provider Namespace"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // get the collection of this FeatureResource + FeatureCollection collection = resourceProvider.GetFeatures(); + + // invoke the operation + string featureName = "feature"; + FeatureResource result = await collection.GetAsync(featureName); + + // 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 + FeatureData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get feature + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetFeature() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json + // this example is just showing the usage of "Features_Get" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "subid"; + string resourceProviderNamespace = "Resource Provider Namespace"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // get the collection of this FeatureResource + FeatureCollection collection = resourceProvider.GetFeatures(); + + // invoke the operation + string featureName = "feature"; + bool result = await collection.ExistsAsync(featureName); + + Console.WriteLine($"Succeeded: {result}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureResource.cs new file mode 100644 index 0000000000000..5213c82125a9e --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_FeatureResource.cs @@ -0,0 +1,112 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_FeatureResource + { + // Get feature + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetFeature() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json + // this example is just showing the usage of "Features_Get" 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 FeatureResource created on azure + // for more information of creating FeatureResource, please refer to the document of FeatureResource + string subscriptionId = "subid"; + string resourceProviderNamespace = "Resource Provider Namespace"; + string featureName = "feature"; + ResourceIdentifier featureResourceId = FeatureResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace, featureName); + FeatureResource feature = client.GetFeatureResource(featureResourceId); + + // invoke the operation + FeatureResource result = await feature.GetAsync(); + + // 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 + FeatureData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Register feature + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Register_RegisterFeature() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/registerFeature.json + // this example is just showing the usage of "Features_Register" 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 FeatureResource created on azure + // for more information of creating FeatureResource, please refer to the document of FeatureResource + string subscriptionId = "subid"; + string resourceProviderNamespace = "Resource Provider Namespace"; + string featureName = "feature"; + ResourceIdentifier featureResourceId = FeatureResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace, featureName); + FeatureResource feature = client.GetFeatureResource(featureResourceId); + + // invoke the operation + FeatureResource result = await feature.RegisterAsync(); + + // 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 + FeatureData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Register feature + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Unregister_RegisterFeature() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/unregisterFeature.json + // this example is just showing the usage of "Features_Unregister" 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 FeatureResource created on azure + // for more information of creating FeatureResource, please refer to the document of FeatureResource + string subscriptionId = "ff23096b-f5a2-46ea-bd62-59c3e93fef9a"; + string resourceProviderNamespace = "Resource Provider Namespace"; + string featureName = "feature"; + ResourceIdentifier featureResourceId = FeatureResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace, featureName); + FeatureResource feature = client.GetFeatureResource(featureResourceId); + + // invoke the operation + FeatureResource result = await feature.UnregisterAsync(); + + // 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 + FeatureData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupCollection.cs new file mode 100644 index 0000000000000..cb8d188302a98 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupCollection.cs @@ -0,0 +1,441 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; +using Azure.ResourceManager.ManagementGroups.Models; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.ManagementGroups.Samples +{ + public partial class Sample_ManagementGroupCollection + { + // ListManagementGroups + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListManagementGroups() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/ListManagementGroups.json + // this example is just showing the usage of "ManagementGroups_List" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation and iterate over the result + string cacheControl = "no-cache"; + await foreach (ManagementGroupResource item in collection.GetAllAsync(cacheControl: cacheControl)) + { + // the variable item 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 + ManagementGroupData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // GetManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroup.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + string cacheControl = "no-cache"; + ManagementGroupResource result = await collection.GetAsync(groupId, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroup.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(groupId, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetManagementGroupWithAncestors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithAncestors() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithAncestors.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-00000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Ancestors; + string cacheControl = "no-cache"; + ManagementGroupResource result = await collection.GetAsync(groupId, expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithAncestors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementGroupWithAncestors() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithAncestors.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-00000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Ancestors; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(groupId, expand: expand, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetManagementGroupWithExpand + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithExpand() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpand.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + string cacheControl = "no-cache"; + ManagementGroupResource result = await collection.GetAsync(groupId, expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithExpand + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementGroupWithExpand() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpand.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(groupId, expand: expand, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetManagementGroupWithPath + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithPath() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithPath.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Path; + string cacheControl = "no-cache"; + ManagementGroupResource result = await collection.GetAsync(groupId, expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithPath + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementGroupWithPath() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithPath.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Path; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(groupId, expand: expand, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetManagementGroupsWithExpandAndRecurse + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupsWithExpandAndRecurse() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpandAndRecurse.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + bool? recurse = true; + string cacheControl = "no-cache"; + ManagementGroupResource result = await collection.GetAsync(groupId, expand: expand, recurse: recurse, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupsWithExpandAndRecurse + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementGroupsWithExpandAndRecurse() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpandAndRecurse.json + // this example is just showing the usage of "ManagementGroups_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "20000000-0001-0000-0000-000000000000"; + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + bool? recurse = true; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(groupId, expand: expand, recurse: recurse, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // PutManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_PutManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/PutManagementGroup.json + // this example is just showing the usage of "ManagementGroups_CreateOrUpdate" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + string groupId = "ChildGroup"; + ManagementGroupCreateOrUpdateContent content = new ManagementGroupCreateOrUpdateContent() + { + DisplayName = "ChildGroup", + Details = new CreateManagementGroupDetails() + { + Parent = new ManagementGroupParentCreateOptions() + { + Id = "/providers/Microsoft.Management/managementGroups/RootGroup", + }, + }, + }; + string cacheControl = "no-cache"; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, groupId, content, cacheControl: cacheControl); + ManagementGroupResource 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // CheckManagementGroupNameAvailability + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CheckNameAvailability_CheckManagementGroupNameAvailability() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/CheckManagementGroupNameAvailability.json + // this example is just showing the usage of "ManagementGroups_CheckNameAvailability" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenantResource = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this ManagementGroupResource + ManagementGroupCollection collection = tenantResource.GetManagementGroups(); + + // invoke the operation + ManagementGroupNameAvailabilityContent content = new ManagementGroupNameAvailabilityContent() + { + Name = "nameTocheck", + ResourceType = new ResourceType("Microsoft.Management/managementGroups"), + }; + ManagementGroupNameAvailabilityResult result = await collection.CheckNameAvailabilityAsync(content); + + Console.WriteLine($"Succeeded: {result}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionCollection.cs new file mode 100644 index 0000000000000..f699f67789222 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionCollection.cs @@ -0,0 +1,200 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementGroupPolicyDefinitionCollection + { + // Create or update a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicyDefinitionResource + ManagementGroupPolicyDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "All", + DisplayName = "Enforce resource naming convention", + Description = "Force resource names to begin with given 'prefix' and/or end with given 'suffix'", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["not"] = new Dictionary() + { + ["field"] = "name", + ["like"] = "[concat(parameters('prefix'), '*', parameters('suffix'))]" + } + }, + ["then"] = new Dictionary() + { + ["effect"] = "deny" + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Naming" + }), + Parameters = +{ +["prefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix", +Description = "Resource name prefix", +}, +}, +["suffix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Suffix", +Description = "Resource name suffix", +}, +}, +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyDefinitionName, data); + ManagementGroupPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_GetAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicyDefinitionResource + ManagementGroupPolicyDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + ManagementGroupPolicyDefinitionResource result = await collection.GetAsync(policyDefinitionName); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_GetAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicyDefinitionResource + ManagementGroupPolicyDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + bool result = await collection.ExistsAsync(policyDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List policy definitions by management group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicyDefinitionsByManagementGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitionsByManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_ListByManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicyDefinitionResource + ManagementGroupPolicyDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicyDefinitions(); + + // invoke the operation and iterate over the result + await foreach (ManagementGroupPolicyDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicyDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionResource.cs new file mode 100644 index 0000000000000..fed04af67f02a --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicyDefinitionResource.cs @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementGroupPolicyDefinitionResource + { + // Create or update a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupPolicyDefinitionResource created on azure + // for more information of creating ManagementGroupPolicyDefinitionResource, please refer to the document of ManagementGroupPolicyDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier managementGroupPolicyDefinitionResourceId = ManagementGroupPolicyDefinitionResource.CreateResourceIdentifier(managementGroupId, policyDefinitionName); + ManagementGroupPolicyDefinitionResource managementGroupPolicyDefinition = client.GetManagementGroupPolicyDefinitionResource(managementGroupPolicyDefinitionResourceId); + + // invoke the operation + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "All", + DisplayName = "Enforce resource naming convention", + Description = "Force resource names to begin with given 'prefix' and/or end with given 'suffix'", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["not"] = new Dictionary() + { + ["field"] = "name", + ["like"] = "[concat(parameters('prefix'), '*', parameters('suffix'))]" + } + }, + ["then"] = new Dictionary() + { + ["effect"] = "deny" + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Naming" + }), + Parameters = +{ +["prefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix", +Description = "Resource name prefix", +}, +}, +["suffix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Suffix", +Description = "Resource name suffix", +}, +}, +}, + }; + ArmOperation lro = await managementGroupPolicyDefinition.UpdateAsync(WaitUntil.Completed, data); + ManagementGroupPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Delete a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_DeleteAtManagementGroup" 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 ManagementGroupPolicyDefinitionResource created on azure + // for more information of creating ManagementGroupPolicyDefinitionResource, please refer to the document of ManagementGroupPolicyDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier managementGroupPolicyDefinitionResourceId = ManagementGroupPolicyDefinitionResource.CreateResourceIdentifier(managementGroupId, policyDefinitionName); + ManagementGroupPolicyDefinitionResource managementGroupPolicyDefinition = client.GetManagementGroupPolicyDefinitionResource(managementGroupPolicyDefinitionResourceId); + + // invoke the operation + await managementGroupPolicyDefinition.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Retrieve a policy definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicyDefinitions_GetAtManagementGroup" 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 ManagementGroupPolicyDefinitionResource created on azure + // for more information of creating ManagementGroupPolicyDefinitionResource, please refer to the document of ManagementGroupPolicyDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier managementGroupPolicyDefinitionResourceId = ManagementGroupPolicyDefinitionResource.CreateResourceIdentifier(managementGroupId, policyDefinitionName); + ManagementGroupPolicyDefinitionResource managementGroupPolicyDefinition = client.GetManagementGroupPolicyDefinitionResource(managementGroupPolicyDefinitionResourceId); + + // invoke the operation + ManagementGroupPolicyDefinitionResource result = await managementGroupPolicyDefinition.GetAsync(); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionCollection.cs new file mode 100644 index 0000000000000..d9db142c8c2df --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionCollection.cs @@ -0,0 +1,282 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementGroupPolicySetDefinitionCollection + { + // Create or update a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicySetDefinitionResource + ManagementGroupPolicySetDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +},new PolicyDefinitionReference("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policySetDefinitionName, data); + ManagementGroupPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy set definition with groups at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicySetDefinitionResource + ManagementGroupPolicySetDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +GroupNames = +{ +"CostSaving" +}, +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +GroupNames = +{ +"Organizational" +}, +} +}, + PolicyDefinitionGroups = +{ +new PolicyDefinitionGroup("CostSaving") +{ +DisplayName = "Cost Management Policies", +Description = "Policies designed to control spend within a subscription.", +},new PolicyDefinitionGroup("Organizational") +{ +DisplayName = "Organizational Policies", +Description = "Policies that help enforce resource organization standards within a subscription.", +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policySetDefinitionName, data); + ManagementGroupPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_GetAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicySetDefinitionResource + ManagementGroupPolicySetDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + ManagementGroupPolicySetDefinitionResource result = await collection.GetAsync(policySetDefinitionName); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_GetAtManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicySetDefinitionResource + ManagementGroupPolicySetDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + bool result = await collection.ExistsAsync(policySetDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List policy set definitions at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicySetDefinitionsAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitionsByManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_ListByManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string managementGroupId = "MyManagementGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(managementGroupId); + ManagementGroupResource managementGroupResource = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupPolicySetDefinitionResource + ManagementGroupPolicySetDefinitionCollection collection = managementGroupResource.GetManagementGroupPolicySetDefinitions(); + + // invoke the operation and iterate over the result + await foreach (ManagementGroupPolicySetDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicySetDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionResource.cs new file mode 100644 index 0000000000000..fb9bf7b428f3e --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupPolicySetDefinitionResource.cs @@ -0,0 +1,234 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementGroupPolicySetDefinitionResource + { + // Create or update a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupPolicySetDefinitionResource created on azure + // for more information of creating ManagementGroupPolicySetDefinitionResource, please refer to the document of ManagementGroupPolicySetDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier managementGroupPolicySetDefinitionResourceId = ManagementGroupPolicySetDefinitionResource.CreateResourceIdentifier(managementGroupId, policySetDefinitionName); + ManagementGroupPolicySetDefinitionResource managementGroupPolicySetDefinition = client.GetManagementGroupPolicySetDefinitionResource(managementGroupPolicySetDefinitionResourceId); + + // invoke the operation + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +},new PolicyDefinitionReference("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +} +}, + }; + ArmOperation lro = await managementGroupPolicySetDefinition.UpdateAsync(WaitUntil.Completed, data); + ManagementGroupPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy set definition with groups at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdateAtManagementGroup" 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 ManagementGroupPolicySetDefinitionResource created on azure + // for more information of creating ManagementGroupPolicySetDefinitionResource, please refer to the document of ManagementGroupPolicySetDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier managementGroupPolicySetDefinitionResourceId = ManagementGroupPolicySetDefinitionResource.CreateResourceIdentifier(managementGroupId, policySetDefinitionName); + ManagementGroupPolicySetDefinitionResource managementGroupPolicySetDefinition = client.GetManagementGroupPolicySetDefinitionResource(managementGroupPolicySetDefinitionResourceId); + + // invoke the operation + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +GroupNames = +{ +"CostSaving" +}, +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +GroupNames = +{ +"Organizational" +}, +} +}, + PolicyDefinitionGroups = +{ +new PolicyDefinitionGroup("CostSaving") +{ +DisplayName = "Cost Management Policies", +Description = "Policies designed to control spend within a subscription.", +},new PolicyDefinitionGroup("Organizational") +{ +DisplayName = "Organizational Policies", +Description = "Policies that help enforce resource organization standards within a subscription.", +} +}, + }; + ArmOperation lro = await managementGroupPolicySetDefinition.UpdateAsync(WaitUntil.Completed, data); + ManagementGroupPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Delete a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_DeleteAtManagementGroup" 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 ManagementGroupPolicySetDefinitionResource created on azure + // for more information of creating ManagementGroupPolicySetDefinitionResource, please refer to the document of ManagementGroupPolicySetDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier managementGroupPolicySetDefinitionResourceId = ManagementGroupPolicySetDefinitionResource.CreateResourceIdentifier(managementGroupId, policySetDefinitionName); + ManagementGroupPolicySetDefinitionResource managementGroupPolicySetDefinition = client.GetManagementGroupPolicySetDefinitionResource(managementGroupPolicySetDefinitionResourceId); + + // invoke the operation + await managementGroupPolicySetDefinition.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Retrieve a policy set definition at management group level + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicySetDefinitionAtManagementGroupLevel() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json + // this example is just showing the usage of "PolicySetDefinitions_GetAtManagementGroup" 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 ManagementGroupPolicySetDefinitionResource created on azure + // for more information of creating ManagementGroupPolicySetDefinitionResource, please refer to the document of ManagementGroupPolicySetDefinitionResource + string managementGroupId = "MyManagementGroup"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier managementGroupPolicySetDefinitionResourceId = ManagementGroupPolicySetDefinitionResource.CreateResourceIdentifier(managementGroupId, policySetDefinitionName); + ManagementGroupPolicySetDefinitionResource managementGroupPolicySetDefinition = client.GetManagementGroupPolicySetDefinitionResource(managementGroupPolicySetDefinitionResourceId); + + // invoke the operation + ManagementGroupPolicySetDefinitionResource result = await managementGroupPolicySetDefinition.GetAsync(); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupResource.cs new file mode 100644 index 0000000000000..250db63ebc712 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementGroupResource.cs @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; +using Azure.ResourceManager.ManagementGroups.Models; + +namespace Azure.ResourceManager.ManagementGroups.Samples +{ + public partial class Sample_ManagementGroupResource + { + // GetManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroup.json + // this example is just showing the usage of "ManagementGroups_Get" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0001-0000-0000-000000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.GetAsync(cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithAncestors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithAncestors() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithAncestors.json + // this example is just showing the usage of "ManagementGroups_Get" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0001-0000-0000-00000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + ManagementGroupExpandType? expand = ManagementGroupExpandType.Ancestors; + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.GetAsync(expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithExpand + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithExpand() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpand.json + // this example is just showing the usage of "ManagementGroups_Get" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0001-0000-0000-000000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.GetAsync(expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupWithPath + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupWithPath() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithPath.json + // this example is just showing the usage of "ManagementGroups_Get" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0001-0000-0000-000000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + ManagementGroupExpandType? expand = ManagementGroupExpandType.Path; + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.GetAsync(expand: expand, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetManagementGroupsWithExpandAndRecurse + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementGroupsWithExpandAndRecurse() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetManagementGroupWithExpandAndRecurse.json + // this example is just showing the usage of "ManagementGroups_Get" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0001-0000-0000-000000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + ManagementGroupExpandType? expand = ManagementGroupExpandType.Children; + bool? recurse = true; + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.GetAsync(expand: expand, recurse: recurse, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // PatchManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_PatchManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/PatchManagementGroup.json + // this example is just showing the usage of "ManagementGroups_Update" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "ChildGroup"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + ManagementGroupPatch patch = new ManagementGroupPatch() + { + DisplayName = "AlternateDisplayName", + ParentGroupId = "/providers/Microsoft.Management/managementGroups/AlternateRootGroup", + }; + string cacheControl = "no-cache"; + ManagementGroupResource result = await managementGroup.UpdateAsync(patch, cacheControl: cacheControl); + + // 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 + ManagementGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // DeleteManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/DeleteManagementGroup.json + // this example is just showing the usage of "ManagementGroups_Delete" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "GroupToDelete"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation + string cacheControl = "no-cache"; + await managementGroup.DeleteAsync(WaitUntil.Completed, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded"); + } + + // GetDescendants + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetDescendants_GetDescendants() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetDescendants.json + // this example is just showing the usage of "ManagementGroups_GetDescendants" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "20000000-0000-0000-0000-000000000000"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // invoke the operation and iterate over the result + await foreach (DescendantData item in managementGroup.GetDescendantsAsync()) + { + Console.WriteLine($"Succeeded: {item}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockCollection.cs new file mode 100644 index 0000000000000..08cc3fccd8f54 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockCollection.cs @@ -0,0 +1,149 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementLockCollection + { + // Create management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtScope.json + // this example is just showing the usage of "ManagementLocks_CreateOrUpdateByScope" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this ManagementLockResource + string scope = "subscriptions/subscriptionId"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + ManagementLockCollection collection = client.GetGenericResource(scopeId).GetManagementLocks(); + + // invoke the operation + string lockName = "testlock"; + ManagementLockData data = new ManagementLockData(ManagementLockLevel.ReadOnly); + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, lockName, data); + ManagementLockResource 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 + ManagementLockData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtScope.json + // this example is just showing the usage of "ManagementLocks_GetByScope" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this ManagementLockResource + string scope = "subscriptions/subscriptionId"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + ManagementLockCollection collection = client.GetGenericResource(scopeId).GetManagementLocks(); + + // invoke the operation + string lockName = "testlock"; + ManagementLockResource result = await collection.GetAsync(lockName); + + // 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 + ManagementLockData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtScope.json + // this example is just showing the usage of "ManagementLocks_GetByScope" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this ManagementLockResource + string scope = "subscriptions/subscriptionId"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + ManagementLockCollection collection = client.GetGenericResource(scopeId).GetManagementLocks(); + + // invoke the operation + string lockName = "testlock"; + bool result = await collection.ExistsAsync(lockName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List management locks at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListManagementLocksAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_ListAtScope.json + // this example is just showing the usage of "ManagementLocks_ListByScope" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this ManagementLockResource + string scope = "subscriptions/subscriptionId"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + ManagementLockCollection collection = client.GetGenericResource(scopeId).GetManagementLocks(); + + // invoke the operation and iterate over the result + await foreach (ManagementLockResource item in collection.GetAllAsync()) + { + // the variable item 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 + ManagementLockData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockResource.cs new file mode 100644 index 0000000000000..0c27bb702cf1d --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ManagementLockResource.cs @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ManagementLockResource + { + // Create management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_CreateOrUpdateAtScope.json + // this example is just showing the usage of "ManagementLocks_CreateOrUpdateByScope" 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 ManagementLockResource created on azure + // for more information of creating ManagementLockResource, please refer to the document of ManagementLockResource + string scope = "subscriptions/subscriptionId"; + string lockName = "testlock"; + ResourceIdentifier managementLockResourceId = ManagementLockResource.CreateResourceIdentifier(scope, lockName); + ManagementLockResource managementLock = client.GetManagementLockResource(managementLockResourceId); + + // invoke the operation + ManagementLockData data = new ManagementLockData(ManagementLockLevel.ReadOnly); + ArmOperation lro = await managementLock.UpdateAsync(WaitUntil.Completed, data); + ManagementLockResource 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 + ManagementLockData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Delete management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_DeleteAtScope.json + // this example is just showing the usage of "ManagementLocks_DeleteByScope" 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 ManagementLockResource created on azure + // for more information of creating ManagementLockResource, please refer to the document of ManagementLockResource + string scope = "subscriptions/subscriptionId"; + string lockName = "testlock"; + ResourceIdentifier managementLockResourceId = ManagementLockResource.CreateResourceIdentifier(scope, lockName); + ManagementLockResource managementLock = client.GetManagementLockResource(managementLockResourceId); + + // invoke the operation + await managementLock.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Get management lock at scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetManagementLockAtScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2016-09-01/examples/ManagementLocks_GetAtScope.json + // this example is just showing the usage of "ManagementLocks_GetByScope" 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 ManagementLockResource created on azure + // for more information of creating ManagementLockResource, please refer to the document of ManagementLockResource + string scope = "subscriptions/subscriptionId"; + string lockName = "testlock"; + ResourceIdentifier managementLockResourceId = ManagementLockResource.CreateResourceIdentifier(scope, lockName); + ManagementLockResource managementLock = client.GetManagementLockResource(managementLockResourceId); + + // invoke the operation + ManagementLockResource result = await managementLock.GetAsync(); + + // 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 + ManagementLockData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentCollection.cs new file mode 100644 index 0000000000000..b778467bb9c97 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentCollection.cs @@ -0,0 +1,872 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Models; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_PolicyAssignmentCollection + { + // Create or update a policy assignment + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignment() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignment.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + DisplayName = "Enforce resource naming rules", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, + Description = "Force resource names to begin with given DeptA and end with -LC", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Special Someone" + }), + NonComplianceMessages = +{ +new NonComplianceMessage("Resource names must start with 'DeptA' and end with '-LC'.") +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment with a system assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithIdentity.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + Location = new AzureLocation("eastus"), + ManagedIdentity = new ManagedServiceIdentity("SystemAssigned"), + DisplayName = "Enforce resource naming rules", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, + Description = "Force resource names to begin with given DeptA and end with -LC", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Foo Bar" + }), + EnforcementMode = new EnforcementMode("Default"), + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment with a user assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + Location = new AzureLocation("eastus"), + ManagedIdentity = new ManagedServiceIdentity("UserAssigned") + { + UserAssignedIdentities = +{ +[new ResourceIdentifier("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity")] = new UserAssignedIdentity(), +}, + }, + DisplayName = "Enforce resource naming rules", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, + Description = "Force resource names to begin with given DeptA and end with -LC", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Foo Bar" + }), + EnforcementMode = new EnforcementMode("Default"), + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment with multiple non-compliance messages + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentNonComplianceMessages.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "securityInitAssignment"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + DisplayName = "Enforce security policies", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/securityInitiative", + NonComplianceMessages = +{ +new NonComplianceMessage("Resources must comply with all internal security policies. See for more info."),new NonComplianceMessage("Resource names must start with 'DeptA' and end with '-LC'.") +{ +PolicyDefinitionReferenceId = "10420126870854049575", +},new NonComplianceMessage("Storage accounts must have firewall rules configured.") +{ +PolicyDefinitionReferenceId = "8572513655450389710", +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment with overrides + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithOverrides() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithOverrides.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + DisplayName = "Limit the resource location and resource SKU", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement", + Description = "Limit the resource location and resource SKU", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Special Someone" + }), + Overrides = +{ +new PolicyOverride() +{ +Kind = PolicyOverrideKind.PolicyEffect, +Value = "Audit", +Selectors = +{ +new ResourceSelectorExpression() +{ +Kind = ResourceSelectorKind.PolicyDefinitionReferenceId, +In = +{ +"Limit_Skus","Limit_Locations" +}, +} +}, +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment with resource selectors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithResourceSelectors() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithResourceSelectors.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + DisplayName = "Limit the resource location and resource SKU", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement", + Description = "Limit the resource location and resource SKU", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Special Someone" + }), + ResourceSelectors = +{ +new ResourceSelector() +{ +Name = "SDPRegions", +Selectors = +{ +new ResourceSelectorExpression() +{ +Kind = ResourceSelectorKind.ResourceLocation, +In = +{ +"eastus2euap","centraluseuap" +}, +} +}, +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy assignment without enforcing policy effect during resource creation or update. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/createPolicyAssignmentWithoutEnforcement.json + // this example is just showing the usage of "PolicyAssignments_Create" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentData data = new PolicyAssignmentData() + { + DisplayName = "Enforce resource naming rules", + PolicyDefinitionId = "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming", + Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, + Description = "Force resource names to begin with given DeptA and end with -LC", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["assignedBy"] = "Special Someone" + }), + EnforcementMode = EnforcementMode.DoNotEnforce, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyAssignmentName, data); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignment() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignment.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentResource result = await collection.GetAsync(policyAssignmentName); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyAssignment() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignment.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + bool result = await collection.ExistsAsync(policyAssignmentName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // Retrieve a policy assignment with a system assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithASystemAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentResource result = await collection.GetAsync(policyAssignmentName); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with a system assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyAssignmentWithASystemAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + bool result = await collection.ExistsAsync(policyAssignmentName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // Retrieve a policy assignment with a user assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithAUserAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + PolicyAssignmentResource result = await collection.GetAsync(policyAssignmentName); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with a user assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyAssignmentWithAUserAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "EnforceNaming"; + bool result = await collection.ExistsAsync(policyAssignmentName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // Retrieve a policy assignment with overrides + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithOverrides() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithOverrides.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + PolicyAssignmentResource result = await collection.GetAsync(policyAssignmentName); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with overrides + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyAssignmentWithOverrides() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithOverrides.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + bool result = await collection.ExistsAsync(policyAssignmentName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // Retrieve a policy assignment with resource selectors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithResourceSelectors() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithResourceSelectors.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + PolicyAssignmentResource result = await collection.GetAsync(policyAssignmentName); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with resource selectors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyAssignmentWithResourceSelectors() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithResourceSelectors.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/{0}", scope)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation + string policyAssignmentName = "CostManagement"; + bool result = await collection.ExistsAsync(policyAssignmentName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List policy assignments that apply to a resource group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicyAssignmentsThatApplyToAResourceGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForResourceGroup.json + // this example is just showing the usage of "PolicyAssignments_ListForResourceGroup" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string resourceGroupName = "TestResourceGroup"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}", subscriptionId, resourceGroupName)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation and iterate over the result + string filter = "atScope()"; + await foreach (PolicyAssignmentResource item in collection.GetAllAsync(filter: filter)) + { + // the variable item 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 + PolicyAssignmentData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // List all policy assignments that apply to a resource + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListAllPolicyAssignmentsThatApplyToAResource() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForResource.json + // this example is just showing the usage of "PolicyAssignments_ListForResource" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string resourceGroupName = "TestResourceGroup"; + string resourceProviderNamespace = "Microsoft.Compute"; + string parentResourcePath = "virtualMachines/MyTestVm"; + string resourceType = "domainNames"; + string resourceName = "MyTestComputer.cloudapp.net"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/{2}/{3}/{4}/{5}", subscriptionId, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation and iterate over the result + await foreach (PolicyAssignmentResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicyAssignmentData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // List policy assignments that apply to a management group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicyAssignmentsThatApplyToAManagementGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignmentsForManagementGroup.json + // this example is just showing the usage of "PolicyAssignments_ListForManagementGroup" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string managementGroupId = "TestManagementGroup"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/providers/Microsoft.Management/managementGroups/{0}", managementGroupId)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation and iterate over the result + string filter = "atScope()"; + await foreach (PolicyAssignmentResource item in collection.GetAllAsync(filter: filter)) + { + // the variable item 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 + PolicyAssignmentData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // List policy assignments that apply to a subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicyAssignmentsThatApplyToASubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/listPolicyAssignments.json + // this example is just showing the usage of "PolicyAssignments_List" 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 ArmResource created on azure + // for more information of creating ArmResource, please refer to the document of ArmResource + + // get the collection of this PolicyAssignmentResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier scopeId = new ResourceIdentifier(string.Format("/subscriptions/{0}", subscriptionId)); + PolicyAssignmentCollection collection = client.GetGenericResource(scopeId).GetPolicyAssignments(); + + // invoke the operation and iterate over the result + string filter = "atScope()"; + await foreach (PolicyAssignmentResource item in collection.GetAllAsync(filter: filter)) + { + // the variable item 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 + PolicyAssignmentData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentResource.cs new file mode 100644 index 0000000000000..374dc4007fbbe --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_PolicyAssignmentResource.cs @@ -0,0 +1,382 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Models; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_PolicyAssignmentResource + { + // Delete a policy assignment + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteAPolicyAssignment() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/deletePolicyAssignment.json + // this example is just showing the usage of "PolicyAssignments_Delete" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + ArmOperation lro = await policyAssignment.DeleteAsync(WaitUntil.Completed); + PolicyAssignmentResource 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignment() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignment.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentResource result = await policyAssignment.GetAsync(); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with a system assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithASystemAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentResource result = await policyAssignment.GetAsync(); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with a user assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithAUserAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentResource result = await policyAssignment.GetAsync(); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with overrides + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithOverrides() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithOverrides.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "CostManagement"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentResource result = await policyAssignment.GetAsync(); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy assignment with resource selectors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyAssignmentWithResourceSelectors() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/getPolicyAssignmentWithResourceSelectors.json + // this example is just showing the usage of "PolicyAssignments_Get" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "CostManagement"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentResource result = await policyAssignment.GetAsync(); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update a policy assignment with a system assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateAPolicyAssignmentWithASystemAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithIdentity.json + // this example is just showing the usage of "PolicyAssignments_Update" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentPatch patch = new PolicyAssignmentPatch() + { + Location = new AzureLocation("eastus"), + Identity = new ManagedServiceIdentity("SystemAssigned"), + }; + PolicyAssignmentResource result = await policyAssignment.UpdateAsync(patch); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update a policy assignment with a user assigned identity + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateAPolicyAssignmentWithAUserAssignedIdentity() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json + // this example is just showing the usage of "PolicyAssignments_Update" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "EnforceNaming"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentPatch patch = new PolicyAssignmentPatch() + { + Location = new AzureLocation("eastus"), + Identity = new ManagedServiceIdentity("UserAssigned") + { + UserAssignedIdentities = +{ +[new ResourceIdentifier("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity")] = new UserAssignedIdentity(), +}, + }, + }; + PolicyAssignmentResource result = await policyAssignment.UpdateAsync(patch); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update a policy assignment with overrides + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateAPolicyAssignmentWithOverrides() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithOverrides.json + // this example is just showing the usage of "PolicyAssignments_Update" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "CostManagement"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentPatch patch = new PolicyAssignmentPatch() + { + Overrides = +{ +new PolicyOverride() +{ +Kind = PolicyOverrideKind.PolicyEffect, +Value = "Audit", +Selectors = +{ +new ResourceSelectorExpression() +{ +Kind = ResourceSelectorKind.PolicyDefinitionReferenceId, +In = +{ +"Limit_Skus","Limit_Locations" +}, +} +}, +} +}, + }; + PolicyAssignmentResource result = await policyAssignment.UpdateAsync(patch); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update a policy assignment with resource selectors + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateAPolicyAssignmentWithResourceSelectors() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2022-06-01/examples/updatePolicyAssignmentWithResourceSelectors.json + // this example is just showing the usage of "PolicyAssignments_Update" 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 PolicyAssignmentResource created on azure + // for more information of creating PolicyAssignmentResource, please refer to the document of PolicyAssignmentResource + string scope = "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyAssignmentName = "CostManagement"; + ResourceIdentifier policyAssignmentResourceId = PolicyAssignmentResource.CreateResourceIdentifier(scope, policyAssignmentName); + PolicyAssignmentResource policyAssignment = client.GetPolicyAssignmentResource(policyAssignmentResourceId); + + // invoke the operation + PolicyAssignmentPatch patch = new PolicyAssignmentPatch() + { + ResourceSelectors = +{ +new ResourceSelector() +{ +Name = "SDPRegions", +Selectors = +{ +new ResourceSelectorExpression() +{ +Kind = ResourceSelectorKind.ResourceLocation, +In = +{ +"eastus2euap","centraluseuap" +}, +} +}, +} +}, + }; + PolicyAssignmentResource result = await policyAssignment.UpdateAsync(patch); + + // 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 + PolicyAssignmentData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupCollection.cs new file mode 100644 index 0000000000000..027938b87648d --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupCollection.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ResourceGroupCollection + { + // Create or update a resource group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAResourceGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/CreateResourceGroup.json + // this example is just showing the usage of "ResourceGroups_CreateOrUpdate" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this ResourceGroupResource + ResourceGroupCollection collection = subscription.GetResourceGroups(); + + // invoke the operation + string resourceGroupName = "my-resource-group"; + ResourceGroupData data = new ResourceGroupData(new AzureLocation("eastus")); + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, resourceGroupName, data); + ResourceGroupResource 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 + ResourceGroupData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupResource.cs new file mode 100644 index 0000000000000..439a1b53cc03d --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceGroupResource.cs @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ResourceGroupResource + { + // Force delete all the Virtual Machines and Virtual Machine Scale Sets in a resource group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_ForceDeleteAllTheVirtualMachinesAndVirtualMachineScaleSetsInAResourceGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ForceDeleteVMsAndVMSSInResourceGroup.json + // this example is just showing the usage of "ResourceGroups_Delete" 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 ResourceGroupResource created on azure + // for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceGroupName = "my-resource-group"; + ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName); + ResourceGroupResource resourceGroup = client.GetResourceGroupResource(resourceGroupResourceId); + + // invoke the operation + string forceDeletionTypes = "Microsoft.Compute/virtualMachines,Microsoft.Compute/virtualMachineScaleSets"; + await resourceGroup.DeleteAsync(WaitUntil.Completed, forceDeletionTypes: forceDeletionTypes); + + Console.WriteLine($"Succeeded"); + } + + // Force delete all the Virtual Machines in a resource group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_ForceDeleteAllTheVirtualMachinesInAResourceGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ForceDeleteVMsInResourceGroup.json + // this example is just showing the usage of "ResourceGroups_Delete" 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 ResourceGroupResource created on azure + // for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceGroupName = "my-resource-group"; + ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName); + ResourceGroupResource resourceGroup = client.GetResourceGroupResource(resourceGroupResourceId); + + // invoke the operation + string forceDeletionTypes = "Microsoft.Compute/virtualMachines"; + await resourceGroup.DeleteAsync(WaitUntil.Completed, forceDeletionTypes: forceDeletionTypes); + + Console.WriteLine($"Succeeded"); + } + + // Export a resource group + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task ExportTemplate_ExportAResourceGroup() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ExportResourceGroup.json + // this example is just showing the usage of "ResourceGroups_ExportTemplate" 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 ResourceGroupResource created on azure + // for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceGroupName = "my-resource-group"; + ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName); + ResourceGroupResource resourceGroup = client.GetResourceGroupResource(resourceGroupResourceId); + + // invoke the operation + ExportTemplate exportTemplate = new ExportTemplate() + { + Resources = +{ +"*" +}, + Options = "IncludeParameterDefaultValue,IncludeComments", + }; + ArmOperation lro = await resourceGroup.ExportTemplateAsync(WaitUntil.Completed, exportTemplate); + ResourceGroupExportResult result = lro.Value; + + Console.WriteLine($"Succeeded: {result}"); + } + + // Export a resource group with filtering + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task ExportTemplate_ExportAResourceGroupWithFiltering() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/ExportResourceGroupWithFiltering.json + // this example is just showing the usage of "ResourceGroups_ExportTemplate" 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 ResourceGroupResource created on azure + // for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceGroupName = "my-resource-group"; + ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName); + ResourceGroupResource resourceGroup = client.GetResourceGroupResource(resourceGroupResourceId); + + // invoke the operation + ExportTemplate exportTemplate = new ExportTemplate() + { + Resources = +{ +"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/My.RP/myResourceType/myFirstResource" +}, + Options = "SkipResourceNameParameterization", + }; + ArmOperation lro = await resourceGroup.ExportTemplateAsync(WaitUntil.Completed, exportTemplate); + ResourceGroupExportResult result = lro.Value; + + Console.WriteLine($"Succeeded: {result}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderCollection.cs new file mode 100644 index 0000000000000..fe07e670fa833 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderCollection.cs @@ -0,0 +1,116 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ResourceProviderCollection + { + // Get providers. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_GetProviders() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviders.json + // this example is just showing the usage of "Providers_List" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this ResourceProviderResource + ResourceProviderCollection collection = subscription.GetResourceProviders(); + + // invoke the operation and iterate over the result + await foreach (ResourceProviderResource item in collection.GetAllAsync()) + { + // the variable item 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 + ResourceProviderData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + + // Get provider. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetProvider() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProvider.json + // this example is just showing the usage of "Providers_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this ResourceProviderResource + ResourceProviderCollection collection = subscription.GetResourceProviders(); + + // invoke the operation + string resourceProviderNamespace = "Microsoft.TestRP1"; + ResourceProviderResource result = await collection.GetAsync(resourceProviderNamespace); + + // 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 + ResourceProviderData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get provider. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetProvider() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProvider.json + // this example is just showing the usage of "Providers_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this ResourceProviderResource + ResourceProviderCollection collection = subscription.GetResourceProviders(); + + // invoke the operation + string resourceProviderNamespace = "Microsoft.TestRP1"; + bool result = await collection.ExistsAsync(resourceProviderNamespace); + + Console.WriteLine($"Succeeded: {result}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderResource.cs new file mode 100644 index 0000000000000..02354c16dd357 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_ResourceProviderResource.cs @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_ResourceProviderResource + { + // Get provider resource types. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task ProviderPermissions_GetProviderResourceTypes() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviderPermissions.json + // this example is just showing the usage of "Providers_ProviderPermissions" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceProviderNamespace = "Microsoft.TestRP"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // invoke the operation and iterate over the result + await foreach (ProviderPermission item in resourceProvider.ProviderPermissionsAsync()) + { + Console.WriteLine($"Succeeded: {item}"); + } + + Console.WriteLine($"Succeeded"); + } + + // Get provider. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetProvider() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProvider.json + // this example is just showing the usage of "Providers_Get" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceProviderNamespace = "Microsoft.TestRP1"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // invoke the operation + ResourceProviderResource result = await resourceProvider.GetAsync(); + + // 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 + ResourceProviderData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get provider resource types. + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetProviderResourceTypes_GetProviderResourceTypes() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetProviderResourceTypes.json + // this example is just showing the usage of "ProviderResourceTypes_List" 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 ResourceProviderResource created on azure + // for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + string resourceProviderNamespace = "Microsoft.TestRP"; + ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace); + ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId); + + // invoke the operation and iterate over the result + await foreach (ProviderResourceType item in resourceProvider.GetProviderResourceTypesAsync()) + { + Console.WriteLine($"Succeeded: {item}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs new file mode 100644 index 0000000000000..8b0de1b93e296 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionCollection + { + // GetASingleSubscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetASingleSubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // this example is just showing the usage of "Subscriptions_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this SubscriptionResource + SubscriptionCollection collection = tenant.GetSubscriptions(); + + // invoke the operation + string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + SubscriptionResource result = await collection.GetAsync(subscriptionId); + + // 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 + SubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetASingleSubscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetASingleSubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // this example is just showing the usage of "Subscriptions_Get" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this SubscriptionResource + SubscriptionCollection collection = tenant.GetSubscriptions(); + + // invoke the operation + string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + bool result = await collection.ExistsAsync(subscriptionId); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetAllSubscriptions + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_GetAllSubscriptions() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscriptions.json + // this example is just showing the usage of "Subscriptions_List" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this SubscriptionResource + SubscriptionCollection collection = tenant.GetSubscriptions(); + + // invoke the operation and iterate over the result + await foreach (SubscriptionResource item in collection.GetAllAsync()) + { + // the variable item 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 + SubscriptionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionCollection.cs new file mode 100644 index 0000000000000..ab07f423b45b1 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionCollection.cs @@ -0,0 +1,286 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionPolicyDefinitionCollection + { + // Create or update a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdate" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicyDefinitionResource + SubscriptionPolicyDefinitionCollection collection = subscription.GetSubscriptionPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "All", + DisplayName = "Enforce resource naming convention", + Description = "Force resource names to begin with given 'prefix' and/or end with given 'suffix'", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["not"] = new Dictionary() + { + ["field"] = "name", + ["like"] = "[concat(parameters('prefix'), '*', parameters('suffix'))]" + } + }, + ["then"] = new Dictionary() + { + ["effect"] = "deny" + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Naming" + }), + Parameters = +{ +["prefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix", +Description = "Resource name prefix", +}, +}, +["suffix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Suffix", +Description = "Resource name suffix", +}, +}, +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyDefinitionName, data); + SubscriptionPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy definition with advanced parameters + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicyDefinitionWithAdvancedParameters() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdate" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicyDefinitionResource + SubscriptionPolicyDefinitionCollection collection = subscription.GetSubscriptionPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "EventHubDiagnosticLogs"; + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "Indexed", + DisplayName = "Event Hubs should have diagnostic logging enabled", + Description = "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["equals"] = "Microsoft.EventHub/namespaces", + ["field"] = "type" + }, + ["then"] = new Dictionary() + { + ["effect"] = "AuditIfNotExists", + ["details"] = new Dictionary() + { + ["type"] = "Microsoft.Insights/diagnosticSettings", + ["existenceCondition"] = new Dictionary() + { + ["allOf"] = new object[] { new Dictionary() +{ +["equals"] = "true", +["field"] = "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled"}, new Dictionary() +{ +["equals"] = "[parameters('requiredRetentionDays')]", +["field"] = "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days"} } + } + } + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Event Hub" + }), + Parameters = +{ +["requiredRetentionDays"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.Integer, +AllowedValues = +{ +BinaryData.FromString("0"),BinaryData.FromString("30"),BinaryData.FromString("90"),BinaryData.FromString("180"),BinaryData.FromString("365") +}, +DefaultValue = BinaryData.FromString("365"), +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Required retention (days)", +Description = "The required diagnostic logs retention in days", +}, +}, +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyDefinitionName, data); + SubscriptionPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicyDefinitionResource + SubscriptionPolicyDefinitionCollection collection = subscription.GetSubscriptionPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + SubscriptionPolicyDefinitionResource result = await collection.GetAsync(policyDefinitionName); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicyDefinitionResource + SubscriptionPolicyDefinitionCollection collection = subscription.GetSubscriptionPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "ResourceNaming"; + bool result = await collection.ExistsAsync(policyDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List policy definitions by subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicyDefinitionsBySubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitions.json + // this example is just showing the usage of "PolicyDefinitions_List" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicyDefinitionResource + SubscriptionPolicyDefinitionCollection collection = subscription.GetSubscriptionPolicyDefinitions(); + + // invoke the operation and iterate over the result + await foreach (SubscriptionPolicyDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicyDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionResource.cs new file mode 100644 index 0000000000000..2512b0d2d2f37 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicyDefinitionResource.cs @@ -0,0 +1,239 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionPolicyDefinitionResource + { + // Create or update a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdate" 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 SubscriptionPolicyDefinitionResource created on azure + // for more information of creating SubscriptionPolicyDefinitionResource, please refer to the document of SubscriptionPolicyDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier subscriptionPolicyDefinitionResourceId = SubscriptionPolicyDefinitionResource.CreateResourceIdentifier(subscriptionId, policyDefinitionName); + SubscriptionPolicyDefinitionResource subscriptionPolicyDefinition = client.GetSubscriptionPolicyDefinitionResource(subscriptionPolicyDefinitionResourceId); + + // invoke the operation + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "All", + DisplayName = "Enforce resource naming convention", + Description = "Force resource names to begin with given 'prefix' and/or end with given 'suffix'", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["not"] = new Dictionary() + { + ["field"] = "name", + ["like"] = "[concat(parameters('prefix'), '*', parameters('suffix'))]" + } + }, + ["then"] = new Dictionary() + { + ["effect"] = "deny" + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Naming" + }), + Parameters = +{ +["prefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix", +Description = "Resource name prefix", +}, +}, +["suffix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Suffix", +Description = "Resource name suffix", +}, +}, +}, + }; + ArmOperation lro = await subscriptionPolicyDefinition.UpdateAsync(WaitUntil.Completed, data); + SubscriptionPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy definition with advanced parameters + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicyDefinitionWithAdvancedParameters() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json + // this example is just showing the usage of "PolicyDefinitions_CreateOrUpdate" 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 SubscriptionPolicyDefinitionResource created on azure + // for more information of creating SubscriptionPolicyDefinitionResource, please refer to the document of SubscriptionPolicyDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyDefinitionName = "EventHubDiagnosticLogs"; + ResourceIdentifier subscriptionPolicyDefinitionResourceId = SubscriptionPolicyDefinitionResource.CreateResourceIdentifier(subscriptionId, policyDefinitionName); + SubscriptionPolicyDefinitionResource subscriptionPolicyDefinition = client.GetSubscriptionPolicyDefinitionResource(subscriptionPolicyDefinitionResourceId); + + // invoke the operation + PolicyDefinitionData data = new PolicyDefinitionData() + { + Mode = "Indexed", + DisplayName = "Event Hubs should have diagnostic logging enabled", + Description = "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised", + PolicyRule = BinaryData.FromObjectAsJson(new Dictionary() + { + ["if"] = new Dictionary() + { + ["equals"] = "Microsoft.EventHub/namespaces", + ["field"] = "type" + }, + ["then"] = new Dictionary() + { + ["effect"] = "AuditIfNotExists", + ["details"] = new Dictionary() + { + ["type"] = "Microsoft.Insights/diagnosticSettings", + ["existenceCondition"] = new Dictionary() + { + ["allOf"] = new object[] { new Dictionary() +{ +["equals"] = "true", +["field"] = "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled"}, new Dictionary() +{ +["equals"] = "[parameters('requiredRetentionDays')]", +["field"] = "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days"} } + } + } + } + }), + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Event Hub" + }), + Parameters = +{ +["requiredRetentionDays"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.Integer, +AllowedValues = +{ +BinaryData.FromString("0"),BinaryData.FromString("30"),BinaryData.FromString("90"),BinaryData.FromString("180"),BinaryData.FromString("365") +}, +DefaultValue = BinaryData.FromString("365"), +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Required retention (days)", +Description = "The required diagnostic logs retention in days", +}, +}, +}, + }; + ArmOperation lro = await subscriptionPolicyDefinition.UpdateAsync(WaitUntil.Completed, data); + SubscriptionPolicyDefinitionResource 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Delete a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_Delete" 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 SubscriptionPolicyDefinitionResource created on azure + // for more information of creating SubscriptionPolicyDefinitionResource, please refer to the document of SubscriptionPolicyDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier subscriptionPolicyDefinitionResourceId = SubscriptionPolicyDefinitionResource.CreateResourceIdentifier(subscriptionId, policyDefinitionName); + SubscriptionPolicyDefinitionResource subscriptionPolicyDefinition = client.GetSubscriptionPolicyDefinitionResource(subscriptionPolicyDefinitionResourceId); + + // invoke the operation + await subscriptionPolicyDefinition.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Retrieve a policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_Get" 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 SubscriptionPolicyDefinitionResource created on azure + // for more information of creating SubscriptionPolicyDefinitionResource, please refer to the document of SubscriptionPolicyDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policyDefinitionName = "ResourceNaming"; + ResourceIdentifier subscriptionPolicyDefinitionResourceId = SubscriptionPolicyDefinitionResource.CreateResourceIdentifier(subscriptionId, policyDefinitionName); + SubscriptionPolicyDefinitionResource subscriptionPolicyDefinition = client.GetSubscriptionPolicyDefinitionResource(subscriptionPolicyDefinitionResourceId); + + // invoke the operation + SubscriptionPolicyDefinitionResource result = await subscriptionPolicyDefinition.GetAsync(); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionCollection.cs new file mode 100644 index 0000000000000..8b30ba94b45b3 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionCollection.cs @@ -0,0 +1,293 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionPolicySetDefinitionCollection + { + // Create or update a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdate" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicySetDefinitionResource + SubscriptionPolicySetDefinitionCollection collection = subscription.GetSubscriptionPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + Parameters = +{ +["namePrefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +DefaultValue = BinaryData.FromString("myPrefix"), +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix to enforce on resource names", +}, +}, +}, + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("[parameters('namePrefix')]"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policySetDefinitionName, data); + SubscriptionPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy set definition with groups + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_CreateOrUpdateAPolicySetDefinitionWithGroups() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdate" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicySetDefinitionResource + SubscriptionPolicySetDefinitionCollection collection = subscription.GetSubscriptionPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +GroupNames = +{ +"CostSaving" +}, +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +GroupNames = +{ +"Organizational" +}, +} +}, + PolicyDefinitionGroups = +{ +new PolicyDefinitionGroup("CostSaving") +{ +DisplayName = "Cost Management Policies", +Description = "Policies designed to control spend within a subscription.", +},new PolicyDefinitionGroup("Organizational") +{ +DisplayName = "Organizational Policies", +Description = "Policies that help enforce resource organization standards within a subscription.", +} +}, + }; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policySetDefinitionName, data); + SubscriptionPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicySetDefinitionResource + SubscriptionPolicySetDefinitionCollection collection = subscription.GetSubscriptionPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + SubscriptionPolicySetDefinitionResource result = await collection.GetAsync(policySetDefinitionName); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicySetDefinitionResource + SubscriptionPolicySetDefinitionCollection collection = subscription.GetSubscriptionPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "CostManagement"; + bool result = await collection.ExistsAsync(policySetDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List policy set definitions + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListPolicySetDefinitions() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitions.json + // this example is just showing the usage of "PolicySetDefinitions_List" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // get the collection of this SubscriptionPolicySetDefinitionResource + SubscriptionPolicySetDefinitionCollection collection = subscription.GetSubscriptionPolicySetDefinitions(); + + // invoke the operation and iterate over the result + await foreach (SubscriptionPolicySetDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicySetDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionResource.cs new file mode 100644 index 0000000000000..10fee32c65d52 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionPolicySetDefinitionResource.cs @@ -0,0 +1,246 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionPolicySetDefinitionResource + { + // Create or update a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdate" 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 SubscriptionPolicySetDefinitionResource created on azure + // for more information of creating SubscriptionPolicySetDefinitionResource, please refer to the document of SubscriptionPolicySetDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier subscriptionPolicySetDefinitionResourceId = SubscriptionPolicySetDefinitionResource.CreateResourceIdentifier(subscriptionId, policySetDefinitionName); + SubscriptionPolicySetDefinitionResource subscriptionPolicySetDefinition = client.GetSubscriptionPolicySetDefinitionResource(subscriptionPolicySetDefinitionResourceId); + + // invoke the operation + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + Parameters = +{ +["namePrefix"] = new ArmPolicyParameter() +{ +ParameterType = ArmPolicyParameterType.String, +DefaultValue = BinaryData.FromString("myPrefix"), +Metadata = new ParameterDefinitionsValueMetadata() +{ +DisplayName = "Prefix to enforce on resource names", +}, +}, +}, + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("[parameters('namePrefix')]"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +} +}, + }; + ArmOperation lro = await subscriptionPolicySetDefinition.UpdateAsync(WaitUntil.Completed, data); + SubscriptionPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Create or update a policy set definition with groups + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_CreateOrUpdateAPolicySetDefinitionWithGroups() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json + // this example is just showing the usage of "PolicySetDefinitions_CreateOrUpdate" 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 SubscriptionPolicySetDefinitionResource created on azure + // for more information of creating SubscriptionPolicySetDefinitionResource, please refer to the document of SubscriptionPolicySetDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier subscriptionPolicySetDefinitionResourceId = SubscriptionPolicySetDefinitionResource.CreateResourceIdentifier(subscriptionId, policySetDefinitionName); + SubscriptionPolicySetDefinitionResource subscriptionPolicySetDefinition = client.GetSubscriptionPolicySetDefinitionResource(subscriptionPolicySetDefinitionResourceId); + + // invoke the operation + PolicySetDefinitionData data = new PolicySetDefinitionData() + { + DisplayName = "Cost Management", + Description = "Policies to enforce low cost storage SKUs", + Metadata = BinaryData.FromObjectAsJson(new Dictionary() + { + ["category"] = "Cost Management" + }), + PolicyDefinitions = +{ +new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1") +{ +Parameters = +{ +["listOfAllowedSKUs"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromObjectAsJson(new object[] { "Standard_GRS", "Standard_LRS" }), +}, +}, +PolicyDefinitionReferenceId = "Limit_Skus", +GroupNames = +{ +"CostSaving" +}, +},new PolicyDefinitionReference("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming") +{ +Parameters = +{ +["prefix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("DeptA"), +}, +["suffix"] = new ArmPolicyParameterValue() +{ +Value = BinaryData.FromString("-LC"), +}, +}, +PolicyDefinitionReferenceId = "Resource_Naming", +GroupNames = +{ +"Organizational" +}, +} +}, + PolicyDefinitionGroups = +{ +new PolicyDefinitionGroup("CostSaving") +{ +DisplayName = "Cost Management Policies", +Description = "Policies designed to control spend within a subscription.", +},new PolicyDefinitionGroup("Organizational") +{ +DisplayName = "Organizational Policies", +Description = "Policies that help enforce resource organization standards within a subscription.", +} +}, + }; + ArmOperation lro = await subscriptionPolicySetDefinition.UpdateAsync(WaitUntil.Completed, data); + SubscriptionPolicySetDefinitionResource 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Delete a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_Delete" 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 SubscriptionPolicySetDefinitionResource created on azure + // for more information of creating SubscriptionPolicySetDefinitionResource, please refer to the document of SubscriptionPolicySetDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier subscriptionPolicySetDefinitionResourceId = SubscriptionPolicySetDefinitionResource.CreateResourceIdentifier(subscriptionId, policySetDefinitionName); + SubscriptionPolicySetDefinitionResource subscriptionPolicySetDefinition = client.GetSubscriptionPolicySetDefinitionResource(subscriptionPolicySetDefinitionResourceId); + + // invoke the operation + await subscriptionPolicySetDefinition.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Retrieve a policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveAPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_Get" 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 SubscriptionPolicySetDefinitionResource created on azure + // for more information of creating SubscriptionPolicySetDefinitionResource, please refer to the document of SubscriptionPolicySetDefinitionResource + string subscriptionId = "ae640e6b-ba3e-4256-9d62-2993eecfa6f2"; + string policySetDefinitionName = "CostManagement"; + ResourceIdentifier subscriptionPolicySetDefinitionResourceId = SubscriptionPolicySetDefinitionResource.CreateResourceIdentifier(subscriptionId, policySetDefinitionName); + SubscriptionPolicySetDefinitionResource subscriptionPolicySetDefinition = client.GetSubscriptionPolicySetDefinitionResource(subscriptionPolicySetDefinitionResourceId); + + // invoke the operation + SubscriptionPolicySetDefinitionResource result = await subscriptionPolicySetDefinition.GetAsync(); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs new file mode 100644 index 0000000000000..7113f07c91269 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_SubscriptionResource + { + // GetLocationsWithASubscriptionId + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetLocations_GetLocationsWithASubscriptionId() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetLocations.json + // this example is just showing the usage of "Subscriptions_ListLocations" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation and iterate over the result + await foreach (LocationExpanded item in subscription.GetLocationsAsync()) + { + Console.WriteLine($"Succeeded: {item}"); + } + + Console.WriteLine($"Succeeded"); + } + + // GetLocationsWithExtendedLocations + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetLocations_GetLocationsWithExtendedLocations() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetLocationsWithExtendedLocations.json + // this example is just showing the usage of "Subscriptions_ListLocations" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation and iterate over the result + bool? includeExtendedLocations = true; + await foreach (LocationExpanded item in subscription.GetLocationsAsync(includeExtendedLocations: includeExtendedLocations)) + { + Console.WriteLine($"Succeeded: {item}"); + } + + Console.WriteLine($"Succeeded"); + } + + // GetASingleSubscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetASingleSubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // this example is just showing the usage of "Subscriptions_Get" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation + SubscriptionResource result = await subscription.GetAsync(); + + // 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 + SubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // List subscription Features + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetFeatures_ListSubscriptionFeatures() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listSubscriptionFeatures.json + // this example is just showing the usage of "Features_ListAll" 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 SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "subid"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation and iterate over the result + await foreach (FeatureResource item in subscription.GetFeaturesAsync()) + { + // the variable item 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 + FeatureData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TagResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TagResource.cs new file mode 100644 index 0000000000000..d28f9307f7bd0 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TagResource.cs @@ -0,0 +1,283 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TagResource + { + // Update tags on a resource + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_UpdateTagsOnAResource() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutTagsResource.json + // this example is just showing the usage of "Tags_CreateOrUpdateAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResourceData data = new TagResourceData(new Tag() + { + TagValues = +{ +["tagKey1"] = "tag-value-1", +["tagKey2"] = "tag-value-2", +}, + }); + ArmOperation lro = await tagResource.CreateOrUpdateAsync(WaitUntil.Completed, data); + TagResource 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update tags on a subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_UpdateTagsOnASubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PutTagsSubscription.json + // this example is just showing the usage of "Tags_CreateOrUpdateAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResourceData data = new TagResourceData(new Tag() + { + TagValues = +{ +["tagKey1"] = "tag-value-1", +["tagKey2"] = "tag-value-2", +}, + }); + ArmOperation lro = await tagResource.CreateOrUpdateAsync(WaitUntil.Completed, data); + TagResource 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update tags on a resource + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateTagsOnAResource() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PatchTagsResource.json + // this example is just showing the usage of "Tags_UpdateAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResourcePatch patch = new TagResourcePatch() + { + PatchMode = TagPatchMode.Replace, + TagValues = +{ +["tagKey1"] = "tag-value-1", +["tagKey2"] = "tag-value-2", +}, + }; + ArmOperation lro = await tagResource.UpdateAsync(WaitUntil.Completed, patch); + TagResource 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update tags on a subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_UpdateTagsOnASubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/PatchTagsSubscription.json + // this example is just showing the usage of "Tags_UpdateAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResourcePatch patch = new TagResourcePatch() + { + PatchMode = TagPatchMode.Replace, + TagValues = +{ +["tagKey1"] = "tag-value-1", +["tagKey2"] = "tag-value-2", +}, + }; + ArmOperation lro = await tagResource.UpdateAsync(WaitUntil.Completed, patch); + TagResource 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get tags on a resource + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetTagsOnAResource() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetTagsResource.json + // this example is just showing the usage of "Tags_GetAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResource result = await tagResource.GetAsync(); + + // 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Get tags on a subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetTagsOnASubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetTagsSubscription.json + // this example is just showing the usage of "Tags_GetAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + TagResource result = await tagResource.GetAsync(); + + // 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 + TagResourceData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Update tags on a resource + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_UpdateTagsOnAResource() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/DeleteTagsResource.json + // this example is just showing the usage of "Tags_DeleteAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + await tagResource.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + + // Update tags on a subscription + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_UpdateTagsOnASubscription() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/DeleteTagsSubscription.json + // this example is just showing the usage of "Tags_DeleteAtScope" 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 TagResource created on azure + // for more information of creating TagResource, please refer to the document of TagResource + string scope = "subscriptions/00000000-0000-0000-0000-000000000000"; + ResourceIdentifier tagResourceId = TagResource.CreateResourceIdentifier(scope); + TagResource tagResource = client.GetTagResource(tagResourceId); + + // invoke the operation + await tagResource.DeleteAsync(WaitUntil.Completed); + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs new file mode 100644 index 0000000000000..3ac7b7353473d --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantCollection + { + // GetAllTenants + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_GetAllTenants() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetTenants.json + // this example is just showing the usage of "Tenants_List" 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); + + TenantCollection collection = client.GetTenants(); + + // invoke the operation and iterate over the result + await foreach (TenantResource item in collection.GetAllAsync()) + { + // the variable item 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 + TenantData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionCollection.cs new file mode 100644 index 0000000000000..4c02b00e92931 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionCollection.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantPolicyDefinitionCollection + { + // Retrieve a built-in policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveABuiltInPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_GetBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicyDefinitionResource + TenantPolicyDefinitionCollection collection = tenant.GetTenantPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; + TenantPolicyDefinitionResource result = await collection.GetAsync(policyDefinitionName); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a built-in policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveABuiltInPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_GetBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicyDefinitionResource + TenantPolicyDefinitionCollection collection = tenant.GetTenantPolicyDefinitions(); + + // invoke the operation + string policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; + bool result = await collection.ExistsAsync(policyDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List built-in policy definitions + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListBuiltInPolicyDefinitions() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicyDefinitions.json + // this example is just showing the usage of "PolicyDefinitions_ListBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicyDefinitionResource + TenantPolicyDefinitionCollection collection = tenant.GetTenantPolicyDefinitions(); + + // invoke the operation and iterate over the result + await foreach (TenantPolicyDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicyDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionResource.cs new file mode 100644 index 0000000000000..1559817e71585 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicyDefinitionResource.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantPolicyDefinitionResource + { + // Retrieve a built-in policy definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveABuiltInPolicyDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json + // this example is just showing the usage of "PolicyDefinitions_GetBuiltIn" 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 TenantPolicyDefinitionResource created on azure + // for more information of creating TenantPolicyDefinitionResource, please refer to the document of TenantPolicyDefinitionResource + string policyDefinitionName = "7433c107-6db4-4ad1-b57a-a76dce0154a1"; + ResourceIdentifier tenantPolicyDefinitionResourceId = TenantPolicyDefinitionResource.CreateResourceIdentifier(policyDefinitionName); + TenantPolicyDefinitionResource tenantPolicyDefinition = client.GetTenantPolicyDefinitionResource(tenantPolicyDefinitionResourceId); + + // invoke the operation + TenantPolicyDefinitionResource result = await tenantPolicyDefinition.GetAsync(); + + // 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 + PolicyDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionCollection.cs new file mode 100644 index 0000000000000..ee2d77f202f34 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionCollection.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantPolicySetDefinitionCollection + { + // Retrieve a built-in policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveABuiltInPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_GetBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicySetDefinitionResource + TenantPolicySetDefinitionCollection collection = tenant.GetTenantPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; + TenantPolicySetDefinitionResource result = await collection.GetAsync(policySetDefinitionName); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // Retrieve a built-in policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_RetrieveABuiltInPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_GetBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicySetDefinitionResource + TenantPolicySetDefinitionCollection collection = tenant.GetTenantPolicySetDefinitions(); + + // invoke the operation + string policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; + bool result = await collection.ExistsAsync(policySetDefinitionName); + + Console.WriteLine($"Succeeded: {result}"); + } + + // List built-in policy set definitions + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_ListBuiltInPolicySetDefinitions() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicySetDefinitions.json + // this example is just showing the usage of "PolicySetDefinitions_ListBuiltIn" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // get the collection of this TenantPolicySetDefinitionResource + TenantPolicySetDefinitionCollection collection = tenant.GetTenantPolicySetDefinitions(); + + // invoke the operation and iterate over the result + await foreach (TenantPolicySetDefinitionResource item in collection.GetAllAsync()) + { + // the variable item 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 + PolicySetDefinitionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionResource.cs new file mode 100644 index 0000000000000..7e8c5956176c6 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantPolicySetDefinitionResource.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantPolicySetDefinitionResource + { + // Retrieve a built-in policy set definition + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_RetrieveABuiltInPolicySetDefinition() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json + // this example is just showing the usage of "PolicySetDefinitions_GetBuiltIn" 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 TenantPolicySetDefinitionResource created on azure + // for more information of creating TenantPolicySetDefinitionResource, please refer to the document of TenantPolicySetDefinitionResource + string policySetDefinitionName = "1f3afdf9-d0c9-4c3d-847f-89da613e70a8"; + ResourceIdentifier tenantPolicySetDefinitionResourceId = TenantPolicySetDefinitionResource.CreateResourceIdentifier(policySetDefinitionName); + TenantPolicySetDefinitionResource tenantPolicySetDefinition = client.GetTenantPolicySetDefinitionResource(tenantPolicySetDefinitionResourceId); + + // invoke the operation + TenantPolicySetDefinitionResource result = await tenantPolicySetDefinition.GetAsync(); + + // 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 + PolicySetDefinitionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantResource.cs new file mode 100644 index 0000000000000..f4f5d4fd7a9d7 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantResource.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Resources.Models; + +namespace Azure.ResourceManager.Resources.Samples +{ + public partial class Sample_TenantResource + { + // Get a resource provider at tenant scope + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetTenantResourceProvider_GetAResourceProviderAtTenantScope() + { + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-09-01/examples/GetNamedProviderAtTenant.json + // this example is just showing the usage of "Providers_GetAtTenantScope" 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 TenantResource created on azure + // for more information of creating TenantResource, please refer to the document of TenantResource + var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current; + + // invoke the operation + string resourceProviderNamespace = "Microsoft.Storage"; + string expand = "resourceTypes/aliases"; + TenantResourceProvider result = await tenant.GetTenantResourceProviderAsync(resourceProviderNamespace, expand: expand); + + Console.WriteLine($"Succeeded: {result}"); + } + } +} From 148299fc9e410ee8c1f6b74e9878f466b3acf68a Mon Sep 17 00:00:00 2001 From: Rodge Fu Date: Thu, 20 Jul 2023 18:18:49 +0800 Subject: [PATCH 2/2] update sample --- .../generated/Samples/Sample_SubscriptionCollection.cs | 6 +++--- .../generated/Samples/Sample_SubscriptionResource.cs | 10 +++++----- .../generated/Samples/Sample_TenantCollection.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs index 8b0de1b93e296..944538b304841 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionCollection.cs @@ -21,7 +21,7 @@ public partial class Sample_SubscriptionCollection [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task Get_GetASingleSubscription() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetSubscription.json // this example is just showing the usage of "Subscriptions_Get" 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 @@ -52,7 +52,7 @@ public async Task Get_GetASingleSubscription() [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task Exists_GetASingleSubscription() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetSubscription.json // this example is just showing the usage of "Subscriptions_Get" 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 @@ -79,7 +79,7 @@ public async Task Exists_GetASingleSubscription() [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task GetAll_GetAllSubscriptions() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscriptions.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetSubscriptions.json // this example is just showing the usage of "Subscriptions_List" 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 diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs index 7113f07c91269..988296e68a979 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_SubscriptionResource.cs @@ -22,7 +22,7 @@ public partial class Sample_SubscriptionResource [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task GetLocations_GetLocationsWithASubscriptionId() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetLocations.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetLocations.json // this example is just showing the usage of "Subscriptions_ListLocations" 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 @@ -32,7 +32,7 @@ public async Task GetLocations_GetLocationsWithASubscriptionId() // this example assumes you already have this SubscriptionResource created on azure // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource - string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + string subscriptionId = "a1ffc958-d2c7-493e-9f1e-125a0477f536"; ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); @@ -50,7 +50,7 @@ public async Task GetLocations_GetLocationsWithASubscriptionId() [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task GetLocations_GetLocationsWithExtendedLocations() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetLocationsWithExtendedLocations.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetLocationsWithExtendedLocations.json // this example is just showing the usage of "Subscriptions_ListLocations" 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 @@ -60,7 +60,7 @@ public async Task GetLocations_GetLocationsWithExtendedLocations() // this example assumes you already have this SubscriptionResource created on azure // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource - string subscriptionId = "291bba3f-e0a5-47bc-a099-3bdcb2a50a05"; + string subscriptionId = "a1ffc958-d2c7-493e-9f1e-125a0477f536"; ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); SubscriptionResource subscription = client.GetSubscriptionResource(subscriptionResourceId); @@ -79,7 +79,7 @@ public async Task GetLocations_GetLocationsWithExtendedLocations() [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task Get_GetASingleSubscription() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetSubscription.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetSubscription.json // this example is just showing the usage of "Subscriptions_Get" 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 diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs index 3ac7b7353473d..04746f0d6cec3 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/generated/Samples/Sample_TenantCollection.cs @@ -21,7 +21,7 @@ public partial class Sample_TenantCollection [NUnit.Framework.Ignore("Only verifying that the sample builds")] public async Task GetAll_GetAllTenants() { - // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2021-01-01/examples/GetTenants.json + // Generated from example definition: specification/resources/resource-manager/Microsoft.Resources/stable/2022-12-01/examples/GetTenants.json // this example is just showing the usage of "Tenants_List" 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