From b135b8c3df8f244b21071aee0ef3e7aac936f100 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 25 Sep 2024 21:32:01 +1000 Subject: [PATCH 01/33] SDK dir structure --- sdk/resourcemanager/ci.mgmt.yml | 2 + .../Azure.ResourceManager.Terraform.sln | 65 +++++++++++++++ .../CHANGELOG.md | 19 +++++ .../Directory.Build.props | 6 ++ .../Azure.ResourceManager.Terraform/README.md | 80 +++++++++++++++++++ .../assets.json | 6 ++ ...e.ResourceManager.Terraform.Samples.csproj | 10 +++ .../Azure.ResourceManager.Terraform.csproj | 8 ++ .../src/Properties/AssemblyInfo.cs | 9 +++ ...ure.ResourceManager.Terraform.Tests.csproj | 5 ++ .../tests/terraformManagementTestBase.cs | 43 ++++++++++ .../terraformManagementTestEnvironment.cs | 11 +++ .../tsp-location.yaml | 3 + sdk/terraform/ci.mgmt.yml | 23 ++++++ 14 files changed, 290 insertions(+) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/Azure.ResourceManager.Terraform.sln create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/Directory.Build.props create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/README.md create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/assets.json create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/samples/Azure.ResourceManager.Terraform.Samples.csproj create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Azure.ResourceManager.Terraform.csproj create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Properties/AssemblyInfo.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/Azure.ResourceManager.Terraform.Tests.csproj create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml create mode 100644 sdk/terraform/ci.mgmt.yml diff --git a/sdk/resourcemanager/ci.mgmt.yml b/sdk/resourcemanager/ci.mgmt.yml index d0b6b524e8744..30235df2405c1 100644 --- a/sdk/resourcemanager/ci.mgmt.yml +++ b/sdk/resourcemanager/ci.mgmt.yml @@ -192,6 +192,7 @@ trigger: - sdk/subscription/Azure.ResourceManager.Subscription - sdk/support/Azure.ResourceManager.Support - sdk/synapse/Azure.ResourceManager.Synapse + - sdk/terraform/Azure.ResourceManager.Terraform - sdk/trafficmanager/Azure.ResourceManager.TrafficManager - sdk/trustedsigning/Azure.ResourceManager.TrustedSigning - sdk/voiceservices/Azure.ResourceManager.VoiceServices @@ -393,6 +394,7 @@ pr: - sdk/subscription/Azure.ResourceManager.Subscription - sdk/support/Azure.ResourceManager.Support - sdk/synapse/Azure.ResourceManager.Synapse + - sdk/terraform/Azure.ResourceManager.Terraform - sdk/trafficmanager/Azure.ResourceManager.TrafficManager - sdk/trustedsigning/Azure.ResourceManager.TrustedSigning - sdk/voiceservices/Azure.ResourceManager.VoiceServices diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/Azure.ResourceManager.Terraform.sln b/sdk/terraform/Azure.ResourceManager.Terraform/Azure.ResourceManager.Terraform.sln new file mode 100644 index 0000000000000..0fdcc0b1d313f --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/Azure.ResourceManager.Terraform.sln @@ -0,0 +1,65 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{57104F4E-33D2-4712-89D0-35A4165C1BA1}") = "Azure.ResourceManager.Terraform", "src\Azure.ResourceManager.Terraform.csproj", "{3457A0A4-B5E1-4184-8D42-0F1C542217C9}" +EndProject +Project("{57104F4E-33D2-4712-89D0-35A4165C1BA1}") = "Azure.ResourceManager.Terraform.Tests", "tests\Azure.ResourceManager.Terraform.Tests.csproj", "{DC07DC97-58C7-4345-B915-29DF7739ABD5}" +EndProject +Project("{57104F4E-33D2-4712-89D0-35A4165C1BA1}") = "Azure.ResourceManager.Terraform.Samples", "samples\Azure.ResourceManager.Terraform.Samples.csproj", "{0C87CC4B-8863-41FC-8704-20CC6F8A58E1}" +EndProject +Global + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {79ECAB3D-FE5F-4AF2-9214-2D6F13CB7F9C} + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|x64.ActiveCfg = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|x64.Build.0 = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|x86.ActiveCfg = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Debug|x86.Build.0 = Debug|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|Any CPU.Build.0 = Release|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|x64.ActiveCfg = Release|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|x64.Build.0 = Release|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|x86.ActiveCfg = Release|Any CPU + {3457A0A4-B5E1-4184-8D42-0F1C542217C9}.Release|x86.Build.0 = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|x64.ActiveCfg = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|x64.Build.0 = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|x86.ActiveCfg = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Debug|x86.Build.0 = Debug|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|Any CPU.Build.0 = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|x64.ActiveCfg = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|x64.Build.0 = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|x86.ActiveCfg = Release|Any CPU + {DC07DC97-58C7-4345-B915-29DF7739ABD5}.Release|x86.Build.0 = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|x64.ActiveCfg = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|x64.Build.0 = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|x86.ActiveCfg = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Debug|x86.Build.0 = Debug|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|Any CPU.Build.0 = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|x64.ActiveCfg = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|x64.Build.0 = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|x86.ActiveCfg = Release|Any CPU + {0C87CC4B-8863-41FC-8704-20CC6F8A58E1}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md new file mode 100644 index 0000000000000..1a85987a15b9e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md @@ -0,0 +1,19 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + + + +### Features Added + +This package follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: + + - Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. + - Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. + - HTTP pipeline with custom policies. + - Better error-handling. + - Support uniform telemetry across all languages. + +This package is a Public Preview version, so expect incompatible changes in subsequent releases as we improve the product. To provide feedback, submit an issue in our [Azure SDK for .NET GitHub repo](https://github.com/Azure/azure-sdk-for-net/issues). + +> NOTE: For more information about unified authentication, please refer to [Microsoft Azure Identity documentation for .NET](https://docs.microsoft.com//dotnet/api/overview/azure/identity-readme?view=azure-dotnet). \ No newline at end of file diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/Directory.Build.props b/sdk/terraform/Azure.ResourceManager.Terraform/Directory.Build.props new file mode 100644 index 0000000000000..1a9611bd49242 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/README.md b/sdk/terraform/Azure.ResourceManager.Terraform/README.md new file mode 100644 index 0000000000000..6d15453099af0 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/README.md @@ -0,0 +1,80 @@ +# Microsoft Azure terraform management client library for .NET + +**[Describe the service briefly first.]** + +This library follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: + + - Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. + - Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. + - HTTP pipeline with custom policies. + - Better error-handling. + - Support uniform telemetry across all languages. + +## Getting started + +### Install the package + +Install the Microsoft Azure terraform management library for .NET with [NuGet](https://www.nuget.org/): + +```dotnetcli +dotnet add package Azure.ResourceManager.Terraform --prerelease +``` + +### Prerequisites + +* You must have an [Microsoft Azure subscription](https://azure.microsoft.com/free/dotnet/). + +### Authenticate the Client + +To create an authenticated client and start interacting with Microsoft Azure resources, see the [quickstart guide here](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/mgmt_quickstart.md). + +## Key concepts + +Key concepts of the Microsoft Azure SDK for .NET can be found [here](https://azure.github.io/azure-sdk/dotnet_introduction.html) + +## Documentation + +Documentation is available to help you learn how to use this package: + +- [Quickstart](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/mgmt_quickstart.md). +- [API References](https://docs.microsoft.com/dotnet/api/?view=azure-dotnet). +- [Authentication](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md). + +## Examples + +Code samples for using the management library for .NET can be found in the following locations +- [.NET Management Library Code Samples](https://aka.ms/azuresdk-net-mgmt-samples) + +## Troubleshooting + +- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). +- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. + +## Next steps + +For more information about Microsoft Azure SDK, see [this website](https://azure.github.io/azure-sdk/). + +## Contributing + +For details on contributing to this repository, see the [contributing +guide][cg]. + +This project welcomes contributions and suggestions. Most contributions +require you to agree to a Contributor License Agreement (CLA) declaring +that you have the right to, and actually do, grant us the rights to use +your contribution. For details, visit . + +When you submit a pull request, a CLA-bot will automatically determine +whether you need to provide a CLA and decorate the PR appropriately +(for example, label, comment). Follow the instructions provided by the +bot. You'll only need to do this action once across all repositories +using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For +more information, see the [Code of Conduct FAQ][coc_faq] or contact + with any other questions or comments. + + +[cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md +[coc]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ \ No newline at end of file diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json new file mode 100644 index 0000000000000..1e8c0b20696bd --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", + "Tag": "" +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Azure.ResourceManager.Terraform.Samples.csproj b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Azure.ResourceManager.Terraform.Samples.csproj new file mode 100644 index 0000000000000..8d2d95777931e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Azure.ResourceManager.Terraform.Samples.csproj @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Azure.ResourceManager.Terraform.csproj b/sdk/terraform/Azure.ResourceManager.Terraform/src/Azure.ResourceManager.Terraform.csproj new file mode 100644 index 0000000000000..f2dd197dd4a3f --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Azure.ResourceManager.Terraform.csproj @@ -0,0 +1,8 @@ + + + 1.0.0-beta.1 + Azure.ResourceManager.Terraform + Azure Resource Manager client SDK for Azure resource provider terraform. + azure;management;arm;resource manager;terraform + + diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Properties/AssemblyInfo.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000..3c84376af3452 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: Azure.Core.AzureResourceProviderNamespace("terraform")] + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] +[assembly: InternalsVisibleTo("Azure.ResourceManager.Terraform.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")] diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Azure.ResourceManager.Terraform.Tests.csproj b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Azure.ResourceManager.Terraform.Tests.csproj new file mode 100644 index 0000000000000..76dcb524d7731 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Azure.ResourceManager.Terraform.Tests.csproj @@ -0,0 +1,5 @@ + + + + + diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs new file mode 100644 index 0000000000000..85f09319296dc --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.TestFramework; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace Azure.ResourceManager.Terraform.Tests +{ + public class terraformManagementTestBase : ManagementRecordedTestBase + { + protected ArmClient Client { get; private set; } + protected SubscriptionResource DefaultSubscription { get; private set; } + + protected terraformManagementTestBase(bool isAsync, RecordedTestMode mode) + : base(isAsync, mode) + { + } + + protected terraformManagementTestBase(bool isAsync) + : base(isAsync) + { + } + + [SetUp] + public async Task CreateCommonClient() + { + Client = GetArmClient(); + DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); + } + + protected async Task CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location) + { + string rgName = Recording.GenerateAssetName(rgNamePrefix); + ResourceGroupData input = new ResourceGroupData(location); + var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); + return lro.Value; + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs new file mode 100644 index 0000000000000..c4842b3a3611d --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.ResourceManager.Terraform.Tests +{ + public class terraformManagementTestEnvironment : TestEnvironment + { + } +} \ No newline at end of file diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml new file mode 100644 index 0000000000000..5b3aaca417139 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -0,0 +1,3 @@ +directory: sspecification/terraform/Microsoft.AzureTerraform.Management +commit: to-be-specified-when-spec-change-merged +repo: Azure/azure-rest-api-specs diff --git a/sdk/terraform/ci.mgmt.yml b/sdk/terraform/ci.mgmt.yml new file mode 100644 index 0000000000000..82c4c1f05a4c5 --- /dev/null +++ b/sdk/terraform/ci.mgmt.yml @@ -0,0 +1,23 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: none +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/terraform/ci.mgmt.yml + - sdk/terraform/Azure.ResourceManager.Terraform/ + +extends: + template: /eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: terraform + LimitForPullRequest: true + Artifacts: + - name: Azure.ResourceManager.Terraform + safeName: AzureResourceManagerTerraform From c018cd2fc11f6cea1d01c40d39d2124d4e40629b Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 25 Sep 2024 22:51:26 +1000 Subject: [PATCH 02/33] fix typo in spec folder --- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 5b3aaca417139..7a79148b183b5 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ -directory: sspecification/terraform/Microsoft.AzureTerraform.Management +directory: specification/terraform/Microsoft.AzureTerraform.Management commit: to-be-specified-when-spec-change-merged repo: Azure/azure-rest-api-specs From 69b62e671feb6dfd8c4a228583568fc4ce5ded14 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 25 Sep 2024 23:18:37 +1000 Subject: [PATCH 03/33] fixed commit hash in tsp-location.yaml --- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 7a79148b183b5..9009369cc7e63 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: to-be-specified-when-spec-change-merged +commit: befbed40f82c444b19d6aaf5d4ac6bdf50960d54 repo: Azure/azure-rest-api-specs From 4bebbeaf326ac1db0680c62321a4fddaacf9b0e8 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Thu, 26 Sep 2024 09:44:44 +1000 Subject: [PATCH 04/33] Ran dotnet build for code generation --- .../Sample_SubscriptionResourceExtensions.cs | 71 ++++ .../src/Generated/ArmTerraformModelFactory.cs | 57 +++ .../MockableTerraformSubscriptionResource.cs | 218 ++++++++++ .../Extensions/TerraformExtensions.cs | 159 +++++++ .../src/Generated/Internal/Argument.cs | 129 ++++++ .../Internal/ChangeTrackingDictionary.cs | 167 ++++++++ .../Generated/Internal/ChangeTrackingList.cs | 153 +++++++ .../Internal/ModelSerializationExtensions.cs | 398 ++++++++++++++++++ .../src/Generated/Internal/Optional.cs | 51 +++ .../Internal/Utf8JsonRequestContent.cs | 55 +++ .../TerraformArmOperation.cs | 94 +++++ .../Models/BaseExportModel.Serialization.cs | 127 ++++++ .../src/Generated/Models/BaseExportModel.cs | 81 ++++ .../Models/ExportQuery.Serialization.cs | 206 +++++++++ .../src/Generated/Models/ExportQuery.cs | 56 +++ .../Models/ExportResource.Serialization.cs | 224 ++++++++++ .../src/Generated/Models/ExportResource.cs | 61 +++ .../ExportResourceGroup.Serialization.cs | 190 +++++++++ .../Generated/Models/ExportResourceGroup.cs | 52 +++ .../src/Generated/Models/TargetProvider.cs | 51 +++ .../src/Generated/Models/Type.cs | 54 +++ .../UnknownBaseExportModel.Serialization.cs | 164 ++++++++ .../Models/UnknownBaseExportModel.cs | 32 ++ .../src/Generated/ProviderConstants.cs | 16 + .../AzureTerraformRestOperations.cs | 114 +++++ .../OperationStatusesRestOperations.cs | 113 +++++ 26 files changed, 3093 insertions(+) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Argument.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingDictionary.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingList.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ModelSerializationExtensions.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Optional.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Utf8JsonRequestContent.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ProviderConstants.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs new file mode 100644 index 0000000000000..dc8033389113c --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -0,0 +1,71 @@ +// 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.Resources; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform.Samples +{ + public partial class Sample_SubscriptionResourceExtensions + { + // ExportTerraform + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task ExportTerraformAzureTerraformClient_ExportTerraform() + { + // Generated from example definition: 2023-07-01-preview/ExportTerraform.json + // this example is just showing the usage of "AzureTerraform_ExportTerraform" 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 subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation + BaseExportModel exportParameter = new ExportResourceGroup("rg1"); + await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); + + Console.WriteLine($"Succeeded"); + } + + // Get specific operation status + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetOperationStatus_GetSpecificOperationStatus() + { + // Generated from example definition: 2023-07-01-preview/GetOperationStatus.json + // this example is just showing the usage of "OperationStatuses_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 subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation + string operationId = "00000000-0000-0000-0000-000000000000"; + await subscriptionResource.GetOperationStatusAsync(WaitUntil.Completed, operationId); + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs new file mode 100644 index 0000000000000..7edb13e0991cf --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// Model factory for models. + public static partial class ArmTerraformModelFactory + { + /// Initializes a new instance of . + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + /// The name pattern of the Terraform resources. + /// Whether to recursively list child resources of the query result. + /// A new instance for mocking. + public static ExportQuery ExportQuery(TargetProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) + { + return new ExportQuery( + Type.ExportQuery, + targetProvider, + fullProperties, + maskSensitive, + serializedAdditionalRawData: null, + query, + namePattern, + recursive); + } + + /// Initializes a new instance of . + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// The name of the resource group to be exported. + /// The name pattern of the Terraform resources. + /// A new instance for mocking. + public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) + { + return new ExportResourceGroup( + Type.ExportResourceGroup, + targetProvider, + fullProperties, + maskSensitive, + serializedAdditionalRawData: null, + resourceGroupName, + namePattern); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs new file mode 100644 index 0000000000000..f5bc24668b1c2 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -0,0 +1,218 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform.Mocking +{ + /// A class to add extension methods to SubscriptionResource. + public partial class MockableTerraformSubscriptionResource : ArmResource + { + private ClientDiagnostics _azureTerraformClientClientDiagnostics; + private AzureTerraformRestOperations _azureTerraformClientRestClient; + private ClientDiagnostics _operationStatusesClientDiagnostics; + private OperationStatusesRestOperations _operationStatusesRestClient; + + /// Initializes a new instance of the class for mocking. + protected MockableTerraformSubscriptionResource() + { + } + + /// Initializes a new instance of the class. + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + internal MockableTerraformSubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + } + + private ClientDiagnostics AzureTerraformClientClientDiagnostics => _azureTerraformClientClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); + private AzureTerraformRestOperations AzureTerraformClientRestClient => _azureTerraformClientRestClient ??= new AzureTerraformRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); + private ClientDiagnostics OperationStatusesClientDiagnostics => _operationStatusesClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); + private OperationStatusesRestOperations OperationStatusesRestClient => _operationStatusesRestClient ??= new OperationStatusesRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); + + private string GetApiVersionOrNull(ResourceType resourceType) + { + TryGetApiVersion(resourceType, out string apiVersion); + return apiVersion; + } + + /// + /// Exports the Terraform configuration of the specified resource(s). + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/exportTerraform + /// + /// + /// Operation Id + /// AzureTerraform_ExportTerraform + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The export parameter. + /// The cancellation token to use. + /// is null. + public virtual async Task ExportTerraformAzureTerraformClientAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + + using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraformAzureTerraformClient"); + scope.Start(); + try + { + var response = await AzureTerraformClientRestClient.ExportTerraformAsync(Id.SubscriptionId, exportParameter, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Exports the Terraform configuration of the specified resource(s). + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/exportTerraform + /// + /// + /// Operation Id + /// AzureTerraform_ExportTerraform + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The export parameter. + /// The cancellation token to use. + /// is null. + public virtual ArmOperation ExportTerraformAzureTerraformClient(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + + using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraformAzureTerraformClient"); + scope.Start(); + try + { + var response = AzureTerraformClientRestClient.ExportTerraform(Id.SubscriptionId, exportParameter, cancellationToken); + var operation = new TerraformArmOperation(AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletionResponse(cancellationToken); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Get the status of a long running azure asynchronous operation. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} + /// + /// + /// Operation Id + /// OperationStatuses_Get + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The ID of an ongoing async operation. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual async Task GetOperationStatusAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + + using var scope = OperationStatusesClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.GetOperationStatus"); + scope.Start(); + try + { + var response = await OperationStatusesRestClient.GetAsync(operationId, Id.SubscriptionId, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(OperationStatusesClientDiagnostics, Pipeline, OperationStatusesRestClient.CreateGetRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Get the status of a long running azure asynchronous operation. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} + /// + /// + /// Operation Id + /// OperationStatuses_Get + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The ID of an ongoing async operation. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual ArmOperation GetOperationStatus(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + + using var scope = OperationStatusesClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.GetOperationStatus"); + scope.Start(); + try + { + var response = OperationStatusesRestClient.Get(operationId, Id.SubscriptionId, cancellationToken); + var operation = new TerraformArmOperation(OperationStatusesClientDiagnostics, Pipeline, OperationStatusesRestClient.CreateGetRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletionResponse(cancellationToken); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs new file mode 100644 index 0000000000000..a479ff9e3a36e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Terraform.Mocking; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform +{ + /// A class to add extension methods to Azure.ResourceManager.Terraform. + public static partial class TerraformExtensions + { + private static MockableTerraformSubscriptionResource GetMockableTerraformSubscriptionResource(ArmResource resource) + { + return resource.GetCachedClient(client => new MockableTerraformSubscriptionResource(client, resource.Id)); + } + + /// + /// Exports the Terraform configuration of the specified resource(s). + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/exportTerraform + /// + /// + /// Operation Id + /// AzureTerraform_ExportTerraform + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The export parameter. + /// The cancellation token to use. + /// or is null. + public static async Task ExportTerraformAzureTerraformClientAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAzureTerraformClientAsync(waitUntil, exportParameter, cancellationToken).ConfigureAwait(false); + } + + /// + /// Exports the Terraform configuration of the specified resource(s). + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/exportTerraform + /// + /// + /// Operation Id + /// AzureTerraform_ExportTerraform + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The export parameter. + /// The cancellation token to use. + /// or is null. + public static ArmOperation ExportTerraformAzureTerraformClient(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAzureTerraformClient(waitUntil, exportParameter, cancellationToken); + } + + /// + /// Get the status of a long running azure asynchronous operation. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} + /// + /// + /// Operation Id + /// OperationStatuses_Get + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The ID of an ongoing async operation. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// or is null. + public static async Task GetOperationStatusAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return await GetMockableTerraformSubscriptionResource(subscriptionResource).GetOperationStatusAsync(waitUntil, operationId, cancellationToken).ConfigureAwait(false); + } + + /// + /// Get the status of a long running azure asynchronous operation. + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} + /// + /// + /// Operation Id + /// OperationStatuses_Get + /// + /// + /// Default Api Version + /// 2023-07-01-preview + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// The ID of an ongoing async operation. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// or is null. + public static ArmOperation GetOperationStatus(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return GetMockableTerraformSubscriptionResource(subscriptionResource).GetOperationStatus(waitUntil, operationId, cancellationToken); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Argument.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Argument.cs new file mode 100644 index 0000000000000..2cbf70c62fe1e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Argument.cs @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform +{ + internal static class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingDictionary.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 0000000000000..975398aa4c203 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform +{ + internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingList.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 0000000000000..3060ed9470d2c --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Terraform +{ + internal class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ModelSerializationExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 0000000000000..763bd6f7f9977 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,398 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; +using System.Xml; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform +{ + internal static class ModelSerializationExtensions + { + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + var text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + { + throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + var value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case IUtf8JsonSerializable serializable: + serializable.Write(writer); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + + internal static class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Azure SDK requires it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; + int size = checked(numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Optional.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Optional.cs new file mode 100644 index 0000000000000..3eceaa43bffe6 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Optional.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Azure.ResourceManager.Terraform +{ + internal static class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + + public static bool IsDefined(string value) + { + return value != null; + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Utf8JsonRequestContent.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Utf8JsonRequestContent.cs new file mode 100644 index 0000000000000..dcad4261c64d2 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Internal/Utf8JsonRequestContent.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform +{ + internal class Utf8JsonRequestContent : RequestContent + { + private readonly MemoryStream _stream; + private readonly RequestContent _content; + + public Utf8JsonRequestContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs new file mode 100644 index 0000000000000..727a5af30d57f --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ +#pragma warning disable SA1649 // File name should match first type name + internal class TerraformArmOperation : ArmOperation +#pragma warning restore SA1649 // File name should match first type name + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of TerraformArmOperation for mocking. + protected TerraformArmOperation() + { + } + + internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + internal TerraformArmOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) + { + _nextLinkOperation = nextLinkOperationValue; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal(nextLinkOperation, clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); + } + + private string GetOperationId(RehydrationToken? rehydrationToken) + { + if (rehydrationToken is null) + { + return null; + } + var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); + return lroDetails["id"]; + } + /// + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override bool HasCompleted => _operation.HasCompleted; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletionResponse(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(cancellationToken); + + /// + public override Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken); + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs new file mode 100644 index 0000000000000..d37b80af3d1a2 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs @@ -0,0 +1,127 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + [PersistableModelProxy(typeof(UnknownBaseExportModel))] + public partial class BaseExportModel : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(TargetProvider)) + { + writer.WritePropertyName("targetProvider"u8); + writer.WriteStringValue(TargetProvider.Value.ToString()); + } + if (Optional.IsDefined(FullProperties)) + { + writer.WritePropertyName("fullProperties"u8); + writer.WriteBooleanValue(FullProperties.Value); + } + if (Optional.IsDefined(MaskSensitive)) + { + writer.WritePropertyName("maskSensitive"u8); + writer.WriteBooleanValue(MaskSensitive.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeBaseExportModel(document.RootElement, options); + } + + internal static BaseExportModel DeserializeBaseExportModel(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "ExportQuery": return ExportQuery.DeserializeExportQuery(element, options); + case "ExportResource": return ExportResource.DeserializeExportResource(element, options); + case "ExportResourceGroup": return ExportResourceGroup.DeserializeExportResourceGroup(element, options); + } + } + return UnknownBaseExportModel.DeserializeUnknownBaseExportModel(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{options.Format}' format."); + } + } + + BaseExportModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeBaseExportModel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs new file mode 100644 index 0000000000000..a14d8c7b4642e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// + /// The base export parameter + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// The available derived classes include , and . + /// + public abstract partial class BaseExportModel + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private protected IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + protected BaseExportModel() + { + } + + /// Initializes a new instance of . + /// The parameter type. + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// Keeps track of any properties unknown to the library. + internal BaseExportModel(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) + { + Type = type; + TargetProvider = targetProvider; + FullProperties = fullProperties; + MaskSensitive = maskSensitive; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The parameter type. + internal Type Type { get; set; } + /// The target Azure Terraform Provider. + public TargetProvider? TargetProvider { get; set; } + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + public bool? FullProperties { get; set; } + /// Mask sensitive attributes in the Terraform configuration. + public bool? MaskSensitive { get; set; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs new file mode 100644 index 0000000000000..1f99d3ef7b1b4 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs @@ -0,0 +1,206 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class ExportQuery : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportQuery)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("query"u8); + writer.WriteStringValue(Query); + if (Optional.IsDefined(NamePattern)) + { + writer.WritePropertyName("namePattern"u8); + writer.WriteStringValue(NamePattern); + } + if (Optional.IsDefined(Recursive)) + { + writer.WritePropertyName("recursive"u8); + writer.WriteBooleanValue(Recursive.Value); + } + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(TargetProvider)) + { + writer.WritePropertyName("targetProvider"u8); + writer.WriteStringValue(TargetProvider.Value.ToString()); + } + if (Optional.IsDefined(FullProperties)) + { + writer.WritePropertyName("fullProperties"u8); + writer.WriteBooleanValue(FullProperties.Value); + } + if (Optional.IsDefined(MaskSensitive)) + { + writer.WritePropertyName("maskSensitive"u8); + writer.WriteBooleanValue(MaskSensitive.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ExportQuery IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportQuery)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeExportQuery(document.RootElement, options); + } + + internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string query = default; + string namePattern = default; + bool? recursive = default; + Type type = default; + TargetProvider? targetProvider = default; + bool? fullProperties = default; + bool? maskSensitive = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("query"u8)) + { + query = property.Value.GetString(); + continue; + } + if (property.NameEquals("namePattern"u8)) + { + namePattern = property.Value.GetString(); + continue; + } + if (property.NameEquals("recursive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + recursive = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new Type(property.Value.GetString()); + continue; + } + if (property.NameEquals("targetProvider"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + targetProvider = new TargetProvider(property.Value.GetString()); + continue; + } + if (property.NameEquals("fullProperties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fullProperties = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("maskSensitive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maskSensitive = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ExportQuery( + type, + targetProvider, + fullProperties, + maskSensitive, + serializedAdditionalRawData, + query, + namePattern, + recursive); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ExportQuery)} does not support writing '{options.Format}' format."); + } + } + + ExportQuery IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeExportQuery(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ExportQuery)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs new file mode 100644 index 0000000000000..e0992c67697b6 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// Export parameter for resources queried by ARG (Azure Resource Graph). + public partial class ExportQuery : BaseExportModel + { + /// Initializes a new instance of . + /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + /// is null. + public ExportQuery(string query) + { + Argument.AssertNotNull(query, nameof(query)); + + Query = query; + Type = Type.ExportQuery; + } + + /// Initializes a new instance of . + /// The parameter type. + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// Keeps track of any properties unknown to the library. + /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + /// The name pattern of the Terraform resources. + /// Whether to recursively list child resources of the query result. + internal ExportQuery(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + { + Query = query; + NamePattern = namePattern; + Recursive = recursive; + Type = type; + } + + /// Initializes a new instance of for deserialization. + internal ExportQuery() + { + } + + /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. + public string Query { get; } + /// The name pattern of the Terraform resources. + public string NamePattern { get; set; } + /// Whether to recursively list child resources of the query result. + public bool? Recursive { get; set; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs new file mode 100644 index 0000000000000..3fd6e808fc94e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs @@ -0,0 +1,224 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class ExportResource : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResource)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("resourceIds"u8); + writer.WriteStartArray(); + foreach (var item in ResourceIds) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsDefined(ResourceName)) + { + writer.WritePropertyName("resourceName"u8); + writer.WriteStringValue(ResourceName); + } + if (Optional.IsDefined(ResourceType)) + { + writer.WritePropertyName("resourceType"u8); + writer.WriteStringValue(ResourceType); + } + if (Optional.IsDefined(NamePattern)) + { + writer.WritePropertyName("namePattern"u8); + writer.WriteStringValue(NamePattern); + } + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(TargetProvider)) + { + writer.WritePropertyName("targetProvider"u8); + writer.WriteStringValue(TargetProvider.Value.ToString()); + } + if (Optional.IsDefined(FullProperties)) + { + writer.WritePropertyName("fullProperties"u8); + writer.WriteBooleanValue(FullProperties.Value); + } + if (Optional.IsDefined(MaskSensitive)) + { + writer.WritePropertyName("maskSensitive"u8); + writer.WriteBooleanValue(MaskSensitive.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ExportResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResource)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeExportResource(document.RootElement, options); + } + + internal static ExportResource DeserializeExportResource(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList resourceIds = default; + string resourceName = default; + string resourceType = default; + string namePattern = default; + Type type = default; + TargetProvider? targetProvider = default; + bool? fullProperties = default; + bool? maskSensitive = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("resourceIds"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + resourceIds = array; + continue; + } + if (property.NameEquals("resourceName"u8)) + { + resourceName = property.Value.GetString(); + continue; + } + if (property.NameEquals("resourceType"u8)) + { + resourceType = property.Value.GetString(); + continue; + } + if (property.NameEquals("namePattern"u8)) + { + namePattern = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new Type(property.Value.GetString()); + continue; + } + if (property.NameEquals("targetProvider"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + targetProvider = new TargetProvider(property.Value.GetString()); + continue; + } + if (property.NameEquals("fullProperties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fullProperties = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("maskSensitive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maskSensitive = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ExportResource( + type, + targetProvider, + fullProperties, + maskSensitive, + serializedAdditionalRawData, + resourceIds, + resourceName, + resourceType, + namePattern); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ExportResource)} does not support writing '{options.Format}' format."); + } + } + + ExportResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeExportResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ExportResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs new file mode 100644 index 0000000000000..56425d884a0e6 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// Export parameter for individual resources. + public partial class ExportResource : BaseExportModel + { + /// Initializes a new instance of . + /// The id of the resource to be exported. + /// is null. + public ExportResource(IEnumerable resourceIds) + { + Argument.AssertNotNull(resourceIds, nameof(resourceIds)); + + ResourceIds = resourceIds.ToList(); + Type = Type.ExportResource; + } + + /// Initializes a new instance of . + /// The parameter type. + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// Keeps track of any properties unknown to the library. + /// The id of the resource to be exported. + /// The Terraform resource name. Only works when `resourceIds` contains only one item. + /// The Terraform resource type. Only works when `resourceIds` contains only one item. + /// The name pattern of the Terraform resources. + internal ExportResource(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + { + ResourceIds = resourceIds; + ResourceName = resourceName; + ResourceType = resourceType; + NamePattern = namePattern; + Type = type; + } + + /// Initializes a new instance of for deserialization. + internal ExportResource() + { + } + + /// The id of the resource to be exported. + public IList ResourceIds { get; } + /// The Terraform resource name. Only works when `resourceIds` contains only one item. + public string ResourceName { get; set; } + /// The Terraform resource type. Only works when `resourceIds` contains only one item. + public string ResourceType { get; set; } + /// The name pattern of the Terraform resources. + public string NamePattern { get; set; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs new file mode 100644 index 0000000000000..639f168c3f91e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs @@ -0,0 +1,190 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class ExportResourceGroup : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("resourceGroupName"u8); + writer.WriteStringValue(ResourceGroupName); + if (Optional.IsDefined(NamePattern)) + { + writer.WritePropertyName("namePattern"u8); + writer.WriteStringValue(NamePattern); + } + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(TargetProvider)) + { + writer.WritePropertyName("targetProvider"u8); + writer.WriteStringValue(TargetProvider.Value.ToString()); + } + if (Optional.IsDefined(FullProperties)) + { + writer.WritePropertyName("fullProperties"u8); + writer.WriteBooleanValue(FullProperties.Value); + } + if (Optional.IsDefined(MaskSensitive)) + { + writer.WritePropertyName("maskSensitive"u8); + writer.WriteBooleanValue(MaskSensitive.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ExportResourceGroup IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeExportResourceGroup(document.RootElement, options); + } + + internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string resourceGroupName = default; + string namePattern = default; + Type type = default; + TargetProvider? targetProvider = default; + bool? fullProperties = default; + bool? maskSensitive = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("resourceGroupName"u8)) + { + resourceGroupName = property.Value.GetString(); + continue; + } + if (property.NameEquals("namePattern"u8)) + { + namePattern = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new Type(property.Value.GetString()); + continue; + } + if (property.NameEquals("targetProvider"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + targetProvider = new TargetProvider(property.Value.GetString()); + continue; + } + if (property.NameEquals("fullProperties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fullProperties = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("maskSensitive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maskSensitive = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ExportResourceGroup( + type, + targetProvider, + fullProperties, + maskSensitive, + serializedAdditionalRawData, + resourceGroupName, + namePattern); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support writing '{options.Format}' format."); + } + } + + ExportResourceGroup IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeExportResourceGroup(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs new file mode 100644 index 0000000000000..3ea06af1982f0 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// Export parameter for a resource group. + public partial class ExportResourceGroup : BaseExportModel + { + /// Initializes a new instance of . + /// The name of the resource group to be exported. + /// is null. + public ExportResourceGroup(string resourceGroupName) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + ResourceGroupName = resourceGroupName; + Type = Type.ExportResourceGroup; + } + + /// Initializes a new instance of . + /// The parameter type. + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// Keeps track of any properties unknown to the library. + /// The name of the resource group to be exported. + /// The name pattern of the Terraform resources. + internal ExportResourceGroup(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + { + ResourceGroupName = resourceGroupName; + NamePattern = namePattern; + Type = type; + } + + /// Initializes a new instance of for deserialization. + internal ExportResourceGroup() + { + } + + /// The name of the resource group to be exported. + public string ResourceGroupName { get; } + /// The name pattern of the Terraform resources. + public string NamePattern { get; set; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs new file mode 100644 index 0000000000000..e6aec46fe3461 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The target Azure Terraform Provider. + public readonly partial struct TargetProvider : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TargetProvider(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AzurermValue = "azurerm"; + private const string AzapiValue = "azapi"; + + /// https://registry.terraform.io/providers/hashicorp/azurerm/latest. + public static TargetProvider Azurerm { get; } = new TargetProvider(AzurermValue); + /// https://registry.terraform.io/providers/Azure/azapi/latest. + public static TargetProvider Azapi { get; } = new TargetProvider(AzapiValue); + /// Determines if two values are the same. + public static bool operator ==(TargetProvider left, TargetProvider right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TargetProvider left, TargetProvider right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator TargetProvider(string value) => new TargetProvider(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TargetProvider other && Equals(other); + /// + public bool Equals(TargetProvider other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs new file mode 100644 index 0000000000000..4b51bb6632c04 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The parameter type. + internal readonly partial struct Type : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public Type(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string ExportResourceValue = "ExportResource"; + private const string ExportResourceGroupValue = "ExportResourceGroup"; + private const string ExportQueryValue = "ExportQuery"; + + /// ExportResource. + public static Type ExportResource { get; } = new Type(ExportResourceValue); + /// ExportResourceGroup. + public static Type ExportResourceGroup { get; } = new Type(ExportResourceGroupValue); + /// ExportQuery. + public static Type ExportQuery { get; } = new Type(ExportQueryValue); + /// Determines if two values are the same. + public static bool operator ==(Type left, Type right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(Type left, Type right) => !left.Equals(right); + /// Converts a string to a . + public static implicit operator Type(string value) => new Type(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is Type other && Equals(other); + /// + public bool Equals(Type other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs new file mode 100644 index 0000000000000..d5145cdb2bb1b --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + internal partial class UnknownBaseExportModel : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsDefined(TargetProvider)) + { + writer.WritePropertyName("targetProvider"u8); + writer.WriteStringValue(TargetProvider.Value.ToString()); + } + if (Optional.IsDefined(FullProperties)) + { + writer.WritePropertyName("fullProperties"u8); + writer.WriteBooleanValue(FullProperties.Value); + } + if (Optional.IsDefined(MaskSensitive)) + { + writer.WritePropertyName("maskSensitive"u8); + writer.WriteBooleanValue(MaskSensitive.Value); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeBaseExportModel(document.RootElement, options); + } + + internal static UnknownBaseExportModel DeserializeUnknownBaseExportModel(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Type type = "Unknown"; + TargetProvider? targetProvider = default; + bool? fullProperties = default; + bool? maskSensitive = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new Type(property.Value.GetString()); + continue; + } + if (property.NameEquals("targetProvider"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + targetProvider = new TargetProvider(property.Value.GetString()); + continue; + } + if (property.NameEquals("fullProperties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + fullProperties = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("maskSensitive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maskSensitive = property.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownBaseExportModel(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{options.Format}' format."); + } + } + + BaseExportModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeBaseExportModel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs new file mode 100644 index 0000000000000..54de7bdc89205 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// Unknown version of BaseExportModel. + internal partial class UnknownBaseExportModel : BaseExportModel + { + /// Initializes a new instance of . + /// The parameter type. + /// The target Azure Terraform Provider. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. + /// Keeps track of any properties unknown to the library. + internal UnknownBaseExportModel(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + { + Type = type; + } + + /// Initializes a new instance of for deserialization. + internal UnknownBaseExportModel() + { + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ProviderConstants.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ProviderConstants.cs new file mode 100644 index 0000000000000..32fce05439869 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ProviderConstants.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ + internal static class ProviderConstants + { + public static string DefaultProviderNamespace { get; } = ClientDiagnostics.GetResourceProviderNamespace(typeof(ProviderConstants).Assembly); + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs new file mode 100644 index 0000000000000..be1edccefbc71 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs @@ -0,0 +1,114 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform +{ + internal partial class AzureTerraformRestOperations + { + private readonly TelemetryDetails _userAgent; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of AzureTerraformRestOperations. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The application id to use for user agent. + /// The to use. + /// The API version to use for this operation. + /// or is null. + public AzureTerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) + { + _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); + _endpoint = endpoint ?? new Uri("https://management.azure.com"); + _apiVersion = apiVersion ?? "2023-07-01-preview"; + _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); + } + + internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId, BaseExportModel exportParameter) + { + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/exportTerraform", false); + uri.AppendQuery("api-version", _apiVersion, true); + return uri; + } + + internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExportModel exportParameter) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/exportTerraform", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(exportParameter, ModelSerializationExtensions.WireOptions); + request.Content = content; + _userAgent.Apply(message); + return message; + } + + /// Exports the Terraform configuration of the specified resource(s). + /// The ID of the target subscription. The value must be an UUID. + /// The export parameter. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public async Task ExportTerraformAsync(string subscriptionId, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + + using var message = CreateExportTerraformRequest(subscriptionId, exportParameter); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + + /// Exports the Terraform configuration of the specified resource(s). + /// The ID of the target subscription. The value must be an UUID. + /// The export parameter. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public Response ExportTerraform(string subscriptionId, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + + using var message = CreateExportTerraformRequest(subscriptionId, exportParameter); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs new file mode 100644 index 0000000000000..fd1a85f2297de --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ + internal partial class OperationStatusesRestOperations + { + private readonly TelemetryDetails _userAgent; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of OperationStatusesRestOperations. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The application id to use for user agent. + /// The to use. + /// The API version to use for this operation. + /// or is null. + public OperationStatusesRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) + { + _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); + _endpoint = endpoint ?? new Uri("https://management.azure.com"); + _apiVersion = apiVersion ?? "2023-07-01-preview"; + _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); + } + + internal RequestUriBuilder CreateGetRequestUri(string operationId, string subscriptionId) + { + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); + uri.AppendPath(operationId, true); + uri.AppendQuery("api-version", _apiVersion, true); + return uri; + } + + internal HttpMessage CreateGetRequest(string operationId, string subscriptionId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); + uri.AppendPath(operationId, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// Get the status of a long running azure asynchronous operation. + /// The ID of an ongoing async operation. + /// The ID of the target subscription. The value must be an UUID. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task GetAsync(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + + using var message = CreateGetRequest(operationId, subscriptionId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + + /// Get the status of a long running azure asynchronous operation. + /// The ID of an ongoing async operation. + /// The ID of the target subscription. The value must be an UUID. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response Get(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + + using var message = CreateGetRequest(operationId, subscriptionId); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + } +} From d396efeb17bed54cf58d191594157661f0504891 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Thu, 26 Sep 2024 13:07:32 +1000 Subject: [PATCH 05/33] Generated API files --- ...esourceManager.Terraform.netstandard2.0.cs | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs new file mode 100644 index 0000000000000..19d5312faacb5 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -0,0 +1,95 @@ +namespace Azure.ResourceManager.Terraform +{ + public static partial class TerraformExtensions + { + public static Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task ExportTerraformAzureTerraformClientAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation GetOperationStatus(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task GetOperationStatusAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Terraform.Mocking +{ + public partial class MockableTerraformSubscriptionResource : Azure.ResourceManager.ArmResource + { + protected MockableTerraformSubscriptionResource() { } + public virtual Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task ExportTerraformAzureTerraformClientAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation GetOperationStatus(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task GetOperationStatusAsync(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Terraform.Models +{ + public static partial class ArmTerraformModelFactory + { + public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } + } + public abstract partial class BaseExportModel : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + protected BaseExportModel() { } + public bool? FullProperties { get { throw null; } set { } } + public bool? MaskSensitive { get { throw null; } set { } } + public Azure.ResourceManager.Terraform.Models.TargetProvider? TargetProvider { get { throw null; } set { } } + Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ExportQuery : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public ExportQuery(string query) { } + public string NamePattern { get { throw null; } set { } } + public string Query { get { throw null; } } + public bool? Recursive { get { throw null; } set { } } + Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ExportResource : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public ExportResource(System.Collections.Generic.IEnumerable resourceIds) { } + public string NamePattern { get { throw null; } set { } } + public System.Collections.Generic.IList ResourceIds { get { throw null; } } + public string ResourceName { get { throw null; } set { } } + public string ResourceType { get { throw null; } set { } } + Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public ExportResourceGroup(string resourceGroupName) { } + public string NamePattern { get { throw null; } set { } } + public string ResourceGroupName { get { throw null; } } + Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct TargetProvider : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public TargetProvider(string value) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TargetProvider Azapi { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.TargetProvider Azurerm { get { throw null; } } + public bool Equals(Azure.ResourceManager.Terraform.Models.TargetProvider other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.ResourceManager.Terraform.Models.TargetProvider left, Azure.ResourceManager.Terraform.Models.TargetProvider right) { throw null; } + public static implicit operator Azure.ResourceManager.Terraform.Models.TargetProvider (string value) { throw null; } + public static bool operator !=(Azure.ResourceManager.Terraform.Models.TargetProvider left, Azure.ResourceManager.Terraform.Models.TargetProvider right) { throw null; } + public override string ToString() { throw null; } + } +} From 0000a91c0bc191cddf78d867ef2cb37a6fe77e4b Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Thu, 26 Sep 2024 13:31:25 +1000 Subject: [PATCH 06/33] Added ExportResource to ExceptionList --- .../tests/InheritanceCheckTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs new file mode 100644 index 0000000000000..7c7e4717e8dd6 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using NUnit.Framework; + +namespace Azure.ResourceManager.TestFramework +{ + public partial class InheritanceCheckTests + { + [OneTimeSetUp] + public void SetExceptionList() + { + ExceptionList = new string[] { "ExportResource" }; + } + } +} From d1bb63b746f11a2df91b003034fa535ffb11f4a6 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 1 Oct 2024 15:56:46 +1000 Subject: [PATCH 07/33] Add e2e test --- .../tests/ExportResourceGroupE2ETest.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs new file mode 100644 index 0000000000000..70c86f76064da --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel.DataAnnotations; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Terraform.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Terraform.E2etest +{ + public class ExportResourceGroupE2ETest + { + /* + Exports resource group specified by the environment variable RESOURCE_GROUP, under SUBSCRIPTION_ID. + This test be skipped unless environment variable RUN_E2E_TEST is set to "true" + */ + [Test] + public async Task exportResourceGroupE2ETest() + { + bool runTest = bool.Parse(Environment.GetEnvironmentVariable("RUN_E2E_TEST") ?? "false"); + if (!runTest) + { + Console.WriteLine("Environment variable RUN_E2E_TEST is not set to true, skipping test"); + return; + } + + string resourceGroup = Environment.GetEnvironmentVariable("RESOURCE_GROUP") ?? throw new ValidationException($"Environment variable RESOURCE_GROUP is not set"); + string subscriptionId = Environment.GetEnvironmentVariable("SUBSCRIPTION_ID") ?? throw new ValidationException($"Environment variable SUBSCRIPTION_ID is not set"); + TokenCredential cred = new DefaultAzureCredential(); + ArmClient client = new ArmClient(cred); + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); + BaseExportModel exportParameter = new ExportResourceGroup(resourceGroup); + + ArmOperation armOperation = await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); + + Response response = armOperation.WaitForCompletionResponse(); + + Console.WriteLine(response.Content.ToString()); + string hcl = hclFromResponseContent(response.Content.ToString()); + + Assert.That(hcl, Does.Contain("azurerm_resource_group")); + Assert.That(hcl, Does.Contain(resourceGroup)); + } + + private string hclFromResponseContent(string responseContent) + { + try + { + using (JsonDocument doc = JsonDocument.Parse(responseContent)) + { + return doc.RootElement.GetProperty("properties").GetProperty("configuration").GetString(); + } + } + catch (Exception e) + { + throw new Exception("Error parsing json string and accessing 'properties.configuration' path", e); + } + } + } +} From 7b7dd82514e1cad7868a642feebc9245132dfe07 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 1 Oct 2024 16:07:56 +1000 Subject: [PATCH 08/33] Updated changelog and readme --- .../CHANGELOG.md | 4 +--- .../Azure.ResourceManager.Terraform/README.md | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md index 1a85987a15b9e..a97f1297b3fbe 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md +++ b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md @@ -2,8 +2,6 @@ ## 1.0.0-beta.1 (Unreleased) - - ### Features Added This package follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: @@ -16,4 +14,4 @@ This package follows the [new Azure SDK guidelines](https://azure.github.io/azur This package is a Public Preview version, so expect incompatible changes in subsequent releases as we improve the product. To provide feedback, submit an issue in our [Azure SDK for .NET GitHub repo](https://github.com/Azure/azure-sdk-for-net/issues). -> NOTE: For more information about unified authentication, please refer to [Microsoft Azure Identity documentation for .NET](https://docs.microsoft.com//dotnet/api/overview/azure/identity-readme?view=azure-dotnet). \ No newline at end of file +> NOTE: For more information about unified authentication, please refer to [Microsoft Azure Identity documentation for .NET](https://docs.microsoft.com//dotnet/api/overview/azure/identity-readme?view=azure-dotnet). diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/README.md b/sdk/terraform/Azure.ResourceManager.Terraform/README.md index 6d15453099af0..7eae62f4da191 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/README.md +++ b/sdk/terraform/Azure.ResourceManager.Terraform/README.md @@ -1,16 +1,17 @@ # Microsoft Azure terraform management client library for .NET -**[Describe the service briefly first.]** +The Azure Terraform Export API aims to export existing Azure resources into its equivalent Terraform configurations, +for either azurerm provider or azapi provider. It is equivalent to ARM Template Export API for Terraform. This library follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: - - Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. - - Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. - - HTTP pipeline with custom policies. - - Better error-handling. - - Support uniform telemetry across all languages. +- Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. +- Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. +- HTTP pipeline with custom policies. +- Better error-handling. +- Support uniform telemetry across all languages. -## Getting started +## Getting started ### Install the package @@ -22,7 +23,7 @@ dotnet add package Azure.ResourceManager.Terraform --prerelease ### Prerequisites -* You must have an [Microsoft Azure subscription](https://azure.microsoft.com/free/dotnet/). +- You must have an [Microsoft Azure subscription](https://azure.microsoft.com/free/dotnet/). ### Authenticate the Client @@ -43,12 +44,13 @@ Documentation is available to help you learn how to use this package: ## Examples Code samples for using the management library for .NET can be found in the following locations + - [.NET Management Library Code Samples](https://aka.ms/azuresdk-net-mgmt-samples) ## Troubleshooting -- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). -- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. +- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). +- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. ## Next steps @@ -77,4 +79,4 @@ more information, see the [Code of Conduct FAQ][coc_faq] or contact [cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md [coc]: https://opensource.microsoft.com/codeofconduct/ -[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ \ No newline at end of file +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ From 927d7432c8cbe99aea8cf1841ffe2effc90ae523 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Thu, 3 Oct 2024 14:22:56 +1000 Subject: [PATCH 09/33] Refactor to use Azure.Core.TestFramework --- .../assets.json | 2 +- .../tests/ExportResourceGroupE2ETest.cs | 66 ------------------- ...Base.cs => TerraformManagementTestBase.cs} | 10 +-- ... => TerraformManagementTestEnvironment.cs} | 4 +- .../tests/Tests/ExportTerraformTests.cs | 64 ++++++++++++++++++ 5 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs rename sdk/terraform/Azure.ResourceManager.Terraform/tests/{terraformManagementTestBase.cs => TerraformManagementTestBase.cs} (68%) rename sdk/terraform/Azure.ResourceManager.Terraform/tests/{terraformManagementTestEnvironment.cs => TerraformManagementTestEnvironment.cs} (75%) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 1e8c0b20696bd..8829021faba16 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "" + "Tag": "net/terraform/Azure.ResourceManager.Terraform_b8ab15c5c5" } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs deleted file mode 100644 index 70c86f76064da..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportResourceGroupE2ETest.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.ComponentModel.DataAnnotations; -using System.Text.Json; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Identity; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.Terraform.Models; -using NUnit.Framework; - -namespace Azure.ResourceManager.Terraform.E2etest -{ - public class ExportResourceGroupE2ETest - { - /* - Exports resource group specified by the environment variable RESOURCE_GROUP, under SUBSCRIPTION_ID. - This test be skipped unless environment variable RUN_E2E_TEST is set to "true" - */ - [Test] - public async Task exportResourceGroupE2ETest() - { - bool runTest = bool.Parse(Environment.GetEnvironmentVariable("RUN_E2E_TEST") ?? "false"); - if (!runTest) - { - Console.WriteLine("Environment variable RUN_E2E_TEST is not set to true, skipping test"); - return; - } - - string resourceGroup = Environment.GetEnvironmentVariable("RESOURCE_GROUP") ?? throw new ValidationException($"Environment variable RESOURCE_GROUP is not set"); - string subscriptionId = Environment.GetEnvironmentVariable("SUBSCRIPTION_ID") ?? throw new ValidationException($"Environment variable SUBSCRIPTION_ID is not set"); - TokenCredential cred = new DefaultAzureCredential(); - ArmClient client = new ArmClient(cred); - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); - SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); - BaseExportModel exportParameter = new ExportResourceGroup(resourceGroup); - - ArmOperation armOperation = await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); - - Response response = armOperation.WaitForCompletionResponse(); - - Console.WriteLine(response.Content.ToString()); - string hcl = hclFromResponseContent(response.Content.ToString()); - - Assert.That(hcl, Does.Contain("azurerm_resource_group")); - Assert.That(hcl, Does.Contain(resourceGroup)); - } - - private string hclFromResponseContent(string responseContent) - { - try - { - using (JsonDocument doc = JsonDocument.Parse(responseContent)) - { - return doc.RootElement.GetProperty("properties").GetProperty("configuration").GetString(); - } - } - catch (Exception e) - { - throw new Exception("Error parsing json string and accessing 'properties.configuration' path", e); - } - } - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestBase.cs similarity index 68% rename from sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestBase.cs index 85f09319296dc..db6f28c657627 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestBase.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestBase.cs @@ -10,17 +10,18 @@ namespace Azure.ResourceManager.Terraform.Tests { - public class terraformManagementTestBase : ManagementRecordedTestBase + public class TerraformManagementTestBase : ManagementRecordedTestBase { protected ArmClient Client { get; private set; } protected SubscriptionResource DefaultSubscription { get; private set; } + protected ResourceGroupCollection ResourceGroupCollection { get; private set; } - protected terraformManagementTestBase(bool isAsync, RecordedTestMode mode) + protected TerraformManagementTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode) { } - protected terraformManagementTestBase(bool isAsync) + protected TerraformManagementTestBase(bool isAsync) : base(isAsync) { } @@ -30,13 +31,14 @@ public async Task CreateCommonClient() { Client = GetArmClient(); DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); + ResourceGroupCollection = DefaultSubscription.GetResourceGroups(); } protected async Task CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location) { string rgName = Recording.GenerateAssetName(rgNamePrefix); ResourceGroupData input = new ResourceGroupData(location); - var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); + ArmOperation lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); return lro.Value; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs similarity index 75% rename from sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs index c4842b3a3611d..5d6e6f86ab8af 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/terraformManagementTestEnvironment.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs @@ -5,7 +5,7 @@ namespace Azure.ResourceManager.Terraform.Tests { - public class terraformManagementTestEnvironment : TestEnvironment + public class TerraformManagementTestEnvironment : TestEnvironment { } -} \ No newline at end of file +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs new file mode 100644 index 0000000000000..6f02e9cc838f7 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.Terraform.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Terraform.Tests.Tests +{ + [TestFixture] + public class ExportTerraformTests : TerraformManagementTestBase + { + private ResourceGroupResource _resourceGroup; + + public ExportTerraformTests() : base(true) + { + } + + [SetUp] + public async Task SetUp() + { + _resourceGroup = await CreateResourceGroup(DefaultSubscription, "exportTerraformRg", AzureLocation.WestUS); + } + + [TearDown] + public async Task TearDown() + { + await _resourceGroup.DeleteAsync(WaitUntil.Completed); + } + + [TestCase] + [RecordedTest] + public async Task ExportTerraform() + { + string rgName = _resourceGroup.Data.Name; + ArmOperation armOperation = await DefaultSubscription.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); + string responseContent = armOperation.GetRawResponse().Content.ToString(); + string hcl = HclFromResponseContent(responseContent); + + Assert.That(hcl, Does.Contain("azurerm_resource_group")); + Assert.That(hcl, Does.Contain(rgName)); + } + + private static string HclFromResponseContent(string responseContent) + { + try + { + using (JsonDocument doc = JsonDocument.Parse(responseContent)) + { + return doc.RootElement.GetProperty("properties").GetProperty("configuration").GetString(); + } + } + catch (Exception e) + { + throw new Exception("Error parsing json string and accessing 'properties.configuration' path", e); + } + } + } +} From 5ba53376d7d472b569ed5d33a3280954fbd9ae72 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 8 Oct 2024 17:07:08 +1100 Subject: [PATCH 10/33] Updated commit hash in tsp-location.yaml, regenerated SDK code --- .../src/Generated/Models/TargetProvider.cs | 2 +- .../src/Generated/Models/Type.cs | 2 +- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs index e6aec46fe3461..9def376f32f94 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs @@ -33,7 +33,7 @@ public TargetProvider(string value) public static bool operator ==(TargetProvider left, TargetProvider right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(TargetProvider left, TargetProvider right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator TargetProvider(string value) => new TargetProvider(value); /// diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs index 4b51bb6632c04..4862340f9945f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs @@ -36,7 +36,7 @@ public Type(string value) public static bool operator ==(Type left, Type right) => left.Equals(right); /// Determines if two values are not the same. public static bool operator !=(Type left, Type right) => !left.Equals(right); - /// Converts a string to a . + /// Converts a to a . public static implicit operator Type(string value) => new Type(value); /// diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 9009369cc7e63..08d79a8309cad 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: befbed40f82c444b19d6aaf5d4ac6bdf50960d54 +commit: dce461bb4e89238f383f0a165d95859f54638fd6 repo: Azure/azure-rest-api-specs From 9787d55690e799b1f124db0bc57ef19b1c378955 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 9 Oct 2024 11:29:16 +1100 Subject: [PATCH 11/33] Regen after final state model update locally --- .../Sample_SubscriptionResourceExtensions.cs | 5 +- .../src/Generated/ArmTerraformModelFactory.cs | 39 +++ .../MockableTerraformSubscriptionResource.cs | 12 +- .../Extensions/TerraformExtensions.cs | 4 +- .../OperationStatusOperationSource.cs | 30 +++ .../TerraformArmOperationOfT.cs | 100 ++++++++ .../Models/ExportResult.Serialization.cs | 172 +++++++++++++ .../src/Generated/Models/ExportResult.cs | 75 ++++++ .../Models/OperationStatus.Serialization.cs | 240 ++++++++++++++++++ .../src/Generated/Models/OperationStatus.cs | 97 +++++++ .../tests/Tests/ExportTerraformTests.cs | 22 +- .../tsp-location.yaml | 2 +- 12 files changed, 767 insertions(+), 31 deletions(-) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index dc8033389113c..bb20f7a5667f7 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -37,9 +37,10 @@ public async Task ExportTerraformAzureTerraformClient_ExportTerraform() // invoke the operation BaseExportModel exportParameter = new ExportResourceGroup("rg1"); - await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); + ArmOperation lro = await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); + OperationStatus result = lro.Value; - Console.WriteLine($"Succeeded"); + Console.WriteLine($"Succeeded: {result}"); } // Get specific operation status diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 7edb13e0991cf..cb000ccc05eb0 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -53,5 +53,44 @@ public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProv resourceGroupName, namePattern); } + + /// Initializes a new instance of . + /// The operation status resource id. + /// The fully qualified resource id of the resource for which the operation was performed. + /// The operation name. + /// The start time of the operation. + /// The end time of the operation. + /// The status of the operation. + /// The progress percentage of the operation, ranges from 0 to 100. + /// The Terraform export result. + /// The error object. + /// A new instance for mocking. + public static OperationStatus OperationStatus(string id = null, string resourceId = null, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, string status = null, double? percentComplete = null, ExportResult properties = null, ResponseError error = null) + { + return new OperationStatus( + id, + resourceId, + name, + startOn, + endOn, + status, + percentComplete, + properties, + error, + serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The Terraform configuration content. + /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. + /// A list of errors derived during exporting each resource. + /// A new instance for mocking. + public static ExportResult ExportResult(string configuration = null, IEnumerable skippedResources = null, IEnumerable errors = null) + { + skippedResources ??= new List(); + errors ??= new List(); + + return new ExportResult(configuration, skippedResources?.ToList(), errors?.ToList(), serializedAdditionalRawData: null); + } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index f5bc24668b1c2..446f19d881f03 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -66,7 +66,7 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// The export parameter. /// The cancellation token to use. /// is null. - public virtual async Task ExportTerraformAzureTerraformClientAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public virtual async Task> ExportTerraformAzureTerraformClientAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); @@ -75,9 +75,9 @@ public virtual async Task ExportTerraformAzureTerraformClientAsync try { var response = await AzureTerraformClientRestClient.ExportTerraformAsync(Id.SubscriptionId, exportParameter, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); return operation; } catch (Exception e) @@ -108,7 +108,7 @@ public virtual async Task ExportTerraformAzureTerraformClientAsync /// The export parameter. /// The cancellation token to use. /// is null. - public virtual ArmOperation ExportTerraformAzureTerraformClient(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public virtual ArmOperation ExportTerraformAzureTerraformClient(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); @@ -117,9 +117,9 @@ public virtual ArmOperation ExportTerraformAzureTerraformClient(WaitUntil waitUn try { var response = AzureTerraformClientRestClient.ExportTerraform(Id.SubscriptionId, exportParameter, cancellationToken); - var operation = new TerraformArmOperation(AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - operation.WaitForCompletionResponse(cancellationToken); + operation.WaitForCompletion(cancellationToken); return operation; } catch (Exception e) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index a479ff9e3a36e..c97085255b00f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -48,7 +48,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// The export parameter. /// The cancellation token to use. /// or is null. - public static async Task ExportTerraformAzureTerraformClientAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public static async Task> ExportTerraformAzureTerraformClientAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); @@ -81,7 +81,7 @@ public static async Task ExportTerraformAzureTerraformClientAsync( /// The export parameter. /// The cancellation token to use. /// or is null. - public static ArmOperation ExportTerraformAzureTerraformClient(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public static ArmOperation ExportTerraformAzureTerraformClient(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs new file mode 100644 index 0000000000000..9d82172ef3e3d --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform +{ + internal class OperationStatusOperationSource : IOperationSource + { + OperationStatus IOperationSource.CreateResult(Response response, CancellationToken cancellationToken) + { + using var document = JsonDocument.Parse(response.ContentStream); + return OperationStatus.DeserializeOperationStatus(document.RootElement); + } + + async ValueTask IOperationSource.CreateResultAsync(Response response, CancellationToken cancellationToken) + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + return OperationStatus.DeserializeOperationStatus(document.RootElement); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs new file mode 100644 index 0000000000000..23e4d4dba878c --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ +#pragma warning disable SA1649 // File name should match first type name + internal class TerraformArmOperation : ArmOperation +#pragma warning restore SA1649 // File name should match first type name + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of TerraformArmOperation for mocking. + protected TerraformArmOperation() + { + } + + internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response.GetRawResponse(), response.Value); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + internal TerraformArmOperation(IOperationSource source, ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) + { + _nextLinkOperation = nextLinkOperationValue; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal(NextLinkOperationImplementation.Create(source, nextLinkOperation), clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); + } + + private string GetOperationId(RehydrationToken? rehydrationToken) + { + if (rehydrationToken is null) + { + return null; + } + var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); + return lroDetails["id"]; + } + /// + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override T Value => _operation.Value; + + /// + public override bool HasValue => _operation.HasValue; + + /// + public override bool HasCompleted => _operation.HasCompleted; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletion(CancellationToken cancellationToken = default) => _operation.WaitForCompletion(cancellationToken); + + /// + public override Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletion(pollingInterval, cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken); + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs new file mode 100644 index 0000000000000..e45a32435af32 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs @@ -0,0 +1,172 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class ExportResult : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResult)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Configuration)) + { + writer.WritePropertyName("configuration"u8); + writer.WriteStringValue(Configuration); + } + if (Optional.IsCollectionDefined(SkippedResources)) + { + writer.WritePropertyName("skippedResources"u8); + writer.WriteStartArray(); + foreach (var item in SkippedResources) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(Errors)) + { + writer.WritePropertyName("errors"u8); + writer.WriteStartArray(); + foreach (var item in Errors) + { + JsonSerializer.Serialize(writer, item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ExportResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExportResult)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeExportResult(document.RootElement, options); + } + + internal static ExportResult DeserializeExportResult(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string configuration = default; + IReadOnlyList skippedResources = default; + IReadOnlyList errors = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("configuration"u8)) + { + configuration = property.Value.GetString(); + continue; + } + if (property.NameEquals("skippedResources"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + skippedResources = array; + continue; + } + if (property.NameEquals("errors"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(JsonSerializer.Deserialize(item.GetRawText())); + } + errors = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ExportResult(configuration, skippedResources ?? new ChangeTrackingList(), errors ?? new ChangeTrackingList(), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ExportResult)} does not support writing '{options.Format}' format."); + } + } + + ExportResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeExportResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ExportResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs new file mode 100644 index 0000000000000..e6759be2d909f --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The Terraform export result. + public partial class ExportResult + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal ExportResult() + { + SkippedResources = new ChangeTrackingList(); + Errors = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The Terraform configuration content. + /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. + /// A list of errors derived during exporting each resource. + /// Keeps track of any properties unknown to the library. + internal ExportResult(string configuration, IReadOnlyList skippedResources, IReadOnlyList errors, IDictionary serializedAdditionalRawData) + { + Configuration = configuration; + SkippedResources = skippedResources; + Errors = errors; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The Terraform configuration content. + public string Configuration { get; } + /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. + public IReadOnlyList SkippedResources { get; } + /// A list of errors derived during exporting each resource. + public IReadOnlyList Errors { get; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs new file mode 100644 index 0000000000000..ef105411c9a9e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs @@ -0,0 +1,240 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class OperationStatus : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (options.Format != "W" && Optional.IsDefined(ResourceId)) + { + writer.WritePropertyName("resourceId"u8); + writer.WriteStringValue(ResourceId); + } + if (Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (options.Format != "W" && Optional.IsDefined(StartOn)) + { + writer.WritePropertyName("startTime"u8); + writer.WriteStringValue(StartOn.Value, "O"); + } + if (options.Format != "W" && Optional.IsDefined(EndOn)) + { + writer.WritePropertyName("endTime"u8); + writer.WriteStringValue(EndOn.Value, "O"); + } + if (Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status); + } + if (Optional.IsDefined(PercentComplete)) + { + writer.WritePropertyName("percentComplete"u8); + writer.WriteNumberValue(PercentComplete.Value); + } + if (Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + if (Optional.IsDefined(Error)) + { + writer.WritePropertyName("error"u8); + JsonSerializer.Serialize(writer, Error); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + OperationStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationStatus)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOperationStatus(document.RootElement, options); + } + + internal static OperationStatus DeserializeOperationStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string id = default; + string resourceId = default; + string name = default; + DateTimeOffset? startTime = default; + DateTimeOffset? endTime = default; + string status = default; + double? percentComplete = default; + ExportResult properties = default; + ResponseError error = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("resourceId"u8)) + { + resourceId = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("startTime"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("endTime"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("status"u8)) + { + status = property.Value.GetString(); + continue; + } + if (property.NameEquals("percentComplete"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + percentComplete = property.Value.GetDouble(); + continue; + } + if (property.NameEquals("properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = ExportResult.DeserializeExportResult(property.Value, options); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new OperationStatus( + id, + resourceId, + name, + startTime, + endTime, + status, + percentComplete, + properties, + error, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{options.Format}' format."); + } + } + + OperationStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeOperationStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OperationStatus)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs new file mode 100644 index 0000000000000..59b5284a03b7e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs @@ -0,0 +1,97 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The status of the LRO operation. + public partial class OperationStatus + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal OperationStatus() + { + } + + /// Initializes a new instance of . + /// The operation status resource id. + /// The fully qualified resource id of the resource for which the operation was performed. + /// The operation name. + /// The start time of the operation. + /// The end time of the operation. + /// The status of the operation. + /// The progress percentage of the operation, ranges from 0 to 100. + /// The Terraform export result. + /// The error object. + /// Keeps track of any properties unknown to the library. + internal OperationStatus(string id, string resourceId, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, string status, double? percentComplete, ExportResult properties, ResponseError error, IDictionary serializedAdditionalRawData) + { + Id = id; + ResourceId = resourceId; + Name = name; + StartOn = startOn; + EndOn = endOn; + Status = status; + PercentComplete = percentComplete; + Properties = properties; + Error = error; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The operation status resource id. + public string Id { get; } + /// The fully qualified resource id of the resource for which the operation was performed. + public string ResourceId { get; } + /// The operation name. + public string Name { get; } + /// The start time of the operation. + public DateTimeOffset? StartOn { get; } + /// The end time of the operation. + public DateTimeOffset? EndOn { get; } + /// The status of the operation. + public string Status { get; } + /// The progress percentage of the operation, ranges from 0 to 100. + public double? PercentComplete { get; } + /// The Terraform export result. + public ExportResult Properties { get; } + /// The error object. + public ResponseError Error { get; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index 6f02e9cc838f7..d1c6817ee8e33 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using System; -using System.Text.Json; using System.Threading.Tasks; using Azure.Core; using Azure.Core.TestFramework; @@ -38,27 +36,11 @@ public async Task TearDown() public async Task ExportTerraform() { string rgName = _resourceGroup.Data.Name; - ArmOperation armOperation = await DefaultSubscription.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); - string responseContent = armOperation.GetRawResponse().Content.ToString(); - string hcl = HclFromResponseContent(responseContent); + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); + string hcl = operationStatus.Value.Properties.Configuration; Assert.That(hcl, Does.Contain("azurerm_resource_group")); Assert.That(hcl, Does.Contain(rgName)); } - - private static string HclFromResponseContent(string responseContent) - { - try - { - using (JsonDocument doc = JsonDocument.Parse(responseContent)) - { - return doc.RootElement.GetProperty("properties").GetProperty("configuration").GetString(); - } - } - catch (Exception e) - { - throw new Exception("Error parsing json string and accessing 'properties.configuration' path", e); - } - } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 08d79a8309cad..73c22b9afc031 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: dce461bb4e89238f383f0a165d95859f54638fd6 +commit: to-be-updated-after-pr-30918-merges repo: Azure/azure-rest-api-specs From 6da82ee2299a369963cc92d18935879db68b37c8 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 9 Oct 2024 13:13:28 +1100 Subject: [PATCH 12/33] Update tsp-location.yaml commit hash --- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 73c22b9afc031..bbb72648b7a83 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: to-be-updated-after-pr-30918-merges +commit: d77c9fb25ccfd04ba25fe80e1c3f5745c92fafa6 repo: Azure/azure-rest-api-specs From ea21db26b6aa24b98866370cb10baa70e3735c35 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 9 Oct 2024 13:22:01 +1100 Subject: [PATCH 13/33] Updated API file --- ...esourceManager.Terraform.netstandard2.0.cs | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index 19d5312faacb5..50268c1a0df21 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -2,8 +2,8 @@ namespace Azure.ResourceManager.Terraform { public static partial class TerraformExtensions { - public static Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task ExportTerraformAzureTerraformClientAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> ExportTerraformAzureTerraformClientAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static Azure.ResourceManager.ArmOperation GetOperationStatus(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public static System.Threading.Tasks.Task GetOperationStatusAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } @@ -13,8 +13,8 @@ namespace Azure.ResourceManager.Terraform.Mocking public partial class MockableTerraformSubscriptionResource : Azure.ResourceManager.ArmResource { protected MockableTerraformSubscriptionResource() { } - public virtual Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task ExportTerraformAzureTerraformClientAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExportTerraformAzureTerraformClientAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.ResourceManager.ArmOperation GetOperationStatus(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task GetOperationStatusAsync(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } @@ -25,6 +25,8 @@ public static partial class ArmTerraformModelFactory { public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportResult ExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResources = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.OperationStatus OperationStatus(string id = null, string resourceId = null, string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), string status = null, double? percentComplete = default(double?), Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResponseError error = null) { throw null; } } public abstract partial class BaseExportModel : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { @@ -74,6 +76,36 @@ public ExportResourceGroup(string resourceGroupName) { } string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } + public partial class ExportResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal ExportResult() { } + public string Configuration { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Errors { get { throw null; } } + public System.Collections.Generic.IReadOnlyList SkippedResources { get { throw null; } } + Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class OperationStatus : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal OperationStatus() { } + public System.DateTimeOffset? EndOn { get { throw null; } } + public Azure.ResponseError Error { get { throw null; } } + public string Id { get { throw null; } } + public string Name { get { throw null; } } + public double? PercentComplete { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.ExportResult Properties { get { throw null; } } + public string ResourceId { get { throw null; } } + public System.DateTimeOffset? StartOn { get { throw null; } } + public string Status { get { throw null; } } + Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct TargetProvider : System.IEquatable { From 811553076c12f3a7cabd7fa65d3f0925d5b17aea Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 9 Oct 2024 17:25:16 +1100 Subject: [PATCH 14/33] Update ExportTerraform method name using @clientName decorator --- .../Sample_SubscriptionResourceExtensions.cs | 4 +- .../MockableTerraformSubscriptionResource.cs | 8 ++-- .../Extensions/TerraformExtensions.cs | 12 ++--- .../Models/BaseExportModel.Serialization.cs | 11 ++++- .../Models/ExportQuery.Serialization.cs | 44 +++++-------------- .../Models/ExportResource.Serialization.cs | 44 +++++-------------- .../ExportResourceGroup.Serialization.cs | 44 +++++-------------- .../Models/ExportResult.Serialization.cs | 11 ++++- .../Models/OperationStatus.Serialization.cs | 11 ++++- .../UnknownBaseExportModel.Serialization.cs | 44 +++++-------------- .../tests/Tests/ExportTerraformTests.cs | 2 +- .../tsp-location.yaml | 2 +- 12 files changed, 81 insertions(+), 156 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index bb20f7a5667f7..daebc98f20cbf 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -19,7 +19,7 @@ public partial class Sample_SubscriptionResourceExtensions // ExportTerraform [NUnit.Framework.Test] [NUnit.Framework.Ignore("Only verifying that the sample builds")] - public async Task ExportTerraformAzureTerraformClient_ExportTerraform() + public async Task ExportTerraform_ExportTerraform() { // Generated from example definition: 2023-07-01-preview/ExportTerraform.json // this example is just showing the usage of "AzureTerraform_ExportTerraform" operation, for the dependent resources, they will have to be created separately. @@ -37,7 +37,7 @@ public async Task ExportTerraformAzureTerraformClient_ExportTerraform() // invoke the operation BaseExportModel exportParameter = new ExportResourceGroup("rg1"); - ArmOperation lro = await subscriptionResource.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, exportParameter); + ArmOperation lro = await subscriptionResource.ExportTerraformAsync(WaitUntil.Completed, exportParameter); OperationStatus result = lro.Value; Console.WriteLine($"Succeeded: {result}"); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index 446f19d881f03..35d668c13e6fe 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -66,11 +66,11 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// The export parameter. /// The cancellation token to use. /// is null. - public virtual async Task> ExportTerraformAzureTerraformClientAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public virtual async Task> ExportTerraformAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); - using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraformAzureTerraformClient"); + using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { @@ -108,11 +108,11 @@ public virtual async Task> ExportTerraformAzureTer /// The export parameter. /// The cancellation token to use. /// is null. - public virtual ArmOperation ExportTerraformAzureTerraformClient(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public virtual ArmOperation ExportTerraform(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); - using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraformAzureTerraformClient"); + using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index c97085255b00f..0b338177c7be2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -40,7 +40,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -48,11 +48,11 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// The export parameter. /// The cancellation token to use. /// or is null. - public static async Task> ExportTerraformAzureTerraformClientAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAzureTerraformClientAsync(waitUntil, exportParameter, cancellationToken).ConfigureAwait(false); + return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAsync(waitUntil, exportParameter, cancellationToken).ConfigureAwait(false); } /// @@ -73,7 +73,7 @@ public static async Task> ExportTerraformAzureTerr /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -81,11 +81,11 @@ public static async Task> ExportTerraformAzureTerr /// The export parameter. /// The cancellation token to use. /// or is null. - public static ArmOperation ExportTerraformAzureTerraformClient(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public static ArmOperation ExportTerraform(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAzureTerraformClient(waitUntil, exportParameter, cancellationToken); + return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraform(waitUntil, exportParameter, cancellationToken); } /// diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs index d37b80af3d1a2..4c89f19dd15b0 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs @@ -18,6 +18,15 @@ public partial class BaseExportModel : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); } - writer.WriteStartObject(); writer.WritePropertyName("type"u8); writer.WriteStringValue(Type.ToString()); if (Optional.IsDefined(TargetProvider)) @@ -58,7 +66,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO #endif } } - writer.WriteEndObject(); } BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs index 1f99d3ef7b1b4..a4dbf2b84201f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs @@ -18,6 +18,15 @@ public partial class ExportQuery : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio throw new FormatException($"The model {nameof(ExportQuery)} does not support writing '{format}' format."); } - writer.WriteStartObject(); + base.JsonModelWriteCore(writer, options); writer.WritePropertyName("query"u8); writer.WriteStringValue(Query); if (Optional.IsDefined(NamePattern)) @@ -38,39 +47,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio writer.WritePropertyName("recursive"u8); writer.WriteBooleanValue(Recursive.Value); } - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.ToString()); - if (Optional.IsDefined(TargetProvider)) - { - writer.WritePropertyName("targetProvider"u8); - writer.WriteStringValue(TargetProvider.Value.ToString()); - } - if (Optional.IsDefined(FullProperties)) - { - writer.WritePropertyName("fullProperties"u8); - writer.WriteBooleanValue(FullProperties.Value); - } - if (Optional.IsDefined(MaskSensitive)) - { - writer.WritePropertyName("maskSensitive"u8); - writer.WriteBooleanValue(MaskSensitive.Value); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); } ExportQuery IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs index 3fd6e808fc94e..25934be472b09 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs @@ -18,6 +18,15 @@ public partial class ExportResource : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp throw new FormatException($"The model {nameof(ExportResource)} does not support writing '{format}' format."); } - writer.WriteStartObject(); + base.JsonModelWriteCore(writer, options); writer.WritePropertyName("resourceIds"u8); writer.WriteStartArray(); foreach (var item in ResourceIds) @@ -48,39 +57,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp writer.WritePropertyName("namePattern"u8); writer.WriteStringValue(NamePattern); } - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.ToString()); - if (Optional.IsDefined(TargetProvider)) - { - writer.WritePropertyName("targetProvider"u8); - writer.WriteStringValue(TargetProvider.Value.ToString()); - } - if (Optional.IsDefined(FullProperties)) - { - writer.WritePropertyName("fullProperties"u8); - writer.WriteBooleanValue(FullProperties.Value); - } - if (Optional.IsDefined(MaskSensitive)) - { - writer.WritePropertyName("maskSensitive"u8); - writer.WriteBooleanValue(MaskSensitive.Value); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); } ExportResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs index 639f168c3f91e..e0b083ce3f6a1 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs @@ -18,6 +18,15 @@ public partial class ExportResourceGroup : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support writing '{format}' format."); } - writer.WriteStartObject(); + base.JsonModelWriteCore(writer, options); writer.WritePropertyName("resourceGroupName"u8); writer.WriteStringValue(ResourceGroupName); if (Optional.IsDefined(NamePattern)) @@ -33,39 +42,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri writer.WritePropertyName("namePattern"u8); writer.WriteStringValue(NamePattern); } - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.ToString()); - if (Optional.IsDefined(TargetProvider)) - { - writer.WritePropertyName("targetProvider"u8); - writer.WriteStringValue(TargetProvider.Value.ToString()); - } - if (Optional.IsDefined(FullProperties)) - { - writer.WritePropertyName("fullProperties"u8); - writer.WriteBooleanValue(FullProperties.Value); - } - if (Optional.IsDefined(MaskSensitive)) - { - writer.WritePropertyName("maskSensitive"u8); - writer.WriteBooleanValue(MaskSensitive.Value); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); } ExportResourceGroup IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs index e45a32435af32..d4d8c37aff524 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs @@ -18,6 +18,15 @@ public partial class ExportResult : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti throw new FormatException($"The model {nameof(ExportResult)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsDefined(Configuration)) { writer.WritePropertyName("configuration"u8); @@ -66,7 +74,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti #endif } } - writer.WriteEndObject(); } ExportResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs index ef105411c9a9e..c2891756492f1 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs @@ -18,6 +18,15 @@ public partial class OperationStatus : IUtf8JsonSerializable, IJsonModel ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,7 +34,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{format}' format."); } - writer.WriteStartObject(); if (Optional.IsDefined(Id)) { writer.WritePropertyName("id"u8); @@ -86,7 +94,6 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO #endif } } - writer.WriteEndObject(); } OperationStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs index d5145cdb2bb1b..ecc6dae201b1e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs @@ -18,6 +18,15 @@ internal partial class UnknownBaseExportModel : IUtf8JsonSerializable, IJsonMode void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") @@ -25,40 +34,7 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); } - writer.WriteStartObject(); - writer.WritePropertyName("type"u8); - writer.WriteStringValue(Type.ToString()); - if (Optional.IsDefined(TargetProvider)) - { - writer.WritePropertyName("targetProvider"u8); - writer.WriteStringValue(TargetProvider.Value.ToString()); - } - if (Optional.IsDefined(FullProperties)) - { - writer.WritePropertyName("fullProperties"u8); - writer.WriteBooleanValue(FullProperties.Value); - } - if (Optional.IsDefined(MaskSensitive)) - { - writer.WritePropertyName("maskSensitive"u8); - writer.WriteBooleanValue(MaskSensitive.Value); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - writer.WriteEndObject(); + base.JsonModelWriteCore(writer, options); } BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index d1c6817ee8e33..4331b527fd6e2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -36,7 +36,7 @@ public async Task TearDown() public async Task ExportTerraform() { string rgName = _resourceGroup.Data.Name; - ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAzureTerraformClientAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); string hcl = operationStatus.Value.Properties.Configuration; Assert.That(hcl, Does.Contain("azurerm_resource_group")); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index bbb72648b7a83..644b2fec57c5e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: d77c9fb25ccfd04ba25fe80e1c3f5745c92fafa6 +commit: to-be-updated-once-spec-changes-merged repo: Azure/azure-rest-api-specs From 34e88ca088cc5a2c58c281cb072e1c6a54a95f33 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 11 Oct 2024 13:44:16 +1100 Subject: [PATCH 15/33] Regen SDK based on https://github.com/Azure/azure-rest-api-specs/pull/30975/commits/35f472949fcf1e96bd1aac92e048a174ca649bfc --- .../Sample_SubscriptionResourceExtensions.cs | 11 +- .../src/Generated/ArmTerraformModelFactory.cs | 24 ++-- .../MockableTerraformSubscriptionResource.cs | 52 ++++---- .../Extensions/TerraformExtensions.cs | 20 ++-- .../TerraformArmOperation.cs | 94 --------------- .../Models/OperationStatus.Serialization.cs | 67 ++++------- .../src/Generated/Models/OperationStatus.cs | 55 +++++---- .../Models/ResourceProvisioningState.cs | 54 +++++++++ ...ns.cs => ExportTerraformRestOperations.cs} | 82 ++++++++++++- .../OperationStatusesRestOperations.cs | 113 ------------------ 10 files changed, 230 insertions(+), 342 deletions(-) delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/{AzureTerraformRestOperations.cs => ExportTerraformRestOperations.cs} (55%) delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index daebc98f20cbf..5cae4f39d65c8 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -22,7 +22,7 @@ public partial class Sample_SubscriptionResourceExtensions public async Task ExportTerraform_ExportTerraform() { // Generated from example definition: 2023-07-01-preview/ExportTerraform.json - // this example is just showing the usage of "AzureTerraform_ExportTerraform" operation, for the dependent resources, they will have to be created separately. + // this example is just showing the usage of "ExportTerraform_ExportTerraform" 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(); @@ -46,10 +46,10 @@ public async Task ExportTerraform_ExportTerraform() // Get specific operation status [NUnit.Framework.Test] [NUnit.Framework.Ignore("Only verifying that the sample builds")] - public async Task GetOperationStatus_GetSpecificOperationStatus() + public async Task OperationStatuses_GetSpecificOperationStatus() { // Generated from example definition: 2023-07-01-preview/GetOperationStatus.json - // this example is just showing the usage of "OperationStatuses_Get" operation, for the dependent resources, they will have to be created separately. + // this example is just showing the usage of "ExportTerraform_OperationStatuses" 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(); @@ -64,9 +64,10 @@ public async Task GetOperationStatus_GetSpecificOperationStatus() // invoke the operation string operationId = "00000000-0000-0000-0000-000000000000"; - await subscriptionResource.GetOperationStatusAsync(WaitUntil.Completed, operationId); + ArmOperation lro = await subscriptionResource.OperationStatusesAsync(WaitUntil.Completed, operationId); + OperationStatus result = lro.Value; - Console.WriteLine($"Succeeded"); + Console.WriteLine($"Succeeded: {result}"); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index cb000ccc05eb0..8c4a00f1cf013 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -55,27 +55,23 @@ public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProv } /// Initializes a new instance of . - /// The operation status resource id. - /// The fully qualified resource id of the resource for which the operation was performed. - /// The operation name. - /// The start time of the operation. - /// The end time of the operation. - /// The status of the operation. - /// The progress percentage of the operation, ranges from 0 to 100. - /// The Terraform export result. - /// The error object. + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + /// The operation status. + /// The name of the operationStatus resource. + /// Operation start time. + /// Operation complete time. + /// The progress made toward completing the operation. + /// Errors that occurred if the operation ended with Canceled or Failed status. /// A new instance for mocking. - public static OperationStatus OperationStatus(string id = null, string resourceId = null, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, string status = null, double? percentComplete = null, ExportResult properties = null, ResponseError error = null) + public static OperationStatus OperationStatus(ExportResult properties = null, ResourceProvisioningState status = default, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, double? percentComplete = null, ResponseError error = null) { return new OperationStatus( - id, - resourceId, + properties, + status, name, startOn, endOn, - status, percentComplete, - properties, error, serializedAdditionalRawData: null); } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index 35d668c13e6fe..a2f81e9e3de32 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -17,10 +17,8 @@ namespace Azure.ResourceManager.Terraform.Mocking /// A class to add extension methods to SubscriptionResource. public partial class MockableTerraformSubscriptionResource : ArmResource { - private ClientDiagnostics _azureTerraformClientClientDiagnostics; - private AzureTerraformRestOperations _azureTerraformClientRestClient; - private ClientDiagnostics _operationStatusesClientDiagnostics; - private OperationStatusesRestOperations _operationStatusesRestClient; + private ClientDiagnostics _exportTerraformClientDiagnostics; + private ExportTerraformRestOperations _exportTerraformRestClient; /// Initializes a new instance of the class for mocking. protected MockableTerraformSubscriptionResource() @@ -34,10 +32,8 @@ internal MockableTerraformSubscriptionResource(ArmClient client, ResourceIdentif { } - private ClientDiagnostics AzureTerraformClientClientDiagnostics => _azureTerraformClientClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); - private AzureTerraformRestOperations AzureTerraformClientRestClient => _azureTerraformClientRestClient ??= new AzureTerraformRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); - private ClientDiagnostics OperationStatusesClientDiagnostics => _operationStatusesClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); - private OperationStatusesRestOperations OperationStatusesRestClient => _operationStatusesRestClient ??= new OperationStatusesRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); + private ClientDiagnostics ExportTerraformClientDiagnostics => _exportTerraformClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); + private ExportTerraformRestOperations ExportTerraformRestClient => _exportTerraformRestClient ??= new ExportTerraformRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); private string GetApiVersionOrNull(ResourceType resourceType) { @@ -54,7 +50,7 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// /// /// Operation Id - /// AzureTerraform_ExportTerraform + /// ExportTerraform_ExportTerraform /// /// /// Default Api Version @@ -70,12 +66,12 @@ public virtual async Task> ExportTerraformAsync(Wa { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); - using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); + using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = await AzureTerraformClientRestClient.ExportTerraformAsync(Id.SubscriptionId, exportParameter, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + var response = await ExportTerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, exportParameter, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); return operation; @@ -96,7 +92,7 @@ public virtual async Task> ExportTerraformAsync(Wa /// /// /// Operation Id - /// AzureTerraform_ExportTerraform + /// ExportTerraform_ExportTerraform /// /// /// Default Api Version @@ -112,12 +108,12 @@ public virtual ArmOperation ExportTerraform(WaitUntil waitUntil { Argument.AssertNotNull(exportParameter, nameof(exportParameter)); - using var scope = AzureTerraformClientClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); + using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = AzureTerraformClientRestClient.ExportTerraform(Id.SubscriptionId, exportParameter, cancellationToken); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), AzureTerraformClientClientDiagnostics, Pipeline, AzureTerraformClientRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); + var response = ExportTerraformRestClient.ExportTerraform(Id.SubscriptionId, exportParameter, cancellationToken); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) operation.WaitForCompletion(cancellationToken); return operation; @@ -138,7 +134,7 @@ public virtual ArmOperation ExportTerraform(WaitUntil waitUntil /// /// /// Operation Id - /// OperationStatuses_Get + /// ExportTerraform_OperationStatuses /// /// /// Default Api Version @@ -151,18 +147,18 @@ public virtual ArmOperation ExportTerraform(WaitUntil waitUntil /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// is null. - public virtual async Task GetOperationStatusAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public virtual async Task> OperationStatusesAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - using var scope = OperationStatusesClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.GetOperationStatus"); + using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.OperationStatuses"); scope.Start(); try { - var response = await OperationStatusesRestClient.GetAsync(operationId, Id.SubscriptionId, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(OperationStatusesClientDiagnostics, Pipeline, OperationStatusesRestClient.CreateGetRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + var response = await ExportTerraformRestClient.OperationStatusesAsync(operationId, Id.SubscriptionId, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); return operation; } catch (Exception e) @@ -181,7 +177,7 @@ public virtual async Task GetOperationStatusAsync(WaitUntil waitUn /// /// /// Operation Id - /// OperationStatuses_Get + /// ExportTerraform_OperationStatuses /// /// /// Default Api Version @@ -194,18 +190,18 @@ public virtual async Task GetOperationStatusAsync(WaitUntil waitUn /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// is null. - public virtual ArmOperation GetOperationStatus(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public virtual ArmOperation OperationStatuses(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - using var scope = OperationStatusesClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.GetOperationStatus"); + using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.OperationStatuses"); scope.Start(); try { - var response = OperationStatusesRestClient.Get(operationId, Id.SubscriptionId, cancellationToken); - var operation = new TerraformArmOperation(OperationStatusesClientDiagnostics, Pipeline, OperationStatusesRestClient.CreateGetRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + var response = ExportTerraformRestClient.OperationStatuses(operationId, Id.SubscriptionId, cancellationToken); + var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - operation.WaitForCompletionResponse(cancellationToken); + operation.WaitForCompletion(cancellationToken); return operation; } catch (Exception e) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index 0b338177c7be2..64cfbf3268f17 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -31,7 +31,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Operation Id - /// AzureTerraform_ExportTerraform + /// ExportTerraform_ExportTerraform /// /// /// Default Api Version @@ -64,7 +64,7 @@ public static async Task> ExportTerraformAsync(thi /// /// /// Operation Id - /// AzureTerraform_ExportTerraform + /// ExportTerraform_ExportTerraform /// /// /// Default Api Version @@ -97,7 +97,7 @@ public static ArmOperation ExportTerraform(this SubscriptionRes /// /// /// Operation Id - /// OperationStatuses_Get + /// ExportTerraform_OperationStatuses /// /// /// Default Api Version @@ -106,7 +106,7 @@ public static ArmOperation ExportTerraform(this SubscriptionRes /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -115,11 +115,11 @@ public static ArmOperation ExportTerraform(this SubscriptionRes /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// or is null. - public static async Task GetOperationStatusAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public static async Task> OperationStatusesAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return await GetMockableTerraformSubscriptionResource(subscriptionResource).GetOperationStatusAsync(waitUntil, operationId, cancellationToken).ConfigureAwait(false); + return await GetMockableTerraformSubscriptionResource(subscriptionResource).OperationStatusesAsync(waitUntil, operationId, cancellationToken).ConfigureAwait(false); } /// @@ -131,7 +131,7 @@ public static async Task GetOperationStatusAsync(this Subscription /// /// /// Operation Id - /// OperationStatuses_Get + /// ExportTerraform_OperationStatuses /// /// /// Default Api Version @@ -140,7 +140,7 @@ public static async Task GetOperationStatusAsync(this Subscription /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -149,11 +149,11 @@ public static async Task GetOperationStatusAsync(this Subscription /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// or is null. - public static ArmOperation GetOperationStatus(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public static ArmOperation OperationStatuses(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return GetMockableTerraformSubscriptionResource(subscriptionResource).GetOperationStatus(waitUntil, operationId, cancellationToken); + return GetMockableTerraformSubscriptionResource(subscriptionResource).OperationStatuses(waitUntil, operationId, cancellationToken); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs deleted file mode 100644 index 727a5af30d57f..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.ResourceManager.Terraform -{ -#pragma warning disable SA1649 // File name should match first type name - internal class TerraformArmOperation : ArmOperation -#pragma warning restore SA1649 // File name should match first type name - { - private readonly OperationInternal _operation; - private readonly RehydrationToken? _completeRehydrationToken; - private readonly NextLinkOperationImplementation _nextLinkOperation; - private readonly string _operationId; - - /// Initializes a new instance of TerraformArmOperation for mocking. - protected TerraformArmOperation() - { - } - - internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) - { - _operation = OperationInternal.Succeeded(response); - _completeRehydrationToken = rehydrationToken; - _operationId = GetOperationId(rehydrationToken); - } - - internal TerraformArmOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) - { - var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); - if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) - { - _nextLinkOperation = nextLinkOperationValue; - _operationId = _nextLinkOperation.OperationId; - } - else - { - _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); - _operationId = GetOperationId(_completeRehydrationToken); - } - _operation = new OperationInternal(nextLinkOperation, clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); - } - - private string GetOperationId(RehydrationToken? rehydrationToken) - { - if (rehydrationToken is null) - { - return null; - } - var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); - return lroDetails["id"]; - } - /// - public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; - - /// - public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; - - /// - public override bool HasCompleted => _operation.HasCompleted; - - /// - public override Response GetRawResponse() => _operation.RawResponse; - - /// - public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); - - /// - public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); - - /// - public override Response WaitForCompletionResponse(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(cancellationToken); - - /// - public override Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken); - - /// - public override ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(cancellationToken); - - /// - public override ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken); - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs index c2891756492f1..c642c0f93d380 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs @@ -34,17 +34,14 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{format}' format."); } - if (Optional.IsDefined(Id)) + if (options.Format != "W" && Optional.IsDefined(Properties)) { - writer.WritePropertyName("id"u8); - writer.WriteStringValue(Id); - } - if (options.Format != "W" && Optional.IsDefined(ResourceId)) - { - writer.WritePropertyName("resourceId"u8); - writer.WriteStringValue(ResourceId); + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); } - if (Optional.IsDefined(Name)) + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (options.Format != "W" && Optional.IsDefined(Name)) { writer.WritePropertyName("name"u8); writer.WriteStringValue(Name); @@ -59,22 +56,12 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("endTime"u8); writer.WriteStringValue(EndOn.Value, "O"); } - if (Optional.IsDefined(Status)) - { - writer.WritePropertyName("status"u8); - writer.WriteStringValue(Status); - } - if (Optional.IsDefined(PercentComplete)) + if (options.Format != "W" && Optional.IsDefined(PercentComplete)) { writer.WritePropertyName("percentComplete"u8); writer.WriteNumberValue(PercentComplete.Value); } - if (Optional.IsDefined(Properties)) - { - writer.WritePropertyName("properties"u8); - writer.WriteObjectValue(Properties, options); - } - if (Optional.IsDefined(Error)) + if (options.Format != "W" && Optional.IsDefined(Error)) { writer.WritePropertyName("error"u8); JsonSerializer.Serialize(writer, Error); @@ -116,27 +103,29 @@ internal static OperationStatus DeserializeOperationStatus(JsonElement element, { return null; } - string id = default; - string resourceId = default; + ExportResult properties = default; + ResourceProvisioningState status = default; string name = default; DateTimeOffset? startTime = default; DateTimeOffset? endTime = default; - string status = default; double? percentComplete = default; - ExportResult properties = default; ResponseError error = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("id"u8)) + if (property.NameEquals("properties"u8)) { - id = property.Value.GetString(); + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = ExportResult.DeserializeExportResult(property.Value, options); continue; } - if (property.NameEquals("resourceId"u8)) + if (property.NameEquals("status"u8)) { - resourceId = property.Value.GetString(); + status = new ResourceProvisioningState(property.Value.GetString()); continue; } if (property.NameEquals("name"u8)) @@ -162,11 +151,6 @@ internal static OperationStatus DeserializeOperationStatus(JsonElement element, endTime = property.Value.GetDateTimeOffset("O"); continue; } - if (property.NameEquals("status"u8)) - { - status = property.Value.GetString(); - continue; - } if (property.NameEquals("percentComplete"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -176,15 +160,6 @@ internal static OperationStatus DeserializeOperationStatus(JsonElement element, percentComplete = property.Value.GetDouble(); continue; } - if (property.NameEquals("properties"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - properties = ExportResult.DeserializeExportResult(property.Value, options); - continue; - } if (property.NameEquals("error"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -201,14 +176,12 @@ internal static OperationStatus DeserializeOperationStatus(JsonElement element, } serializedAdditionalRawData = rawDataDictionary; return new OperationStatus( - id, - resourceId, + properties, + status, name, startTime, endTime, - status, percentComplete, - properties, error, serializedAdditionalRawData); } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs index 59b5284a03b7e..8712f0044e572 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs @@ -46,52 +46,51 @@ public partial class OperationStatus private IDictionary _serializedAdditionalRawData; /// Initializes a new instance of . - internal OperationStatus() + /// The operation status. + internal OperationStatus(ResourceProvisioningState status) { + Status = status; } /// Initializes a new instance of . - /// The operation status resource id. - /// The fully qualified resource id of the resource for which the operation was performed. - /// The operation name. - /// The start time of the operation. - /// The end time of the operation. - /// The status of the operation. - /// The progress percentage of the operation, ranges from 0 to 100. - /// The Terraform export result. - /// The error object. + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + /// The operation status. + /// The name of the operationStatus resource. + /// Operation start time. + /// Operation complete time. + /// The progress made toward completing the operation. + /// Errors that occurred if the operation ended with Canceled or Failed status. /// Keeps track of any properties unknown to the library. - internal OperationStatus(string id, string resourceId, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, string status, double? percentComplete, ExportResult properties, ResponseError error, IDictionary serializedAdditionalRawData) + internal OperationStatus(ExportResult properties, ResourceProvisioningState status, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, double? percentComplete, ResponseError error, IDictionary serializedAdditionalRawData) { - Id = id; - ResourceId = resourceId; + Properties = properties; + Status = status; Name = name; StartOn = startOn; EndOn = endOn; - Status = status; PercentComplete = percentComplete; - Properties = properties; Error = error; _serializedAdditionalRawData = serializedAdditionalRawData; } - /// The operation status resource id. - public string Id { get; } - /// The fully qualified resource id of the resource for which the operation was performed. - public string ResourceId { get; } - /// The operation name. + /// Initializes a new instance of for deserialization. + internal OperationStatus() + { + } + + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + public ExportResult Properties { get; } + /// The operation status. + public ResourceProvisioningState Status { get; } + /// The name of the operationStatus resource. public string Name { get; } - /// The start time of the operation. + /// Operation start time. public DateTimeOffset? StartOn { get; } - /// The end time of the operation. + /// Operation complete time. public DateTimeOffset? EndOn { get; } - /// The status of the operation. - public string Status { get; } - /// The progress percentage of the operation, ranges from 0 to 100. + /// The progress made toward completing the operation. public double? PercentComplete { get; } - /// The Terraform export result. - public ExportResult Properties { get; } - /// The error object. + /// Errors that occurred if the operation ended with Canceled or Failed status. public ResponseError Error { get; } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs new file mode 100644 index 0000000000000..5a69a96b13bad --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The provisioning state of a resource type. + public readonly partial struct ResourceProvisioningState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ResourceProvisioningState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SucceededValue = "Succeeded"; + private const string FailedValue = "Failed"; + private const string CanceledValue = "Canceled"; + + /// Resource has been created. + public static ResourceProvisioningState Succeeded { get; } = new ResourceProvisioningState(SucceededValue); + /// Resource creation failed. + public static ResourceProvisioningState Failed { get; } = new ResourceProvisioningState(FailedValue); + /// Resource creation was canceled. + public static ResourceProvisioningState Canceled { get; } = new ResourceProvisioningState(CanceledValue); + /// Determines if two values are the same. + public static bool operator ==(ResourceProvisioningState left, ResourceProvisioningState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ResourceProvisioningState left, ResourceProvisioningState right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ResourceProvisioningState(string value) => new ResourceProvisioningState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ResourceProvisioningState other && Equals(other); + /// + public bool Equals(ResourceProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs similarity index 55% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs index be1edccefbc71..966d977ea0234 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/AzureTerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs @@ -14,20 +14,20 @@ namespace Azure.ResourceManager.Terraform { - internal partial class AzureTerraformRestOperations + internal partial class ExportTerraformRestOperations { private readonly TelemetryDetails _userAgent; private readonly HttpPipeline _pipeline; private readonly Uri _endpoint; private readonly string _apiVersion; - /// Initializes a new instance of AzureTerraformRestOperations. + /// Initializes a new instance of ExportTerraformRestOperations. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The application id to use for user agent. /// The to use. /// The API version to use for this operation. /// or is null. - public AzureTerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) + public ExportTerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) { _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); _endpoint = endpoint ?? new Uri("https://management.azure.com"); @@ -110,5 +110,81 @@ public Response ExportTerraform(string subscriptionId, BaseExportModel exportPar throw new RequestFailedException(message.Response); } } + + internal RequestUriBuilder CreateOperationStatusesRequestUri(string operationId, string subscriptionId) + { + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); + uri.AppendPath(operationId, true); + uri.AppendQuery("api-version", _apiVersion, true); + return uri; + } + + internal HttpMessage CreateOperationStatusesRequest(string operationId, string subscriptionId) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); + uri.AppendPath(operationId, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// Get the status of a long running azure asynchronous operation. + /// The ID of an ongoing async operation. + /// The ID of the target subscription. The value must be an UUID. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task OperationStatusesAsync(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + + using var message = CreateOperationStatusesRequest(operationId, subscriptionId); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + + /// Get the status of a long running azure asynchronous operation. + /// The ID of an ongoing async operation. + /// The ID of the target subscription. The value must be an UUID. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response OperationStatuses(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + + using var message = CreateOperationStatusesRequest(operationId, subscriptionId); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + case 202: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs deleted file mode 100644 index fd1a85f2297de..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/OperationStatusesRestOperations.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.ResourceManager.Terraform -{ - internal partial class OperationStatusesRestOperations - { - private readonly TelemetryDetails _userAgent; - private readonly HttpPipeline _pipeline; - private readonly Uri _endpoint; - private readonly string _apiVersion; - - /// Initializes a new instance of OperationStatusesRestOperations. - /// The HTTP pipeline for sending and receiving REST requests and responses. - /// The application id to use for user agent. - /// The to use. - /// The API version to use for this operation. - /// or is null. - public OperationStatusesRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) - { - _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); - _endpoint = endpoint ?? new Uri("https://management.azure.com"); - _apiVersion = apiVersion ?? "2023-07-01-preview"; - _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); - } - - internal RequestUriBuilder CreateGetRequestUri(string operationId, string subscriptionId) - { - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/subscriptions/", false); - uri.AppendPath(subscriptionId, true); - uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); - uri.AppendPath(operationId, true); - uri.AppendQuery("api-version", _apiVersion, true); - return uri; - } - - internal HttpMessage CreateGetRequest(string operationId, string subscriptionId) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/subscriptions/", false); - uri.AppendPath(subscriptionId, true); - uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); - uri.AppendPath(operationId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - _userAgent.Apply(message); - return message; - } - - /// Get the status of a long running azure asynchronous operation. - /// The ID of an ongoing async operation. - /// The ID of the target subscription. The value must be an UUID. - /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public async Task GetAsync(string operationId, string subscriptionId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - - using var message = CreateGetRequest(operationId, subscriptionId); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 200: - case 202: - return message.Response; - default: - throw new RequestFailedException(message.Response); - } - } - - /// Get the status of a long running azure asynchronous operation. - /// The ID of an ongoing async operation. - /// The ID of the target subscription. The value must be an UUID. - /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public Response Get(string operationId, string subscriptionId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - - using var message = CreateGetRequest(operationId, subscriptionId); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 200: - case 202: - return message.Response; - default: - throw new RequestFailedException(message.Response); - } - } - } -} From 942037b2a46eb60ea449d5d308ebb99f5c512e42 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 11 Oct 2024 15:08:29 +1100 Subject: [PATCH 16/33] Added test case for OperationStatuses, pushe new test recording files --- .../Azure.ResourceManager.Terraform/assets.json | 2 +- .../tests/Tests/ExportTerraformTests.cs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 8829021faba16..45e0caae6fd87 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "net/terraform/Azure.ResourceManager.Terraform_b8ab15c5c5" + "Tag": "net/terraform/Azure.ResourceManager.Terraform_d87638c046" } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index 4331b527fd6e2..b619407768586 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -33,7 +33,7 @@ public async Task TearDown() [TestCase] [RecordedTest] - public async Task ExportTerraform() + public async Task ExportTerraformTest() { string rgName = _resourceGroup.Data.Name; ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); @@ -42,5 +42,17 @@ public async Task ExportTerraform() Assert.That(hcl, Does.Contain("azurerm_resource_group")); Assert.That(hcl, Does.Contain(rgName)); } + + [TestCase] + [RecordedTest] + public async Task OperationStatusesTest() + { + string rgName = _resourceGroup.Data.Name; + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Started, new ExportResourceGroup(rgName)); + + ArmOperation armOperation = await DefaultSubscription.OperationStatusesAsync(WaitUntil.Completed, operationStatus.Id); + + Assert.That(armOperation.HasCompleted, Is.True); + } } } From 37a586635faa4287a91812405e821a0f46e12656 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 15 Oct 2024 11:18:46 +1100 Subject: [PATCH 17/33] Updated SDK based on specs https://github.com/Azure/azure-rest-api-specs/pull/30975/commits/fe2ce8eb76143def2c3b06b5a1431a765f8352a6 --- .../Sample_SubscriptionResourceExtensions.cs | 5 +- .../MockableTerraformSubscriptionResource.cs | 16 ++-- .../Extensions/TerraformExtensions.cs | 4 +- .../TerraformArmOperation.cs | 94 +++++++++++++++++++ .../ExportTerraformRestOperations.cs | 28 +++--- .../tests/Tests/ExportTerraformTests.cs | 2 +- 6 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index 5cae4f39d65c8..6391deb1578ff 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -64,10 +64,9 @@ public async Task OperationStatuses_GetSpecificOperationStatus() // invoke the operation string operationId = "00000000-0000-0000-0000-000000000000"; - ArmOperation lro = await subscriptionResource.OperationStatusesAsync(WaitUntil.Completed, operationId); - OperationStatus result = lro.Value; + await subscriptionResource.OperationStatusesAsync(WaitUntil.Completed, operationId); - Console.WriteLine($"Succeeded: {result}"); + Console.WriteLine($"Succeeded"); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index a2f81e9e3de32..e964643c40dfd 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -147,7 +147,7 @@ public virtual ArmOperation ExportTerraform(WaitUntil waitUntil /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// is null. - public virtual async Task> OperationStatusesAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public virtual async Task OperationStatusesAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); @@ -155,10 +155,10 @@ public virtual async Task> OperationStatusesAsync( scope.Start(); try { - var response = await ExportTerraformRestClient.OperationStatusesAsync(operationId, Id.SubscriptionId, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + var response = await ExportTerraformRestClient.OperationStatusesAsync(Id.SubscriptionId, operationId, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(Id.SubscriptionId, operationId).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); + await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); return operation; } catch (Exception e) @@ -190,7 +190,7 @@ public virtual async Task> OperationStatusesAsync( /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// is null. - public virtual ArmOperation OperationStatuses(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public virtual ArmOperation OperationStatuses(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); @@ -198,10 +198,10 @@ public virtual ArmOperation OperationStatuses(WaitUntil waitUnt scope.Start(); try { - var response = ExportTerraformRestClient.OperationStatuses(operationId, Id.SubscriptionId, cancellationToken); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(operationId, Id.SubscriptionId).Request, response, OperationFinalStateVia.Location); + var response = ExportTerraformRestClient.OperationStatuses(Id.SubscriptionId, operationId, cancellationToken); + var operation = new TerraformArmOperation(ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(Id.SubscriptionId, operationId).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) - operation.WaitForCompletion(cancellationToken); + operation.WaitForCompletionResponse(cancellationToken); return operation; } catch (Exception e) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index 64cfbf3268f17..f55c33419366d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -115,7 +115,7 @@ public static ArmOperation ExportTerraform(this SubscriptionRes /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// or is null. - public static async Task> OperationStatusesAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public static async Task OperationStatusesAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); @@ -149,7 +149,7 @@ public static async Task> OperationStatusesAsync(t /// The cancellation token to use. /// is an empty string, and was expected to be non-empty. /// or is null. - public static ArmOperation OperationStatuses(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) + public static ArmOperation OperationStatuses(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs new file mode 100644 index 0000000000000..727a5af30d57f --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ +#pragma warning disable SA1649 // File name should match first type name + internal class TerraformArmOperation : ArmOperation +#pragma warning restore SA1649 // File name should match first type name + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of TerraformArmOperation for mocking. + protected TerraformArmOperation() + { + } + + internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + internal TerraformArmOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) + { + _nextLinkOperation = nextLinkOperationValue; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal(nextLinkOperation, clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); + } + + private string GetOperationId(RehydrationToken? rehydrationToken) + { + if (rehydrationToken is null) + { + return null; + } + var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); + return lroDetails["id"]; + } + /// + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override bool HasCompleted => _operation.HasCompleted; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletionResponse(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(cancellationToken); + + /// + public override Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(cancellationToken); + + /// + public override ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken); + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs index 966d977ea0234..f1293271c03bf 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs @@ -111,7 +111,7 @@ public Response ExportTerraform(string subscriptionId, BaseExportModel exportPar } } - internal RequestUriBuilder CreateOperationStatusesRequestUri(string operationId, string subscriptionId) + internal RequestUriBuilder CreateOperationStatusesRequestUri(string subscriptionId, string operationId) { var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); @@ -123,7 +123,7 @@ internal RequestUriBuilder CreateOperationStatusesRequestUri(string operationId, return uri; } - internal HttpMessage CreateOperationStatusesRequest(string operationId, string subscriptionId) + internal HttpMessage CreateOperationStatusesRequest(string subscriptionId, string operationId) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -142,17 +142,17 @@ internal HttpMessage CreateOperationStatusesRequest(string operationId, string s } /// Get the status of a long running azure asynchronous operation. - /// The ID of an ongoing async operation. /// The ID of the target subscription. The value must be an UUID. + /// The ID of an ongoing async operation. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public async Task OperationStatusesAsync(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task OperationStatusesAsync(string subscriptionId, string operationId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - using var message = CreateOperationStatusesRequest(operationId, subscriptionId); + using var message = CreateOperationStatusesRequest(subscriptionId, operationId); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { @@ -165,17 +165,17 @@ public async Task OperationStatusesAsync(string operationId, string su } /// Get the status of a long running azure asynchronous operation. - /// The ID of an ongoing async operation. /// The ID of the target subscription. The value must be an UUID. + /// The ID of an ongoing async operation. /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public Response OperationStatuses(string operationId, string subscriptionId, CancellationToken cancellationToken = default) + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response OperationStatuses(string subscriptionId, string operationId, CancellationToken cancellationToken = default) { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - using var message = CreateOperationStatusesRequest(operationId, subscriptionId); + using var message = CreateOperationStatusesRequest(subscriptionId, operationId); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index b619407768586..4895ef8ab25e2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -50,7 +50,7 @@ public async Task OperationStatusesTest() string rgName = _resourceGroup.Data.Name; ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Started, new ExportResourceGroup(rgName)); - ArmOperation armOperation = await DefaultSubscription.OperationStatusesAsync(WaitUntil.Completed, operationStatus.Id); + ArmOperation armOperation = await DefaultSubscription.OperationStatusesAsync(WaitUntil.Completed, operationStatus.Id); Assert.That(armOperation.HasCompleted, Is.True); } From a6497bf9000f9d12be558bd600106fd43a93ffaf Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 15 Oct 2024 13:21:28 +1100 Subject: [PATCH 18/33] Updated API file --- ...esourceManager.Terraform.netstandard2.0.cs | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index 50268c1a0df21..b76203893ff60 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -2,10 +2,10 @@ namespace Azure.ResourceManager.Terraform { public static partial class TerraformExtensions { - public static Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task> ExportTerraformAzureTerraformClientAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static Azure.ResourceManager.ArmOperation GetOperationStatus(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task GetOperationStatusAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation ExportTerraform(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> ExportTerraformAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation OperationStatuses(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task OperationStatusesAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Mocking @@ -13,10 +13,10 @@ namespace Azure.ResourceManager.Terraform.Mocking public partial class MockableTerraformSubscriptionResource : Azure.ResourceManager.ArmResource { protected MockableTerraformSubscriptionResource() { } - public virtual Azure.ResourceManager.ArmOperation ExportTerraformAzureTerraformClient(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExportTerraformAzureTerraformClientAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.ResourceManager.ArmOperation GetOperationStatus(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task GetOperationStatusAsync(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation ExportTerraform(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExportTerraformAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation OperationStatuses(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task OperationStatusesAsync(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Models @@ -26,7 +26,7 @@ public static partial class ArmTerraformModelFactory public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.ExportResult ExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResources = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } - public static Azure.ResourceManager.Terraform.Models.OperationStatus OperationStatus(string id = null, string resourceId = null, string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), string status = null, double? percentComplete = default(double?), Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResponseError error = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.OperationStatus OperationStatus(Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } public abstract partial class BaseExportModel : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { @@ -34,6 +34,7 @@ protected BaseExportModel() { } public bool? FullProperties { get { throw null; } set { } } public bool? MaskSensitive { get { throw null; } set { } } public Azure.ResourceManager.Terraform.Models.TargetProvider? TargetProvider { get { throw null; } set { } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -46,6 +47,7 @@ public ExportQuery(string query) { } public string NamePattern { get { throw null; } set { } } public string Query { get { throw null; } } public bool? Recursive { get { throw null; } set { } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -59,6 +61,7 @@ public ExportResource(System.Collections.Generic.IEnumerable resourceIds public System.Collections.Generic.IList ResourceIds { get { throw null; } } public string ResourceName { get { throw null; } set { } } public string ResourceType { get { throw null; } set { } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -70,6 +73,7 @@ public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Model public ExportResourceGroup(string resourceGroupName) { } public string NamePattern { get { throw null; } set { } } public string ResourceGroupName { get { throw null; } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -82,6 +86,7 @@ internal ExportResult() { } public string Configuration { get { throw null; } } public System.Collections.Generic.IReadOnlyList Errors { get { throw null; } } public System.Collections.Generic.IReadOnlyList SkippedResources { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -93,13 +98,12 @@ public partial class OperationStatus : System.ClientModel.Primitives.IJsonModel< internal OperationStatus() { } public System.DateTimeOffset? EndOn { get { throw null; } } public Azure.ResponseError Error { get { throw null; } } - public string Id { get { throw null; } } public string Name { get { throw null; } } public double? PercentComplete { get { throw null; } } public Azure.ResourceManager.Terraform.Models.ExportResult Properties { get { throw null; } } - public string ResourceId { get { throw null; } } public System.DateTimeOffset? StartOn { get { throw null; } } - public string Status { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Status { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -107,6 +111,25 @@ internal OperationStatus() { } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct ResourceProvisioningState : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ResourceProvisioningState(string value) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Canceled { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Failed { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Succeeded { get { throw null; } } + public bool Equals(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState right) { throw null; } + public static implicit operator Azure.ResourceManager.Terraform.Models.ResourceProvisioningState (string value) { throw null; } + public static bool operator !=(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState right) { throw null; } + public override string ToString() { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct TargetProvider : System.IEquatable { private readonly object _dummy; From 7840361c8066b2c1c23493821b771062ae681f83 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 18 Oct 2024 12:07:46 +1100 Subject: [PATCH 19/33] Re-generated SDK with new version --- .../assets.json | 2 +- .../Sample_SubscriptionResourceExtensions.cs | 31 +-- .../src/Generated/ArmTerraformModelFactory.cs | 22 -- .../MockableTerraformSubscriptionResource.cs | 118 +--------- .../Extensions/TerraformExtensions.cs | 90 +------ .../OperationStatusOperationSource.cs | 30 --- .../TerraformArmOperation.cs | 94 -------- .../TerraformArmOperationOfT.cs | 100 -------- .../Models/OperationStatus.Serialization.cs | 220 ------------------ .../src/Generated/Models/OperationStatus.cs | 96 -------- .../Models/ResourceProvisioningState.cs | 54 ----- .../ExportTerraformRestOperations.cs | 121 +++------- .../tests/Tests/ExportTerraformTests.cs | 16 +- 13 files changed, 55 insertions(+), 939 deletions(-) delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 45e0caae6fd87..1e8c0b20696bd 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "net/terraform/Azure.ResourceManager.Terraform_d87638c046" + "Tag": "" } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index 6391deb1578ff..86df234cff60e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -36,37 +36,10 @@ public async Task ExportTerraform_ExportTerraform() SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); // invoke the operation - BaseExportModel exportParameter = new ExportResourceGroup("rg1"); - ArmOperation lro = await subscriptionResource.ExportTerraformAsync(WaitUntil.Completed, exportParameter); - OperationStatus result = lro.Value; + BaseExportModel body = new ExportResourceGroup("rg1"); + ExportResult result = await subscriptionResource.ExportTerraformAsync(body); Console.WriteLine($"Succeeded: {result}"); } - - // Get specific operation status - [NUnit.Framework.Test] - [NUnit.Framework.Ignore("Only verifying that the sample builds")] - public async Task OperationStatuses_GetSpecificOperationStatus() - { - // Generated from example definition: 2023-07-01-preview/GetOperationStatus.json - // this example is just showing the usage of "ExportTerraform_OperationStatuses" 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 subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); - - // invoke the operation - string operationId = "00000000-0000-0000-0000-000000000000"; - await subscriptionResource.OperationStatusesAsync(WaitUntil.Completed, operationId); - - Console.WriteLine($"Succeeded"); - } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 8c4a00f1cf013..4fecfe9e759d9 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -54,28 +54,6 @@ public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProv namePattern); } - /// Initializes a new instance of . - /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. - /// The operation status. - /// The name of the operationStatus resource. - /// Operation start time. - /// Operation complete time. - /// The progress made toward completing the operation. - /// Errors that occurred if the operation ended with Canceled or Failed status. - /// A new instance for mocking. - public static OperationStatus OperationStatus(ExportResult properties = null, ResourceProvisioningState status = default, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, double? percentComplete = null, ResponseError error = null) - { - return new OperationStatus( - properties, - status, - name, - startOn, - endOn, - percentComplete, - error, - serializedAdditionalRawData: null); - } - /// Initializes a new instance of . /// The Terraform configuration content. /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index e964643c40dfd..da327c653b8f1 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -58,23 +58,19 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// /// /// - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// is null. - public virtual async Task> ExportTerraformAsync(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + /// is null. + public virtual async Task> ExportTerraformAsync(BaseExportModel body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + Argument.AssertNotNull(body, nameof(body)); using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = await ExportTerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, exportParameter, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); - if (waitUntil == WaitUntil.Completed) - await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); - return operation; + var response = await ExportTerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, body, cancellationToken).ConfigureAwait(false); + return response; } catch (Exception e) { @@ -100,109 +96,19 @@ public virtual async Task> ExportTerraformAsync(Wa /// /// /// - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// is null. - public virtual ArmOperation ExportTerraform(WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + /// is null. + public virtual Response ExportTerraform(BaseExportModel body, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + Argument.AssertNotNull(body, nameof(body)); using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = ExportTerraformRestClient.ExportTerraform(Id.SubscriptionId, exportParameter, cancellationToken); - var operation = new TerraformArmOperation(new OperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, exportParameter).Request, response, OperationFinalStateVia.Location); - if (waitUntil == WaitUntil.Completed) - operation.WaitForCompletion(cancellationToken); - return operation; - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// - /// Get the status of a long running azure asynchronous operation. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} - /// - /// - /// Operation Id - /// ExportTerraform_OperationStatuses - /// - /// - /// Default Api Version - /// 2023-07-01-preview - /// - /// - /// - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// is an empty string, and was expected to be non-empty. - /// is null. - public virtual async Task OperationStatusesAsync(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - - using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.OperationStatuses"); - scope.Start(); - try - { - var response = await ExportTerraformRestClient.OperationStatusesAsync(Id.SubscriptionId, operationId, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(Id.SubscriptionId, operationId).Request, response, OperationFinalStateVia.Location); - if (waitUntil == WaitUntil.Completed) - await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); - return operation; - } - catch (Exception e) - { - scope.Failed(e); - throw; - } - } - - /// - /// Get the status of a long running azure asynchronous operation. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} - /// - /// - /// Operation Id - /// ExportTerraform_OperationStatuses - /// - /// - /// Default Api Version - /// 2023-07-01-preview - /// - /// - /// - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// is an empty string, and was expected to be non-empty. - /// is null. - public virtual ArmOperation OperationStatuses(WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - - using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.OperationStatuses"); - scope.Start(); - try - { - var response = ExportTerraformRestClient.OperationStatuses(Id.SubscriptionId, operationId, cancellationToken); - var operation = new TerraformArmOperation(ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateOperationStatusesRequest(Id.SubscriptionId, operationId).Request, response, OperationFinalStateVia.Location); - if (waitUntil == WaitUntil.Completed) - operation.WaitForCompletionResponse(cancellationToken); - return operation; + var response = ExportTerraformRestClient.ExportTerraform(Id.SubscriptionId, body, cancellationToken); + return response; } catch (Exception e) { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index f55c33419366d..1f350c4898f08 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -40,19 +40,18 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// or is null. - public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + /// or is null. + public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAsync(waitUntil, exportParameter, cancellationToken).ConfigureAwait(false); + return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAsync(body, cancellationToken).ConfigureAwait(false); } /// @@ -73,87 +72,18 @@ public static async Task> ExportTerraformAsync(thi /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// or is null. - public static ArmOperation ExportTerraform(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + /// or is null. + public static Response ExportTerraform(this SubscriptionResource subscriptionResource, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraform(waitUntil, exportParameter, cancellationToken); - } - - /// - /// Get the status of a long running azure asynchronous operation. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} - /// - /// - /// Operation Id - /// ExportTerraform_OperationStatuses - /// - /// - /// Default Api Version - /// 2023-07-01-preview - /// - /// - /// - /// Mocking - /// To mock this method, please mock instead. - /// - /// - /// The instance the method will execute against. - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// is an empty string, and was expected to be non-empty. - /// or is null. - public static async Task OperationStatusesAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - - return await GetMockableTerraformSubscriptionResource(subscriptionResource).OperationStatusesAsync(waitUntil, operationId, cancellationToken).ConfigureAwait(false); - } - - /// - /// Get the status of a long running azure asynchronous operation. - /// - /// - /// Request Path - /// /subscriptions/{subscriptionId}/providers/Microsoft.AzureTerraform/operationStatuses/{operationId} - /// - /// - /// Operation Id - /// ExportTerraform_OperationStatuses - /// - /// - /// Default Api Version - /// 2023-07-01-preview - /// - /// - /// - /// Mocking - /// To mock this method, please mock instead. - /// - /// - /// The instance the method will execute against. - /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// is an empty string, and was expected to be non-empty. - /// or is null. - public static ArmOperation OperationStatuses(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, string operationId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - - return GetMockableTerraformSubscriptionResource(subscriptionResource).OperationStatuses(waitUntil, operationId, cancellationToken); + return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraform(body, cancellationToken); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs deleted file mode 100644 index 9d82172ef3e3d..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/OperationStatusOperationSource.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Text.Json; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.ResourceManager.Terraform.Models; - -namespace Azure.ResourceManager.Terraform -{ - internal class OperationStatusOperationSource : IOperationSource - { - OperationStatus IOperationSource.CreateResult(Response response, CancellationToken cancellationToken) - { - using var document = JsonDocument.Parse(response.ContentStream); - return OperationStatus.DeserializeOperationStatus(document.RootElement); - } - - async ValueTask IOperationSource.CreateResultAsync(Response response, CancellationToken cancellationToken) - { - using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - return OperationStatus.DeserializeOperationStatus(document.RootElement); - } - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs deleted file mode 100644 index 727a5af30d57f..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperation.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.ResourceManager.Terraform -{ -#pragma warning disable SA1649 // File name should match first type name - internal class TerraformArmOperation : ArmOperation -#pragma warning restore SA1649 // File name should match first type name - { - private readonly OperationInternal _operation; - private readonly RehydrationToken? _completeRehydrationToken; - private readonly NextLinkOperationImplementation _nextLinkOperation; - private readonly string _operationId; - - /// Initializes a new instance of TerraformArmOperation for mocking. - protected TerraformArmOperation() - { - } - - internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) - { - _operation = OperationInternal.Succeeded(response); - _completeRehydrationToken = rehydrationToken; - _operationId = GetOperationId(rehydrationToken); - } - - internal TerraformArmOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) - { - var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); - if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) - { - _nextLinkOperation = nextLinkOperationValue; - _operationId = _nextLinkOperation.OperationId; - } - else - { - _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); - _operationId = GetOperationId(_completeRehydrationToken); - } - _operation = new OperationInternal(nextLinkOperation, clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); - } - - private string GetOperationId(RehydrationToken? rehydrationToken) - { - if (rehydrationToken is null) - { - return null; - } - var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); - return lroDetails["id"]; - } - /// - public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; - - /// - public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; - - /// - public override bool HasCompleted => _operation.HasCompleted; - - /// - public override Response GetRawResponse() => _operation.RawResponse; - - /// - public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); - - /// - public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); - - /// - public override Response WaitForCompletionResponse(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(cancellationToken); - - /// - public override Response WaitForCompletionResponse(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken); - - /// - public override ValueTask WaitForCompletionResponseAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(cancellationToken); - - /// - public override ValueTask WaitForCompletionResponseAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken); - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs deleted file mode 100644 index 23e4d4dba878c..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.Pipeline; - -namespace Azure.ResourceManager.Terraform -{ -#pragma warning disable SA1649 // File name should match first type name - internal class TerraformArmOperation : ArmOperation -#pragma warning restore SA1649 // File name should match first type name - { - private readonly OperationInternal _operation; - private readonly RehydrationToken? _completeRehydrationToken; - private readonly NextLinkOperationImplementation _nextLinkOperation; - private readonly string _operationId; - - /// Initializes a new instance of TerraformArmOperation for mocking. - protected TerraformArmOperation() - { - } - - internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) - { - _operation = OperationInternal.Succeeded(response.GetRawResponse(), response.Value); - _completeRehydrationToken = rehydrationToken; - _operationId = GetOperationId(rehydrationToken); - } - - internal TerraformArmOperation(IOperationSource source, ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) - { - var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); - if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) - { - _nextLinkOperation = nextLinkOperationValue; - _operationId = _nextLinkOperation.OperationId; - } - else - { - _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); - _operationId = GetOperationId(_completeRehydrationToken); - } - _operation = new OperationInternal(NextLinkOperationImplementation.Create(source, nextLinkOperation), clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); - } - - private string GetOperationId(RehydrationToken? rehydrationToken) - { - if (rehydrationToken is null) - { - return null; - } - var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); - return lroDetails["id"]; - } - /// - public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; - - /// - public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; - - /// - public override T Value => _operation.Value; - - /// - public override bool HasValue => _operation.HasValue; - - /// - public override bool HasCompleted => _operation.HasCompleted; - - /// - public override Response GetRawResponse() => _operation.RawResponse; - - /// - public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); - - /// - public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); - - /// - public override Response WaitForCompletion(CancellationToken cancellationToken = default) => _operation.WaitForCompletion(cancellationToken); - - /// - public override Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletion(pollingInterval, cancellationToken); - - /// - public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken); - - /// - public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken); - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs deleted file mode 100644 index c642c0f93d380..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.Serialization.cs +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ClientModel.Primitives; -using System.Collections.Generic; -using System.Text.Json; -using Azure.Core; - -namespace Azure.ResourceManager.Terraform.Models -{ - public partial class OperationStatus : IUtf8JsonSerializable, IJsonModel - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - writer.WriteStartObject(); - JsonModelWriteCore(writer, options); - writer.WriteEndObject(); - } - - /// The JSON writer. - /// The client options for reading and writing models. - protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{format}' format."); - } - - if (options.Format != "W" && Optional.IsDefined(Properties)) - { - writer.WritePropertyName("properties"u8); - writer.WriteObjectValue(Properties, options); - } - writer.WritePropertyName("status"u8); - writer.WriteStringValue(Status.ToString()); - if (options.Format != "W" && Optional.IsDefined(Name)) - { - writer.WritePropertyName("name"u8); - writer.WriteStringValue(Name); - } - if (options.Format != "W" && Optional.IsDefined(StartOn)) - { - writer.WritePropertyName("startTime"u8); - writer.WriteStringValue(StartOn.Value, "O"); - } - if (options.Format != "W" && Optional.IsDefined(EndOn)) - { - writer.WritePropertyName("endTime"u8); - writer.WriteStringValue(EndOn.Value, "O"); - } - if (options.Format != "W" && Optional.IsDefined(PercentComplete)) - { - writer.WritePropertyName("percentComplete"u8); - writer.WriteNumberValue(PercentComplete.Value); - } - if (options.Format != "W" && Optional.IsDefined(Error)) - { - writer.WritePropertyName("error"u8); - JsonSerializer.Serialize(writer, Error); - } - if (options.Format != "W" && _serializedAdditionalRawData != null) - { - foreach (var item in _serializedAdditionalRawData) - { - writer.WritePropertyName(item.Key); -#if NET6_0_OR_GREATER - writer.WriteRawValue(item.Value); -#else - using (JsonDocument document = JsonDocument.Parse(item.Value)) - { - JsonSerializer.Serialize(writer, document.RootElement); - } -#endif - } - } - } - - OperationStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - if (format != "J") - { - throw new FormatException($"The model {nameof(OperationStatus)} does not support reading '{format}' format."); - } - - using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeOperationStatus(document.RootElement, options); - } - - internal static OperationStatus DeserializeOperationStatus(JsonElement element, ModelReaderWriterOptions options = null) - { - options ??= ModelSerializationExtensions.WireOptions; - - if (element.ValueKind == JsonValueKind.Null) - { - return null; - } - ExportResult properties = default; - ResourceProvisioningState status = default; - string name = default; - DateTimeOffset? startTime = default; - DateTimeOffset? endTime = default; - double? percentComplete = default; - ResponseError error = default; - IDictionary serializedAdditionalRawData = default; - Dictionary rawDataDictionary = new Dictionary(); - foreach (var property in element.EnumerateObject()) - { - if (property.NameEquals("properties"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - properties = ExportResult.DeserializeExportResult(property.Value, options); - continue; - } - if (property.NameEquals("status"u8)) - { - status = new ResourceProvisioningState(property.Value.GetString()); - continue; - } - if (property.NameEquals("name"u8)) - { - name = property.Value.GetString(); - continue; - } - if (property.NameEquals("startTime"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - startTime = property.Value.GetDateTimeOffset("O"); - continue; - } - if (property.NameEquals("endTime"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - endTime = property.Value.GetDateTimeOffset("O"); - continue; - } - if (property.NameEquals("percentComplete"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - percentComplete = property.Value.GetDouble(); - continue; - } - if (property.NameEquals("error"u8)) - { - if (property.Value.ValueKind == JsonValueKind.Null) - { - continue; - } - error = JsonSerializer.Deserialize(property.Value.GetRawText()); - continue; - } - if (options.Format != "W") - { - rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); - } - } - serializedAdditionalRawData = rawDataDictionary; - return new OperationStatus( - properties, - status, - name, - startTime, - endTime, - percentComplete, - error, - serializedAdditionalRawData); - } - - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - return ModelReaderWriter.Write(this, options); - default: - throw new FormatException($"The model {nameof(OperationStatus)} does not support writing '{options.Format}' format."); - } - } - - OperationStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) - { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; - - switch (format) - { - case "J": - { - using JsonDocument document = JsonDocument.Parse(data); - return DeserializeOperationStatus(document.RootElement, options); - } - default: - throw new FormatException($"The model {nameof(OperationStatus)} does not support reading '{options.Format}' format."); - } - } - - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs deleted file mode 100644 index 8712f0044e572..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/OperationStatus.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; - -namespace Azure.ResourceManager.Terraform.Models -{ - /// The status of the LRO operation. - public partial class OperationStatus - { - /// - /// Keeps track of any properties unknown to the library. - /// - /// To assign an object to the value of this property use . - /// - /// - /// To assign an already formatted json string to this property use . - /// - /// - /// Examples: - /// - /// - /// BinaryData.FromObjectAsJson("foo") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromString("\"foo\"") - /// Creates a payload of "foo". - /// - /// - /// BinaryData.FromObjectAsJson(new { key = "value" }) - /// Creates a payload of { "key": "value" }. - /// - /// - /// BinaryData.FromString("{\"key\": \"value\"}") - /// Creates a payload of { "key": "value" }. - /// - /// - /// - /// - private IDictionary _serializedAdditionalRawData; - - /// Initializes a new instance of . - /// The operation status. - internal OperationStatus(ResourceProvisioningState status) - { - Status = status; - } - - /// Initializes a new instance of . - /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. - /// The operation status. - /// The name of the operationStatus resource. - /// Operation start time. - /// Operation complete time. - /// The progress made toward completing the operation. - /// Errors that occurred if the operation ended with Canceled or Failed status. - /// Keeps track of any properties unknown to the library. - internal OperationStatus(ExportResult properties, ResourceProvisioningState status, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, double? percentComplete, ResponseError error, IDictionary serializedAdditionalRawData) - { - Properties = properties; - Status = status; - Name = name; - StartOn = startOn; - EndOn = endOn; - PercentComplete = percentComplete; - Error = error; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - - /// Initializes a new instance of for deserialization. - internal OperationStatus() - { - } - - /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. - public ExportResult Properties { get; } - /// The operation status. - public ResourceProvisioningState Status { get; } - /// The name of the operationStatus resource. - public string Name { get; } - /// Operation start time. - public DateTimeOffset? StartOn { get; } - /// Operation complete time. - public DateTimeOffset? EndOn { get; } - /// The progress made toward completing the operation. - public double? PercentComplete { get; } - /// Errors that occurred if the operation ended with Canceled or Failed status. - public ResponseError Error { get; } - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs deleted file mode 100644 index 5a69a96b13bad..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.ResourceManager.Terraform.Models -{ - /// The provisioning state of a resource type. - public readonly partial struct ResourceProvisioningState : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public ResourceProvisioningState(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string SucceededValue = "Succeeded"; - private const string FailedValue = "Failed"; - private const string CanceledValue = "Canceled"; - - /// Resource has been created. - public static ResourceProvisioningState Succeeded { get; } = new ResourceProvisioningState(SucceededValue); - /// Resource creation failed. - public static ResourceProvisioningState Failed { get; } = new ResourceProvisioningState(FailedValue); - /// Resource creation was canceled. - public static ResourceProvisioningState Canceled { get; } = new ResourceProvisioningState(CanceledValue); - /// Determines if two values are the same. - public static bool operator ==(ResourceProvisioningState left, ResourceProvisioningState right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(ResourceProvisioningState left, ResourceProvisioningState right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator ResourceProvisioningState(string value) => new ResourceProvisioningState(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is ResourceProvisioningState other && Equals(other); - /// - public bool Equals(ResourceProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs index f1293271c03bf..dc2315ddd0c5e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs @@ -6,6 +6,7 @@ #nullable disable using System; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Azure.Core; @@ -24,7 +25,7 @@ internal partial class ExportTerraformRestOperations /// Initializes a new instance of ExportTerraformRestOperations. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The application id to use for user agent. - /// The to use. + /// Service host. /// The API version to use for this operation. /// or is null. public ExportTerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) @@ -35,7 +36,7 @@ public ExportTerraformRestOperations(HttpPipeline pipeline, string applicationId _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); } - internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId, BaseExportModel exportParameter) + internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId, BaseExportModel body) { var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); @@ -46,7 +47,7 @@ internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId return uri; } - internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExportModel exportParameter) + internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExportModel body) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -61,7 +62,7 @@ internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExp request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(exportParameter, ModelSerializationExtensions.WireOptions); + content.JsonWriter.WriteObjectValue(body, ModelSerializationExtensions.WireOptions); request.Content = content; _userAgent.Apply(message); return message; @@ -69,21 +70,26 @@ internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExp /// Exports the Terraform configuration of the specified resource(s). /// The ID of the target subscription. The value must be an UUID. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public async Task ExportTerraformAsync(string subscriptionId, BaseExportModel exportParameter, CancellationToken cancellationToken = default) + public async Task> ExportTerraformAsync(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - Argument.AssertNotNull(exportParameter, nameof(exportParameter)); + Argument.AssertNotNull(body, nameof(body)); - using var message = CreateExportTerraformRequest(subscriptionId, exportParameter); + using var message = CreateExportTerraformRequest(subscriptionId, body); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { - case 202: - return message.Response; + case 200: + { + ExportResult value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ExportResult.DeserializeExportResult(document.RootElement); + return Response.FromValue(value, message.Response); + } default: throw new RequestFailedException(message.Response); } @@ -91,97 +97,26 @@ public async Task ExportTerraformAsync(string subscriptionId, BaseExpo /// Exports the Terraform configuration of the specified resource(s). /// The ID of the target subscription. The value must be an UUID. - /// The export parameter. + /// The request body. /// The cancellation token to use. - /// or is null. + /// or is null. /// is an empty string, and was expected to be non-empty. - public Response ExportTerraform(string subscriptionId, BaseExportModel exportParameter, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - Argument.AssertNotNull(exportParameter, nameof(exportParameter)); - - using var message = CreateExportTerraformRequest(subscriptionId, exportParameter); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 202: - return message.Response; - default: - throw new RequestFailedException(message.Response); - } - } - - internal RequestUriBuilder CreateOperationStatusesRequestUri(string subscriptionId, string operationId) - { - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/subscriptions/", false); - uri.AppendPath(subscriptionId, true); - uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); - uri.AppendPath(operationId, true); - uri.AppendQuery("api-version", _apiVersion, true); - return uri; - } - - internal HttpMessage CreateOperationStatusesRequest(string subscriptionId, string operationId) - { - var message = _pipeline.CreateMessage(); - var request = message.Request; - request.Method = RequestMethod.Get; - var uri = new RawRequestUriBuilder(); - uri.Reset(_endpoint); - uri.AppendPath("/subscriptions/", false); - uri.AppendPath(subscriptionId, true); - uri.AppendPath("/providers/Microsoft.AzureTerraform/operationStatuses/", false); - uri.AppendPath(operationId, true); - uri.AppendQuery("api-version", _apiVersion, true); - request.Uri = uri; - request.Headers.Add("Accept", "application/json"); - _userAgent.Apply(message); - return message; - } - - /// Get the status of a long running azure asynchronous operation. - /// The ID of the target subscription. The value must be an UUID. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public async Task OperationStatusesAsync(string subscriptionId, string operationId, CancellationToken cancellationToken = default) - { - Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); - - using var message = CreateOperationStatusesRequest(subscriptionId, operationId); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 200: - case 202: - return message.Response; - default: - throw new RequestFailedException(message.Response); - } - } - - /// Get the status of a long running azure asynchronous operation. - /// The ID of the target subscription. The value must be an UUID. - /// The ID of an ongoing async operation. - /// The cancellation token to use. - /// or is null. - /// or is an empty string, and was expected to be non-empty. - public Response OperationStatuses(string subscriptionId, string operationId, CancellationToken cancellationToken = default) + public Response ExportTerraform(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); - Argument.AssertNotNullOrEmpty(operationId, nameof(operationId)); + Argument.AssertNotNull(body, nameof(body)); - using var message = CreateOperationStatusesRequest(subscriptionId, operationId); + using var message = CreateExportTerraformRequest(subscriptionId, body); _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { case 200: - case 202: - return message.Response; + { + ExportResult value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ExportResult.DeserializeExportResult(document.RootElement); + return Response.FromValue(value, message.Response); + } default: throw new RequestFailedException(message.Response); } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index 4895ef8ab25e2..6bf99c4b58288 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -36,23 +36,11 @@ public async Task TearDown() public async Task ExportTerraformTest() { string rgName = _resourceGroup.Data.Name; - ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); - string hcl = operationStatus.Value.Properties.Configuration; + Response response = await DefaultSubscription.ExportTerraformAsync(new ExportResourceGroup(rgName)); + string hcl = response.Value.Configuration; Assert.That(hcl, Does.Contain("azurerm_resource_group")); Assert.That(hcl, Does.Contain(rgName)); } - - [TestCase] - [RecordedTest] - public async Task OperationStatusesTest() - { - string rgName = _resourceGroup.Data.Name; - ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Started, new ExportResourceGroup(rgName)); - - ArmOperation armOperation = await DefaultSubscription.OperationStatusesAsync(WaitUntil.Completed, operationStatus.Id); - - Assert.That(armOperation.HasCompleted, Is.True); - } } } From 5f7140c7bff8142f19d235c6dd4440b4508c9554 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 18 Oct 2024 14:03:20 +1100 Subject: [PATCH 20/33] Fixed exception thrown when calling POST /exportTerraform --- .../Sample_SubscriptionResourceExtensions.cs | 3 +- .../src/Generated/ArmTerraformModelFactory.cs | 22 ++ .../MockableTerraformSubscriptionResource.cs | 16 +- .../Extensions/TerraformExtensions.cs | 14 +- .../TerraformArmOperationOfT.cs | 100 ++++++++ ...TerraformOperationStatusOperationSource.cs | 30 +++ .../Models/ResourceProvisioningState.cs | 54 +++++ .../TerraformOperationStatus.Serialization.cs | 220 ++++++++++++++++++ .../Models/TerraformOperationStatus.cs | 96 ++++++++ .../ExportTerraformRestOperations.cs | 23 +- .../tests/Tests/ExportTerraformTests.cs | 4 +- 11 files changed, 552 insertions(+), 30 deletions(-) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformOperationStatusOperationSource.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index 86df234cff60e..0909a5b18fa0f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -37,7 +37,8 @@ public async Task ExportTerraform_ExportTerraform() // invoke the operation BaseExportModel body = new ExportResourceGroup("rg1"); - ExportResult result = await subscriptionResource.ExportTerraformAsync(body); + ArmOperation lro = await subscriptionResource.ExportTerraformAsync(WaitUntil.Completed, body); + TerraformOperationStatus result = lro.Value; Console.WriteLine($"Succeeded: {result}"); } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 4fecfe9e759d9..7714311dc4386 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -54,6 +54,28 @@ public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProv namePattern); } + /// Initializes a new instance of . + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + /// The operation status. + /// The name of the operationStatus resource. + /// Operation start time. + /// Operation complete time. + /// The progress made toward completing the operation. + /// Errors that occurred if the operation ended with Canceled or Failed status. + /// A new instance for mocking. + public static TerraformOperationStatus TerraformOperationStatus(ExportResult properties = null, ResourceProvisioningState status = default, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, double? percentComplete = null, ResponseError error = null) + { + return new TerraformOperationStatus( + properties, + status, + name, + startOn, + endOn, + percentComplete, + error, + serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// The Terraform configuration content. /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index da327c653b8f1..f9596db077d91 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -58,10 +58,11 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// /// /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. /// The request body. /// The cancellation token to use. /// is null. - public virtual async Task> ExportTerraformAsync(BaseExportModel body, CancellationToken cancellationToken = default) + public virtual async Task> ExportTerraformAsync(WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(body, nameof(body)); @@ -70,7 +71,10 @@ public virtual async Task> ExportTerraformAsync(BaseExpor try { var response = await ExportTerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, body, cancellationToken).ConfigureAwait(false); - return response; + var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); + return operation; } catch (Exception e) { @@ -96,10 +100,11 @@ public virtual async Task> ExportTerraformAsync(BaseExpor /// /// /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. /// The request body. /// The cancellation token to use. /// is null. - public virtual Response ExportTerraform(BaseExportModel body, CancellationToken cancellationToken = default) + public virtual ArmOperation ExportTerraform(WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(body, nameof(body)); @@ -108,7 +113,10 @@ public virtual Response ExportTerraform(BaseExportModel body, Canc try { var response = ExportTerraformRestClient.ExportTerraform(Id.SubscriptionId, body, cancellationToken); - return response; + var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletion(cancellationToken); + return operation; } catch (Exception e) { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index 1f350c4898f08..39afa40b9f118 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -40,18 +40,19 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. /// The request body. /// The cancellation token to use. /// or is null. - public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, BaseExportModel body, CancellationToken cancellationToken = default) + public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAsync(body, cancellationToken).ConfigureAwait(false); + return await GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraformAsync(waitUntil, body, cancellationToken).ConfigureAwait(false); } /// @@ -72,18 +73,19 @@ public static async Task> ExportTerraformAsync(this Subsc /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. /// The request body. /// The cancellation token to use. /// or is null. - public static Response ExportTerraform(this SubscriptionResource subscriptionResource, BaseExportModel body, CancellationToken cancellationToken = default) + public static ArmOperation ExportTerraform(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); - return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraform(body, cancellationToken); + return GetMockableTerraformSubscriptionResource(subscriptionResource).ExportTerraform(waitUntil, body, cancellationToken); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs new file mode 100644 index 0000000000000..23e4d4dba878c --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformArmOperationOfT.cs @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Terraform +{ +#pragma warning disable SA1649 // File name should match first type name + internal class TerraformArmOperation : ArmOperation +#pragma warning restore SA1649 // File name should match first type name + { + private readonly OperationInternal _operation; + private readonly RehydrationToken? _completeRehydrationToken; + private readonly NextLinkOperationImplementation _nextLinkOperation; + private readonly string _operationId; + + /// Initializes a new instance of TerraformArmOperation for mocking. + protected TerraformArmOperation() + { + } + + internal TerraformArmOperation(Response response, RehydrationToken? rehydrationToken = null) + { + _operation = OperationInternal.Succeeded(response.GetRawResponse(), response.Value); + _completeRehydrationToken = rehydrationToken; + _operationId = GetOperationId(rehydrationToken); + } + + internal TerraformArmOperation(IOperationSource source, ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response, OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null) + { + var nextLinkOperation = NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue); + if (nextLinkOperation is NextLinkOperationImplementation nextLinkOperationValue) + { + _nextLinkOperation = nextLinkOperationValue; + _operationId = _nextLinkOperation.OperationId; + } + else + { + _completeRehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia); + _operationId = GetOperationId(_completeRehydrationToken); + } + _operation = new OperationInternal(NextLinkOperationImplementation.Create(source, nextLinkOperation), clientDiagnostics, response, "TerraformArmOperation", fallbackStrategy: new SequentialDelayStrategy()); + } + + private string GetOperationId(RehydrationToken? rehydrationToken) + { + if (rehydrationToken is null) + { + return null; + } + var lroDetails = ModelReaderWriter.Write(rehydrationToken, ModelReaderWriterOptions.Json).ToObjectFromJson>(); + return lroDetails["id"]; + } + /// + public override string Id => _operationId ?? NextLinkOperationImplementation.NotSet; + + /// + public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken; + + /// + public override T Value => _operation.Value; + + /// + public override bool HasValue => _operation.HasValue; + + /// + public override bool HasCompleted => _operation.HasCompleted; + + /// + public override Response GetRawResponse() => _operation.RawResponse; + + /// + public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); + + /// + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); + + /// + public override Response WaitForCompletion(CancellationToken cancellationToken = default) => _operation.WaitForCompletion(cancellationToken); + + /// + public override Response WaitForCompletion(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletion(pollingInterval, cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken); + + /// + public override ValueTask> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken); + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformOperationStatusOperationSource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformOperationStatusOperationSource.cs new file mode 100644 index 0000000000000..47006d98958e1 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/LongRunningOperation/TerraformOperationStatusOperationSource.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.ResourceManager.Terraform.Models; + +namespace Azure.ResourceManager.Terraform +{ + internal class TerraformOperationStatusOperationSource : IOperationSource + { + TerraformOperationStatus IOperationSource.CreateResult(Response response, CancellationToken cancellationToken) + { + using var document = JsonDocument.Parse(response.ContentStream); + return TerraformOperationStatus.DeserializeTerraformOperationStatus(document.RootElement); + } + + async ValueTask IOperationSource.CreateResultAsync(Response response, CancellationToken cancellationToken) + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + return TerraformOperationStatus.DeserializeTerraformOperationStatus(document.RootElement); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs new file mode 100644 index 0000000000000..5a69a96b13bad --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The provisioning state of a resource type. + public readonly partial struct ResourceProvisioningState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public ResourceProvisioningState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SucceededValue = "Succeeded"; + private const string FailedValue = "Failed"; + private const string CanceledValue = "Canceled"; + + /// Resource has been created. + public static ResourceProvisioningState Succeeded { get; } = new ResourceProvisioningState(SucceededValue); + /// Resource creation failed. + public static ResourceProvisioningState Failed { get; } = new ResourceProvisioningState(FailedValue); + /// Resource creation was canceled. + public static ResourceProvisioningState Canceled { get; } = new ResourceProvisioningState(CanceledValue); + /// Determines if two values are the same. + public static bool operator ==(ResourceProvisioningState left, ResourceProvisioningState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(ResourceProvisioningState left, ResourceProvisioningState right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator ResourceProvisioningState(string value) => new ResourceProvisioningState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ResourceProvisioningState other && Equals(other); + /// + public bool Equals(ResourceProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs new file mode 100644 index 0000000000000..12a756dae0ce2 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs @@ -0,0 +1,220 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Terraform.Models +{ + public partial class TerraformOperationStatus : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TerraformOperationStatus)} does not support writing '{format}' format."); + } + + if (options.Format != "W" && Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + if (options.Format != "W" && Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (options.Format != "W" && Optional.IsDefined(StartOn)) + { + writer.WritePropertyName("startTime"u8); + writer.WriteStringValue(StartOn.Value, "O"); + } + if (options.Format != "W" && Optional.IsDefined(EndOn)) + { + writer.WritePropertyName("endTime"u8); + writer.WriteStringValue(EndOn.Value, "O"); + } + if (options.Format != "W" && Optional.IsDefined(PercentComplete)) + { + writer.WritePropertyName("percentComplete"u8); + writer.WriteNumberValue(PercentComplete.Value); + } + if (options.Format != "W" && Optional.IsDefined(Error)) + { + writer.WritePropertyName("error"u8); + JsonSerializer.Serialize(writer, Error); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + TerraformOperationStatus IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TerraformOperationStatus)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTerraformOperationStatus(document.RootElement, options); + } + + internal static TerraformOperationStatus DeserializeTerraformOperationStatus(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ExportResult properties = default; + ResourceProvisioningState status = default; + string name = default; + DateTimeOffset? startTime = default; + DateTimeOffset? endTime = default; + double? percentComplete = default; + ResponseError error = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = ExportResult.DeserializeExportResult(property.Value, options); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new ResourceProvisioningState(property.Value.GetString()); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("startTime"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("endTime"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + endTime = property.Value.GetDateTimeOffset("O"); + continue; + } + if (property.NameEquals("percentComplete"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + percentComplete = property.Value.GetDouble(); + continue; + } + if (property.NameEquals("error"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + error = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new TerraformOperationStatus( + properties, + status, + name, + startTime, + endTime, + percentComplete, + error, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(TerraformOperationStatus)} does not support writing '{options.Format}' format."); + } + } + + TerraformOperationStatus IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeTerraformOperationStatus(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TerraformOperationStatus)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs new file mode 100644 index 0000000000000..4a88942e2e30e --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The status of the LRO operation. + public partial class TerraformOperationStatus + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The operation status. + internal TerraformOperationStatus(ResourceProvisioningState status) + { + Status = status; + } + + /// Initializes a new instance of . + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + /// The operation status. + /// The name of the operationStatus resource. + /// Operation start time. + /// Operation complete time. + /// The progress made toward completing the operation. + /// Errors that occurred if the operation ended with Canceled or Failed status. + /// Keeps track of any properties unknown to the library. + internal TerraformOperationStatus(ExportResult properties, ResourceProvisioningState status, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, double? percentComplete, ResponseError error, IDictionary serializedAdditionalRawData) + { + Properties = properties; + Status = status; + Name = name; + StartOn = startOn; + EndOn = endOn; + PercentComplete = percentComplete; + Error = error; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal TerraformOperationStatus() + { + } + + /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. + public ExportResult Properties { get; } + /// The operation status. + public ResourceProvisioningState Status { get; } + /// The name of the operationStatus resource. + public string Name { get; } + /// Operation start time. + public DateTimeOffset? StartOn { get; } + /// Operation complete time. + public DateTimeOffset? EndOn { get; } + /// The progress made toward completing the operation. + public double? PercentComplete { get; } + /// Errors that occurred if the operation ended with Canceled or Failed status. + public ResponseError Error { get; } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs index dc2315ddd0c5e..e38bacd64e67f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs @@ -6,7 +6,6 @@ #nullable disable using System; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Azure.Core; @@ -74,7 +73,7 @@ internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExp /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public async Task> ExportTerraformAsync(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) + public async Task ExportTerraformAsync(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(body, nameof(body)); @@ -83,13 +82,8 @@ public async Task> ExportTerraformAsync(string subscripti await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { - case 200: - { - ExportResult value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = ExportResult.DeserializeExportResult(document.RootElement); - return Response.FromValue(value, message.Response); - } + case 202: + return message.Response; default: throw new RequestFailedException(message.Response); } @@ -101,7 +95,7 @@ public async Task> ExportTerraformAsync(string subscripti /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public Response ExportTerraform(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) + public Response ExportTerraform(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(body, nameof(body)); @@ -110,13 +104,8 @@ public Response ExportTerraform(string subscriptionId, BaseExportM _pipeline.Send(message, cancellationToken); switch (message.Response.Status) { - case 200: - { - ExportResult value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = ExportResult.DeserializeExportResult(document.RootElement); - return Response.FromValue(value, message.Response); - } + case 202: + return message.Response; default: throw new RequestFailedException(message.Response); } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index 6bf99c4b58288..48e30b0fb79a2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -36,8 +36,8 @@ public async Task TearDown() public async Task ExportTerraformTest() { string rgName = _resourceGroup.Data.Name; - Response response = await DefaultSubscription.ExportTerraformAsync(new ExportResourceGroup(rgName)); - string hcl = response.Value.Configuration; + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); + string hcl = operationStatus.Value.Properties.Configuration; Assert.That(hcl, Does.Contain("azurerm_resource_group")); Assert.That(hcl, Does.Contain(rgName)); From e0ee04d811527a9dc5273cdba1c2a72ff9d9090f Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 18 Oct 2024 15:37:03 +1100 Subject: [PATCH 21/33] Regen SDK after changing operationId name --- .../Sample_SubscriptionResourceExtensions.cs | 2 +- .../MockableTerraformSubscriptionResource.cs | 24 +++++++++---------- .../Extensions/TerraformExtensions.cs | 4 ++-- ...erations.cs => TerraformRestOperations.cs} | 6 ++--- 4 files changed, 18 insertions(+), 18 deletions(-) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/{ExportTerraformRestOperations.cs => TerraformRestOperations.cs} (95%) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index 0909a5b18fa0f..6fb15ec111fe8 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -22,7 +22,7 @@ public partial class Sample_SubscriptionResourceExtensions public async Task ExportTerraform_ExportTerraform() { // Generated from example definition: 2023-07-01-preview/ExportTerraform.json - // this example is just showing the usage of "ExportTerraform_ExportTerraform" operation, for the dependent resources, they will have to be created separately. + // this example is just showing the usage of "Terraform_ExportTerraform" 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(); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index f9596db077d91..4eb7c57a0d9b2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -17,8 +17,8 @@ namespace Azure.ResourceManager.Terraform.Mocking /// A class to add extension methods to SubscriptionResource. public partial class MockableTerraformSubscriptionResource : ArmResource { - private ClientDiagnostics _exportTerraformClientDiagnostics; - private ExportTerraformRestOperations _exportTerraformRestClient; + private ClientDiagnostics _terraformClientDiagnostics; + private TerraformRestOperations _terraformRestClient; /// Initializes a new instance of the class for mocking. protected MockableTerraformSubscriptionResource() @@ -32,8 +32,8 @@ internal MockableTerraformSubscriptionResource(ArmClient client, ResourceIdentif { } - private ClientDiagnostics ExportTerraformClientDiagnostics => _exportTerraformClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); - private ExportTerraformRestOperations ExportTerraformRestClient => _exportTerraformRestClient ??= new ExportTerraformRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); + private ClientDiagnostics TerraformClientDiagnostics => _terraformClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Terraform", ProviderConstants.DefaultProviderNamespace, Diagnostics); + private TerraformRestOperations TerraformRestClient => _terraformRestClient ??= new TerraformRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); private string GetApiVersionOrNull(ResourceType resourceType) { @@ -50,7 +50,7 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// /// /// Operation Id - /// ExportTerraform_ExportTerraform + /// Terraform_ExportTerraform /// /// /// Default Api Version @@ -66,12 +66,12 @@ public virtual async Task> ExportTerrafor { Argument.AssertNotNull(body, nameof(body)); - using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); + using var scope = TerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = await ExportTerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, body, cancellationToken).ConfigureAwait(false); - var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); + var response = await TerraformRestClient.ExportTerraformAsync(Id.SubscriptionId, body, cancellationToken).ConfigureAwait(false); + var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), TerraformClientDiagnostics, Pipeline, TerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitUntil == WaitUntil.Completed) await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); return operation; @@ -92,7 +92,7 @@ public virtual async Task> ExportTerrafor /// /// /// Operation Id - /// ExportTerraform_ExportTerraform + /// Terraform_ExportTerraform /// /// /// Default Api Version @@ -108,12 +108,12 @@ public virtual ArmOperation ExportTerraform(WaitUntil { Argument.AssertNotNull(body, nameof(body)); - using var scope = ExportTerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); + using var scope = TerraformClientDiagnostics.CreateScope("MockableTerraformSubscriptionResource.ExportTerraform"); scope.Start(); try { - var response = ExportTerraformRestClient.ExportTerraform(Id.SubscriptionId, body, cancellationToken); - var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), ExportTerraformClientDiagnostics, Pipeline, ExportTerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); + var response = TerraformRestClient.ExportTerraform(Id.SubscriptionId, body, cancellationToken); + var operation = new TerraformArmOperation(new TerraformOperationStatusOperationSource(), TerraformClientDiagnostics, Pipeline, TerraformRestClient.CreateExportTerraformRequest(Id.SubscriptionId, body).Request, response, OperationFinalStateVia.AzureAsyncOperation); if (waitUntil == WaitUntil.Completed) operation.WaitForCompletion(cancellationToken); return operation; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index 39afa40b9f118..c1dc7136fef33 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -31,7 +31,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Operation Id - /// ExportTerraform_ExportTerraform + /// Terraform_ExportTerraform /// /// /// Default Api Version @@ -64,7 +64,7 @@ public static async Task> ExportTerraform /// /// /// Operation Id - /// ExportTerraform_ExportTerraform + /// Terraform_ExportTerraform /// /// /// Default Api Version diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs similarity index 95% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs index e38bacd64e67f..ab0c5a219b28d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/ExportTerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs @@ -14,20 +14,20 @@ namespace Azure.ResourceManager.Terraform { - internal partial class ExportTerraformRestOperations + internal partial class TerraformRestOperations { private readonly TelemetryDetails _userAgent; private readonly HttpPipeline _pipeline; private readonly Uri _endpoint; private readonly string _apiVersion; - /// Initializes a new instance of ExportTerraformRestOperations. + /// Initializes a new instance of TerraformRestOperations. /// The HTTP pipeline for sending and receiving REST requests and responses. /// The application id to use for user agent. /// Service host. /// The API version to use for this operation. /// or is null. - public ExportTerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) + public TerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) { _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); _endpoint = endpoint ?? new Uri("https://management.azure.com"); From f86ae1e58ee138842b0b555d755ad03add935035 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 18 Oct 2024 15:47:25 +1100 Subject: [PATCH 22/33] Removed [TestFixture] annotation, dual sync/async mode for test --- .../tests/Tests/ExportTerraformTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index 48e30b0fb79a2..d4d57e46ec8df 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -10,12 +10,11 @@ namespace Azure.ResourceManager.Terraform.Tests.Tests { - [TestFixture] public class ExportTerraformTests : TerraformManagementTestBase { private ResourceGroupResource _resourceGroup; - public ExportTerraformTests() : base(true) + public ExportTerraformTests(bool isAsync) : base(isAsync) { } From 00549315b60ab0a3b16b0ea2d2c6788525c18f0e Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 18 Oct 2024 15:50:08 +1100 Subject: [PATCH 23/33] Removed dup namespace segment --- .../tests/Tests/ExportTerraformTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs index d4d57e46ec8df..19b66373098c5 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs @@ -8,7 +8,7 @@ using Azure.ResourceManager.Terraform.Models; using NUnit.Framework; -namespace Azure.ResourceManager.Terraform.Tests.Tests +namespace Azure.ResourceManager.Terraform.Tests { public class ExportTerraformTests : TerraformManagementTestBase { From 7dc5b3ed6957b7eed4d63a0b8334a75d0f576ef6 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Mon, 21 Oct 2024 15:46:17 +1100 Subject: [PATCH 24/33] Updated tsp-location.yml with commit hash after specs merged, updated api file --- ...esourceManager.Terraform.netstandard2.0.cs | 48 +++++++++---------- .../tsp-location.yaml | 2 +- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index b76203893ff60..a0eb54b13f0e2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -2,10 +2,8 @@ namespace Azure.ResourceManager.Terraform { public static partial class TerraformExtensions { - public static Azure.ResourceManager.ArmOperation ExportTerraform(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task> ExportTerraformAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static Azure.ResourceManager.ArmOperation OperationStatuses(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task OperationStatusesAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation ExportTerraform(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> ExportTerraformAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Mocking @@ -13,10 +11,8 @@ namespace Azure.ResourceManager.Terraform.Mocking public partial class MockableTerraformSubscriptionResource : Azure.ResourceManager.ArmResource { protected MockableTerraformSubscriptionResource() { } - public virtual Azure.ResourceManager.ArmOperation ExportTerraform(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExportTerraformAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel exportParameter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.ResourceManager.ArmOperation OperationStatuses(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task OperationStatusesAsync(Azure.WaitUntil waitUntil, string operationId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation ExportTerraform(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExportTerraformAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Models @@ -26,7 +22,7 @@ public static partial class ArmTerraformModelFactory public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.ExportResult ExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResources = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } - public static Azure.ResourceManager.Terraform.Models.OperationStatus OperationStatus(Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } public abstract partial class BaseExportModel : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { @@ -93,23 +89,6 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class OperationStatus : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel - { - internal OperationStatus() { } - public System.DateTimeOffset? EndOn { get { throw null; } } - public Azure.ResponseError Error { get { throw null; } } - public string Name { get { throw null; } } - public double? PercentComplete { get { throw null; } } - public Azure.ResourceManager.Terraform.Models.ExportResult Properties { get { throw null; } } - public System.DateTimeOffset? StartOn { get { throw null; } } - public Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Status { get { throw null; } } - protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.OperationStatus System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct ResourceProvisioningState : System.IEquatable { @@ -147,4 +126,21 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer public static bool operator !=(Azure.ResourceManager.Terraform.Models.TargetProvider left, Azure.ResourceManager.Terraform.Models.TargetProvider right) { throw null; } public override string ToString() { throw null; } } + public partial class TerraformOperationStatus : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal TerraformOperationStatus() { } + public System.DateTimeOffset? EndOn { get { throw null; } } + public Azure.ResponseError Error { get { throw null; } } + public string Name { get { throw null; } } + public double? PercentComplete { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.ExportResult Properties { get { throw null; } } + public System.DateTimeOffset? StartOn { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Status { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.TerraformOperationStatus System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.TerraformOperationStatus System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 644b2fec57c5e..54a1b15e31196 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: to-be-updated-once-spec-changes-merged +commit: 637adebd6042eab6c721be8eda4ff3f5d4d0c2b8 repo: Azure/azure-rest-api-specs From 79af11be57f7a97c4a0b7e1b5b751819642c691c Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Tue, 22 Oct 2024 10:55:28 +1100 Subject: [PATCH 25/33] Push test recording --- sdk/terraform/Azure.ResourceManager.Terraform/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 1e8c0b20696bd..0b8bf3ebadfe7 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "" + "Tag": "net/terraform/Azure.ResourceManager.Terraform_b3fd607c88" } From 95b88cde42361393f6a7ac6daf14737ff2e68bc3 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Wed, 23 Oct 2024 16:03:09 +1100 Subject: [PATCH 26/33] Test env setup + added test for all 3 export types --- ...esourceManager.Terraform.netstandard2.0.cs | 32 ++++----- .../assets.json | 8 +-- .../Sample_SubscriptionResourceExtensions.cs | 2 +- .../MockableTerraformSubscriptionResource.cs | 4 +- .../Extensions/TerraformExtensions.cs | 8 +-- ...> CommonExportProperties.Serialization.cs} | 40 +++++------ ...portModel.cs => CommonExportProperties.cs} | 12 ++-- .../src/Generated/Models/ExportQuery.cs | 2 +- .../Models/ExportResource.Serialization.cs | 18 ++++- .../src/Generated/Models/ExportResource.cs | 9 +-- .../Generated/Models/ExportResourceGroup.cs | 2 +- ...wnCommonExportProperties.Serialization.cs} | 38 +++++------ ...el.cs => UnknownCommonExportProperties.cs} | 12 ++-- .../RestOperations/TerraformRestOperations.cs | 8 +-- .../tests/ExportTerraformTests.cs | 67 +++++++++++++++++++ .../TerraformManagementTestEnvironment.cs | 6 ++ .../tests/Tests/ExportTerraformTests.cs | 45 ------------- sdk/terraform/test-resources.json | 47 +++++++++++++ 18 files changed, 224 insertions(+), 136 deletions(-) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{BaseExportModel.Serialization.cs => CommonExportProperties.Serialization.cs} (64%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{BaseExportModel.cs => CommonExportProperties.cs} (81%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{UnknownBaseExportModel.Serialization.cs => UnknownCommonExportProperties.Serialization.cs} (66%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{UnknownBaseExportModel.cs => UnknownCommonExportProperties.cs} (63%) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs create mode 100644 sdk/terraform/test-resources.json diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index a0eb54b13f0e2..a174bb53c4b5f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -2,8 +2,8 @@ namespace Azure.ResourceManager.Terraform { public static partial class TerraformExtensions { - public static Azure.ResourceManager.ArmOperation ExportTerraform(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public static System.Threading.Tasks.Task> ExportTerraformAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static Azure.ResourceManager.ArmOperation ExportTerraform(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.CommonExportProperties body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> ExportTerraformAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.CommonExportProperties body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Mocking @@ -11,8 +11,8 @@ namespace Azure.ResourceManager.Terraform.Mocking public partial class MockableTerraformSubscriptionResource : Azure.ResourceManager.ArmResource { protected MockableTerraformSubscriptionResource() { } - public virtual Azure.ResourceManager.ArmOperation ExportTerraform(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExportTerraformAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.BaseExportModel body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation ExportTerraform(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.CommonExportProperties body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExportTerraformAsync(Azure.WaitUntil waitUntil, Azure.ResourceManager.Terraform.Models.CommonExportProperties body, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } } namespace Azure.ResourceManager.Terraform.Models @@ -24,20 +24,20 @@ public static partial class ArmTerraformModelFactory public static Azure.ResourceManager.Terraform.Models.ExportResult ExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResources = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } - public abstract partial class BaseExportModel : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public abstract partial class CommonExportProperties : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - protected BaseExportModel() { } + protected CommonExportProperties() { } public bool? FullProperties { get { throw null; } set { } } public bool? MaskSensitive { get { throw null; } set { } } public Azure.ResourceManager.Terraform.Models.TargetProvider? TargetProvider { get { throw null; } set { } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.BaseExportModel System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + Azure.ResourceManager.Terraform.Models.CommonExportProperties System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.CommonExportProperties System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportQuery : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public partial class ExportQuery : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ExportQuery(string query) { } public string NamePattern { get { throw null; } set { } } @@ -50,11 +50,11 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportResource : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public partial class ExportResource : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - public ExportResource(System.Collections.Generic.IEnumerable resourceIds) { } + public ExportResource(System.Collections.Generic.IEnumerable resourceIds) { } public string NamePattern { get { throw null; } set { } } - public System.Collections.Generic.IList ResourceIds { get { throw null; } } + public System.Collections.Generic.IList ResourceIds { get { throw null; } } public string ResourceName { get { throw null; } set { } } public string ResourceType { get { throw null; } set { } } protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } @@ -64,7 +64,7 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Models.BaseExportModel, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ExportResourceGroup(string resourceGroupName) { } public string NamePattern { get { throw null; } set { } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 0b8bf3ebadfe7..291ef5cc33ece 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -1,6 +1,6 @@ { - "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "net", - "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "net/terraform/Azure.ResourceManager.Terraform_b3fd607c88" + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", + "Tag": "net/terraform/Azure.ResourceManager.Terraform_1db6dacdb1" } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index 6fb15ec111fe8..c75110c9e5d88 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -36,7 +36,7 @@ public async Task ExportTerraform_ExportTerraform() SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); // invoke the operation - BaseExportModel body = new ExportResourceGroup("rg1"); + CommonExportProperties body = new ExportResourceGroup("rg1"); ArmOperation lro = await subscriptionResource.ExportTerraformAsync(WaitUntil.Completed, body); TerraformOperationStatus result = lro.Value; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs index 4eb7c57a0d9b2..a49365c8727db 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/MockableTerraformSubscriptionResource.cs @@ -62,7 +62,7 @@ private string GetApiVersionOrNull(ResourceType resourceType) /// The request body. /// The cancellation token to use. /// is null. - public virtual async Task> ExportTerraformAsync(WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) + public virtual async Task> ExportTerraformAsync(WaitUntil waitUntil, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(body, nameof(body)); @@ -104,7 +104,7 @@ public virtual async Task> ExportTerrafor /// The request body. /// The cancellation token to use. /// is null. - public virtual ArmOperation ExportTerraform(WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) + public virtual ArmOperation ExportTerraform(WaitUntil waitUntil, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(body, nameof(body)); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs index c1dc7136fef33..07abb8eda0f3b 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Extensions/TerraformExtensions.cs @@ -40,7 +40,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -48,7 +48,7 @@ private static MockableTerraformSubscriptionResource GetMockableTerraformSubscri /// The request body. /// The cancellation token to use. /// or is null. - public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) + public static async Task> ExportTerraformAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); @@ -73,7 +73,7 @@ public static async Task> ExportTerraform /// /// /// Mocking - /// To mock this method, please mock instead. + /// To mock this method, please mock instead. /// /// /// The instance the method will execute against. @@ -81,7 +81,7 @@ public static async Task> ExportTerraform /// The request body. /// The cancellation token to use. /// or is null. - public static ArmOperation ExportTerraform(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, BaseExportModel body, CancellationToken cancellationToken = default) + public static ArmOperation ExportTerraform(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs similarity index 64% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs index 4c89f19dd15b0..dab8d34f771ac 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs @@ -12,12 +12,12 @@ namespace Azure.ResourceManager.Terraform.Models { - [PersistableModelProxy(typeof(UnknownBaseExportModel))] - public partial class BaseExportModel : IUtf8JsonSerializable, IJsonModel + [PersistableModelProxy(typeof(UnknownCommonExportProperties))] + public partial class CommonExportProperties : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support writing '{format}' format."); } writer.WritePropertyName("type"u8); @@ -68,19 +68,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + CommonExportProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeBaseExportModel(document.RootElement, options); + return DeserializeCommonExportProperties(document.RootElement, options); } - internal static BaseExportModel DeserializeBaseExportModel(JsonElement element, ModelReaderWriterOptions options = null) + internal static CommonExportProperties DeserializeCommonExportProperties(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -97,38 +97,38 @@ internal static BaseExportModel DeserializeBaseExportModel(JsonElement element, case "ExportResourceGroup": return ExportResourceGroup.DeserializeExportResourceGroup(element, options); } } - return UnknownBaseExportModel.DeserializeUnknownBaseExportModel(element, options); + return UnknownCommonExportProperties.DeserializeUnknownCommonExportProperties(element, options); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support writing '{options.Format}' format."); } } - BaseExportModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + CommonExportProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeBaseExportModel(document.RootElement, options); + return DeserializeCommonExportProperties(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs similarity index 81% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs index a14d8c7b4642e..d653819fd69c2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/BaseExportModel.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs @@ -12,10 +12,10 @@ namespace Azure.ResourceManager.Terraform.Models { /// /// The base export parameter - /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. + /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. /// The available derived classes include , and . /// - public abstract partial class BaseExportModel + public abstract partial class CommonExportProperties { /// /// Keeps track of any properties unknown to the library. @@ -49,18 +49,18 @@ public abstract partial class BaseExportModel /// private protected IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - protected BaseExportModel() + /// Initializes a new instance of . + protected CommonExportProperties() { } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal BaseExportModel(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) + internal CommonExportProperties(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) { Type = type; TargetProvider = targetProvider; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs index e0992c67697b6..c5ae0b36d6176 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs @@ -11,7 +11,7 @@ namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for resources queried by ARG (Azure Resource Graph). - public partial class ExportQuery : BaseExportModel + public partial class ExportQuery : CommonExportProperties { /// Initializes a new instance of . /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs index 25934be472b09..f018ff6c59117 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs @@ -39,6 +39,11 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri writer.WriteStartArray(); foreach (var item in ResourceIds) { + if (item == null) + { + writer.WriteNullValue(); + continue; + } writer.WriteStringValue(item); } writer.WriteEndArray(); @@ -79,7 +84,7 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo { return null; } - IList resourceIds = default; + IList resourceIds = default; string resourceName = default; string resourceType = default; string namePattern = default; @@ -93,10 +98,17 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo { if (property.NameEquals("resourceIds"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(item.GetString()); + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(new ResourceIdentifier(item.GetString())); + } } resourceIds = array; continue; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs index 56425d884a0e6..a7f0697dba2e8 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs @@ -8,16 +8,17 @@ using System; using System.Collections.Generic; using System.Linq; +using Azure.Core; namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for individual resources. - public partial class ExportResource : BaseExportModel + public partial class ExportResource : CommonExportProperties { /// Initializes a new instance of . /// The id of the resource to be exported. /// is null. - public ExportResource(IEnumerable resourceIds) + public ExportResource(IEnumerable resourceIds) { Argument.AssertNotNull(resourceIds, nameof(resourceIds)); @@ -35,7 +36,7 @@ public ExportResource(IEnumerable resourceIds) /// The Terraform resource name. Only works when `resourceIds` contains only one item. /// The Terraform resource type. Only works when `resourceIds` contains only one item. /// The name pattern of the Terraform resources. - internal ExportResource(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResource(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { ResourceIds = resourceIds; ResourceName = resourceName; @@ -50,7 +51,7 @@ internal ExportResource() } /// The id of the resource to be exported. - public IList ResourceIds { get; } + public IList ResourceIds { get; } /// The Terraform resource name. Only works when `resourceIds` contains only one item. public string ResourceName { get; set; } /// The Terraform resource type. Only works when `resourceIds` contains only one item. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs index 3ea06af1982f0..2a0d46aea5d35 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs @@ -11,7 +11,7 @@ namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for a resource group. - public partial class ExportResourceGroup : BaseExportModel + public partial class ExportResourceGroup : CommonExportProperties { /// Initializes a new instance of . /// The name of the resource group to be exported. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs similarity index 66% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs index ecc6dae201b1e..52693880f4bbf 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.ResourceManager.Terraform.Models { - internal partial class UnknownBaseExportModel : IUtf8JsonSerializable, IJsonModel + internal partial class UnknownCommonExportProperties : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,28 +28,28 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterO /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); } - BaseExportModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + CommonExportProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeBaseExportModel(document.RootElement, options); + return DeserializeCommonExportProperties(document.RootElement, options); } - internal static UnknownBaseExportModel DeserializeUnknownBaseExportModel(JsonElement element, ModelReaderWriterOptions options = null) + internal static UnknownCommonExportProperties DeserializeUnknownCommonExportProperties(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -103,38 +103,38 @@ internal static UnknownBaseExportModel DeserializeUnknownBaseExportModel(JsonEle } } serializedAdditionalRawData = rawDataDictionary; - return new UnknownBaseExportModel(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData); + return new UnknownCommonExportProperties(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(BaseExportModel)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support writing '{options.Format}' format."); } } - BaseExportModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + CommonExportProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeBaseExportModel(document.RootElement, options); + return DeserializeCommonExportProperties(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(BaseExportModel)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(CommonExportProperties)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs similarity index 63% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs index 54de7bdc89205..ac17049b65b99 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownBaseExportModel.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs @@ -10,22 +10,22 @@ namespace Azure.ResourceManager.Terraform.Models { - /// Unknown version of BaseExportModel. - internal partial class UnknownBaseExportModel : BaseExportModel + /// Unknown version of CommonExportProperties. + internal partial class UnknownCommonExportProperties : CommonExportProperties { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal UnknownBaseExportModel(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal UnknownCommonExportProperties(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { Type = type; } - /// Initializes a new instance of for deserialization. - internal UnknownBaseExportModel() + /// Initializes a new instance of for deserialization. + internal UnknownCommonExportProperties() { } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs index ab0c5a219b28d..de54bfe428895 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/RestOperations/TerraformRestOperations.cs @@ -35,7 +35,7 @@ public TerraformRestOperations(HttpPipeline pipeline, string applicationId, Uri _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); } - internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId, BaseExportModel body) + internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId, CommonExportProperties body) { var uri = new RawRequestUriBuilder(); uri.Reset(_endpoint); @@ -46,7 +46,7 @@ internal RequestUriBuilder CreateExportTerraformRequestUri(string subscriptionId return uri; } - internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExportModel body) + internal HttpMessage CreateExportTerraformRequest(string subscriptionId, CommonExportProperties body) { var message = _pipeline.CreateMessage(); var request = message.Request; @@ -73,7 +73,7 @@ internal HttpMessage CreateExportTerraformRequest(string subscriptionId, BaseExp /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public async Task ExportTerraformAsync(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) + public async Task ExportTerraformAsync(string subscriptionId, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(body, nameof(body)); @@ -95,7 +95,7 @@ public async Task ExportTerraformAsync(string subscriptionId, BaseExpo /// The cancellation token to use. /// or is null. /// is an empty string, and was expected to be non-empty. - public Response ExportTerraform(string subscriptionId, BaseExportModel body, CancellationToken cancellationToken = default) + public Response ExportTerraform(string subscriptionId, CommonExportProperties body, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(body, nameof(body)); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs new file mode 100644 index 0000000000000..5182de3a1f956 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Terraform.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Terraform.Tests +{ + public class ExportTerraformTests : TerraformManagementTestBase + { + private static readonly TerraformManagementTestEnvironment s_env = new(); + + public ExportTerraformTests(bool isAsync) : base(isAsync) + { + } + + [TestCase] + [RecordedTest] + public async Task ExportResourceGroupTest() + { + string resourceGroupName = s_env.ResourceGroup; + string vnetName = s_env.VNetName; + ExportResourceGroup exportResourceGroup = new(resourceGroupName); + + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResourceGroup); + string hcl = operationStatus.Value.Properties.Configuration; + + Assert.That(hcl, Does.Contain("azurerm_resource_group")); + Assert.That(hcl, Does.Contain(resourceGroupName)); + + Assert.That(hcl, Does.Contain("azurerm_virtual_network")); + Assert.That(hcl, Does.Contain(vnetName)); + } + + [TestCase] + [RecordedTest] + public async Task ExportQueryTest() + { + string resourceGroupName = s_env.ResourceGroup; + string vnetName = s_env.VNetName; + ExportQuery exportQuery = new($"resourceGroup =~ \"{resourceGroupName}\""); + + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportQuery); + string hcl = operationStatus.Value.Properties.Configuration; + + Assert.That(hcl, Does.Contain("azurerm_virtual_network")); + Assert.That(hcl, Does.Contain(vnetName)); + } + + [TestCase] + [RecordedTest] + public async Task ExportResourceTest() + { + string vnetName = s_env.VNetName; + ExportResource exportResource = new(new[] { s_env.VNetId }); + + ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResource); + + string hcl = operationStatus.Value.Properties.Configuration; + + Assert.That(hcl, Does.Contain("azurerm_virtual_network")); + Assert.That(hcl, Does.Contain(vnetName)); + } + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs index 5d6e6f86ab8af..a47894359c315 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs @@ -1,11 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core; using Azure.Core.TestFramework; namespace Azure.ResourceManager.Terraform.Tests { public class TerraformManagementTestEnvironment : TestEnvironment { + public string VNetName => GetRecordedVariable("VNET_NAME"); + + public ResourceIdentifier VNetId => new(GetRecordedVariable("VNET_ID")); + + public TerraformManagementTestEnvironment() { } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs deleted file mode 100644 index 19b66373098c5..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/Tests/ExportTerraformTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.Terraform.Models; -using NUnit.Framework; - -namespace Azure.ResourceManager.Terraform.Tests -{ - public class ExportTerraformTests : TerraformManagementTestBase - { - private ResourceGroupResource _resourceGroup; - - public ExportTerraformTests(bool isAsync) : base(isAsync) - { - } - - [SetUp] - public async Task SetUp() - { - _resourceGroup = await CreateResourceGroup(DefaultSubscription, "exportTerraformRg", AzureLocation.WestUS); - } - - [TearDown] - public async Task TearDown() - { - await _resourceGroup.DeleteAsync(WaitUntil.Completed); - } - - [TestCase] - [RecordedTest] - public async Task ExportTerraformTest() - { - string rgName = _resourceGroup.Data.Name; - ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, new ExportResourceGroup(rgName)); - string hcl = operationStatus.Value.Properties.Configuration; - - Assert.That(hcl, Does.Contain("azurerm_resource_group")); - Assert.That(hcl, Does.Contain(rgName)); - } - } -} diff --git a/sdk/terraform/test-resources.json b/sdk/terraform/test-resources.json new file mode 100644 index 0000000000000..535ef0d042842 --- /dev/null +++ b/sdk/terraform/test-resources.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "The location of the resource. By default, this is the same as the resource group." + } + } + }, + "variables": { + "vnetName": "dotnet-sdk-test-vnet" + }, + "resources": [ + { + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2024-01-01", + "name": "[variables('vnetName')]", + "location": "[parameters('location')]", + "properties": { + "addressSpace": { + "addressPrefixes": ["10.0.0.0/16"] + }, + "subnets": [ + { + "name": "default", + "properties": { + "addressPrefix": "10.0.0.0/24" + } + } + ] + } + } + ], + "outputs": { + "VNET_NAME": { + "type": "string", + "value": "[variables('vnetName')]" + }, + "VNET_ID": { + "type": "string", + "value": "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]" + } + } +} From 04a368941114aff929a4f556a1e5600b76ff8052 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Thu, 24 Oct 2024 15:50:54 +1100 Subject: [PATCH 27/33] Regen SDK to sync with latest specs --- ...esourceManager.Terraform.netstandard2.0.cs | 90 +++++++++---------- .../src/Generated/ArmTerraformModelFactory.cs | 19 ++-- .../Models/CommonExportProperties.cs | 4 +- .../Models/ExportQuery.Serialization.cs | 4 +- .../src/Generated/Models/ExportQuery.cs | 2 +- .../Models/ExportResource.Serialization.cs | 4 +- .../src/Generated/Models/ExportResource.cs | 2 +- .../ExportResourceGroup.Serialization.cs | 4 +- .../Generated/Models/ExportResourceGroup.cs | 2 +- .../Models/ResourceProvisioningState.cs | 54 ----------- ...Provider.cs => TargetTerraformProvider.cs} | 30 +++---- ...=> TerraformExportResult.Serialization.cs} | 60 ++++++++----- ...portResult.cs => TerraformExportResult.cs} | 19 ++-- .../TerraformOperationStatus.Serialization.cs | 8 +- .../Models/TerraformOperationStatus.cs | 8 +- .../TerraformResourceProvisioningState.cs | 54 +++++++++++ ...ownCommonExportProperties.Serialization.cs | 4 +- .../Models/UnknownCommonExportProperties.cs | 2 +- 18 files changed, 192 insertions(+), 178 deletions(-) delete mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{TargetProvider.cs => TargetTerraformProvider.cs} (50%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResult.Serialization.cs => TerraformExportResult.Serialization.cs} (64%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResult.cs => TerraformExportResult.cs} (74%) create mode 100644 sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformResourceProvisioningState.cs diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index a174bb53c4b5f..9b1333907aa1d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -19,17 +19,17 @@ namespace Azure.ResourceManager.Terraform.Models { public static partial class ArmTerraformModelFactory { - public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } - public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } - public static Azure.ResourceManager.Terraform.Models.ExportResult ExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResources = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } - public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.ExportResult properties = null, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TerraformExportResult TerraformExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResourceIds = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.TerraformExportResult properties = null, Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } public abstract partial class CommonExportProperties : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected CommonExportProperties() { } public bool? FullProperties { get { throw null; } set { } } public bool? MaskSensitive { get { throw null; } set { } } - public Azure.ResourceManager.Terraform.Models.TargetProvider? TargetProvider { get { throw null; } set { } } + public Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? TargetProvider { get { throw null; } set { } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.CommonExportProperties System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } @@ -76,55 +76,36 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel - { - internal ExportResult() { } - public string Configuration { get { throw null; } } - public System.Collections.Generic.IReadOnlyList Errors { get { throw null; } } - public System.Collections.Generic.IReadOnlyList SkippedResources { get { throw null; } } - protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct ResourceProvisioningState : System.IEquatable + public readonly partial struct TargetTerraformProvider : System.IEquatable { private readonly object _dummy; private readonly int _dummyPrimitive; - public ResourceProvisioningState(string value) { throw null; } - public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Canceled { get { throw null; } } - public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Failed { get { throw null; } } - public static Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Succeeded { get { throw null; } } - public bool Equals(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState other) { throw null; } + public TargetTerraformProvider(string value) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TargetTerraformProvider AzApi { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.TargetTerraformProvider AzureRM { get { throw null; } } + public bool Equals(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override bool Equals(object obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } - public static bool operator ==(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState right) { throw null; } - public static implicit operator Azure.ResourceManager.Terraform.Models.ResourceProvisioningState (string value) { throw null; } - public static bool operator !=(Azure.ResourceManager.Terraform.Models.ResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.ResourceProvisioningState right) { throw null; } + public static bool operator ==(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider left, Azure.ResourceManager.Terraform.Models.TargetTerraformProvider right) { throw null; } + public static implicit operator Azure.ResourceManager.Terraform.Models.TargetTerraformProvider (string value) { throw null; } + public static bool operator !=(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider left, Azure.ResourceManager.Terraform.Models.TargetTerraformProvider right) { throw null; } public override string ToString() { throw null; } } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct TargetProvider : System.IEquatable + public partial class TerraformExportResult : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public TargetProvider(string value) { throw null; } - public static Azure.ResourceManager.Terraform.Models.TargetProvider Azapi { get { throw null; } } - public static Azure.ResourceManager.Terraform.Models.TargetProvider Azurerm { get { throw null; } } - public bool Equals(Azure.ResourceManager.Terraform.Models.TargetProvider other) { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object obj) { throw null; } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override int GetHashCode() { throw null; } - public static bool operator ==(Azure.ResourceManager.Terraform.Models.TargetProvider left, Azure.ResourceManager.Terraform.Models.TargetProvider right) { throw null; } - public static implicit operator Azure.ResourceManager.Terraform.Models.TargetProvider (string value) { throw null; } - public static bool operator !=(Azure.ResourceManager.Terraform.Models.TargetProvider left, Azure.ResourceManager.Terraform.Models.TargetProvider right) { throw null; } - public override string ToString() { throw null; } + internal TerraformExportResult() { } + public string Configuration { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Errors { get { throw null; } } + public System.Collections.Generic.IReadOnlyList SkippedResourceIds { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.TerraformExportResult System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.TerraformExportResult System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public partial class TerraformOperationStatus : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { @@ -133,9 +114,9 @@ internal TerraformOperationStatus() { } public Azure.ResponseError Error { get { throw null; } } public string Name { get { throw null; } } public double? PercentComplete { get { throw null; } } - public Azure.ResourceManager.Terraform.Models.ExportResult Properties { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.TerraformExportResult Properties { get { throw null; } } public System.DateTimeOffset? StartOn { get { throw null; } } - public Azure.ResourceManager.Terraform.Models.ResourceProvisioningState Status { get { throw null; } } + public Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState Status { get { throw null; } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.TerraformOperationStatus System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } @@ -143,4 +124,23 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public readonly partial struct TerraformResourceProvisioningState : System.IEquatable + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public TerraformResourceProvisioningState(string value) { throw null; } + public static Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState Canceled { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState Failed { get { throw null; } } + public static Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState Succeeded { get { throw null; } } + public bool Equals(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState other) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override bool Equals(object obj) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public override int GetHashCode() { throw null; } + public static bool operator ==(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState right) { throw null; } + public static implicit operator Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState (string value) { throw null; } + public static bool operator !=(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState left, Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState right) { throw null; } + public override string ToString() { throw null; } + } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 7714311dc4386..507b3526b1d47 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Azure.Core; namespace Azure.ResourceManager.Terraform.Models { @@ -22,7 +23,7 @@ public static partial class ArmTerraformModelFactory /// The name pattern of the Terraform resources. /// Whether to recursively list child resources of the query result. /// A new instance for mocking. - public static ExportQuery ExportQuery(TargetProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) + public static ExportQuery ExportQuery(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) { return new ExportQuery( Type.ExportQuery, @@ -42,7 +43,7 @@ public static ExportQuery ExportQuery(TargetProvider? targetProvider = null, boo /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. /// A new instance for mocking. - public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) + public static ExportResourceGroup ExportResourceGroup(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) { return new ExportResourceGroup( Type.ExportResourceGroup, @@ -63,7 +64,7 @@ public static ExportResourceGroup ExportResourceGroup(TargetProvider? targetProv /// The progress made toward completing the operation. /// Errors that occurred if the operation ended with Canceled or Failed status. /// A new instance for mocking. - public static TerraformOperationStatus TerraformOperationStatus(ExportResult properties = null, ResourceProvisioningState status = default, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, double? percentComplete = null, ResponseError error = null) + public static TerraformOperationStatus TerraformOperationStatus(TerraformExportResult properties = null, TerraformResourceProvisioningState status = default, string name = null, DateTimeOffset? startOn = null, DateTimeOffset? endOn = null, double? percentComplete = null, ResponseError error = null) { return new TerraformOperationStatus( properties, @@ -76,17 +77,17 @@ public static TerraformOperationStatus TerraformOperationStatus(ExportResult pro serializedAdditionalRawData: null); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The Terraform configuration content. - /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. + /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. /// A list of errors derived during exporting each resource. - /// A new instance for mocking. - public static ExportResult ExportResult(string configuration = null, IEnumerable skippedResources = null, IEnumerable errors = null) + /// A new instance for mocking. + public static TerraformExportResult TerraformExportResult(string configuration = null, IEnumerable skippedResourceIds = null, IEnumerable errors = null) { - skippedResources ??= new List(); + skippedResourceIds ??= new List(); errors ??= new List(); - return new ExportResult(configuration, skippedResources?.ToList(), errors?.ToList(), serializedAdditionalRawData: null); + return new TerraformExportResult(configuration, skippedResourceIds?.ToList(), errors?.ToList(), serializedAdditionalRawData: null); } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs index d653819fd69c2..2182d34655b53 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs @@ -60,7 +60,7 @@ protected CommonExportProperties() /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal CommonExportProperties(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) + internal CommonExportProperties(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) { Type = type; TargetProvider = targetProvider; @@ -72,7 +72,7 @@ internal CommonExportProperties(Type type, TargetProvider? targetProvider, bool? /// The parameter type. internal Type Type { get; set; } /// The target Azure Terraform Provider. - public TargetProvider? TargetProvider { get; set; } + public TargetTerraformProvider? TargetProvider { get; set; } /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. public bool? FullProperties { get; set; } /// Mask sensitive attributes in the Terraform configuration. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs index a4dbf2b84201f..969898ed1c07f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs @@ -73,7 +73,7 @@ internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelRea string namePattern = default; bool? recursive = default; Type type = default; - TargetProvider? targetProvider = default; + TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; IDictionary serializedAdditionalRawData = default; @@ -110,7 +110,7 @@ internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelRea { continue; } - targetProvider = new TargetProvider(property.Value.GetString()); + targetProvider = new TargetTerraformProvider(property.Value.GetString()); continue; } if (property.NameEquals("fullProperties"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs index c5ae0b36d6176..2b2437383fe7e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs @@ -33,7 +33,7 @@ public ExportQuery(string query) /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// The name pattern of the Terraform resources. /// Whether to recursively list child resources of the query result. - internal ExportQuery(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportQuery(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { Query = query; NamePattern = namePattern; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs index f018ff6c59117..f7744fbcec025 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs @@ -89,7 +89,7 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo string resourceType = default; string namePattern = default; Type type = default; - TargetProvider? targetProvider = default; + TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; IDictionary serializedAdditionalRawData = default; @@ -139,7 +139,7 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo { continue; } - targetProvider = new TargetProvider(property.Value.GetString()); + targetProvider = new TargetTerraformProvider(property.Value.GetString()); continue; } if (property.NameEquals("fullProperties"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs index a7f0697dba2e8..f2f32795b01bf 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs @@ -36,7 +36,7 @@ public ExportResource(IEnumerable resourceIds) /// The Terraform resource name. Only works when `resourceIds` contains only one item. /// The Terraform resource type. Only works when `resourceIds` contains only one item. /// The name pattern of the Terraform resources. - internal ExportResource(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResource(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { ResourceIds = resourceIds; ResourceName = resourceName; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs index e0b083ce3f6a1..9f884e691cc2b 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs @@ -67,7 +67,7 @@ internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement e string resourceGroupName = default; string namePattern = default; Type type = default; - TargetProvider? targetProvider = default; + TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; IDictionary serializedAdditionalRawData = default; @@ -95,7 +95,7 @@ internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement e { continue; } - targetProvider = new TargetProvider(property.Value.GetString()); + targetProvider = new TargetTerraformProvider(property.Value.GetString()); continue; } if (property.NameEquals("fullProperties"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs index 2a0d46aea5d35..608a96f15d464 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs @@ -32,7 +32,7 @@ public ExportResourceGroup(string resourceGroupName) /// Keeps track of any properties unknown to the library. /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. - internal ExportResourceGroup(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResourceGroup(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { ResourceGroupName = resourceGroupName; NamePattern = namePattern; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs deleted file mode 100644 index 5a69a96b13bad..0000000000000 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ResourceProvisioningState.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.ComponentModel; - -namespace Azure.ResourceManager.Terraform.Models -{ - /// The provisioning state of a resource type. - public readonly partial struct ResourceProvisioningState : IEquatable - { - private readonly string _value; - - /// Initializes a new instance of . - /// is null. - public ResourceProvisioningState(string value) - { - _value = value ?? throw new ArgumentNullException(nameof(value)); - } - - private const string SucceededValue = "Succeeded"; - private const string FailedValue = "Failed"; - private const string CanceledValue = "Canceled"; - - /// Resource has been created. - public static ResourceProvisioningState Succeeded { get; } = new ResourceProvisioningState(SucceededValue); - /// Resource creation failed. - public static ResourceProvisioningState Failed { get; } = new ResourceProvisioningState(FailedValue); - /// Resource creation was canceled. - public static ResourceProvisioningState Canceled { get; } = new ResourceProvisioningState(CanceledValue); - /// Determines if two values are the same. - public static bool operator ==(ResourceProvisioningState left, ResourceProvisioningState right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(ResourceProvisioningState left, ResourceProvisioningState right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator ResourceProvisioningState(string value) => new ResourceProvisioningState(value); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is ResourceProvisioningState other && Equals(other); - /// - public bool Equals(ResourceProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; - /// - public override string ToString() => _value; - } -} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetTerraformProvider.cs similarity index 50% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetTerraformProvider.cs index 9def376f32f94..7ac7d049825cf 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetProvider.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TargetTerraformProvider.cs @@ -11,36 +11,36 @@ namespace Azure.ResourceManager.Terraform.Models { /// The target Azure Terraform Provider. - public readonly partial struct TargetProvider : IEquatable + public readonly partial struct TargetTerraformProvider : IEquatable { private readonly string _value; - /// Initializes a new instance of . + /// Initializes a new instance of . /// is null. - public TargetProvider(string value) + public TargetTerraformProvider(string value) { _value = value ?? throw new ArgumentNullException(nameof(value)); } - private const string AzurermValue = "azurerm"; - private const string AzapiValue = "azapi"; + private const string AzureRMValue = "azurerm"; + private const string AzApiValue = "azapi"; /// https://registry.terraform.io/providers/hashicorp/azurerm/latest. - public static TargetProvider Azurerm { get; } = new TargetProvider(AzurermValue); + public static TargetTerraformProvider AzureRM { get; } = new TargetTerraformProvider(AzureRMValue); /// https://registry.terraform.io/providers/Azure/azapi/latest. - public static TargetProvider Azapi { get; } = new TargetProvider(AzapiValue); - /// Determines if two values are the same. - public static bool operator ==(TargetProvider left, TargetProvider right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(TargetProvider left, TargetProvider right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator TargetProvider(string value) => new TargetProvider(value); + public static TargetTerraformProvider AzApi { get; } = new TargetTerraformProvider(AzApiValue); + /// Determines if two values are the same. + public static bool operator ==(TargetTerraformProvider left, TargetTerraformProvider right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TargetTerraformProvider left, TargetTerraformProvider right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator TargetTerraformProvider(string value) => new TargetTerraformProvider(value); /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is TargetProvider other && Equals(other); + public override bool Equals(object obj) => obj is TargetTerraformProvider other && Equals(other); /// - public bool Equals(TargetProvider other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + public bool Equals(TargetTerraformProvider other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.Serialization.cs similarity index 64% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.Serialization.cs index d4d8c37aff524..e08eb4e6a8c7e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.ResourceManager.Terraform.Models { - public partial class ExportResult : IUtf8JsonSerializable, IJsonModel + public partial class TerraformExportResult : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOpti /// The client options for reading and writing models. protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResult)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(TerraformExportResult)} does not support writing '{format}' format."); } if (Optional.IsDefined(Configuration)) @@ -39,12 +39,17 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("configuration"u8); writer.WriteStringValue(Configuration); } - if (Optional.IsCollectionDefined(SkippedResources)) + if (Optional.IsCollectionDefined(SkippedResourceIds)) { writer.WritePropertyName("skippedResources"u8); writer.WriteStartArray(); - foreach (var item in SkippedResources) + foreach (var item in SkippedResourceIds) { + if (item == null) + { + writer.WriteNullValue(); + continue; + } writer.WriteStringValue(item); } writer.WriteEndArray(); @@ -76,19 +81,19 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } } - ExportResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + TerraformExportResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResult)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(TerraformExportResult)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeExportResult(document.RootElement, options); + return DeserializeTerraformExportResult(document.RootElement, options); } - internal static ExportResult DeserializeExportResult(JsonElement element, ModelReaderWriterOptions options = null) + internal static TerraformExportResult DeserializeTerraformExportResult(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -97,7 +102,7 @@ internal static ExportResult DeserializeExportResult(JsonElement element, ModelR return null; } string configuration = default; - IReadOnlyList skippedResources = default; + IReadOnlyList skippedResources = default; IReadOnlyList errors = default; IDictionary serializedAdditionalRawData = default; Dictionary rawDataDictionary = new Dictionary(); @@ -114,10 +119,17 @@ internal static ExportResult DeserializeExportResult(JsonElement element, ModelR { continue; } - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(item.GetString()); + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(new ResourceIdentifier(item.GetString())); + } } skippedResources = array; continue; @@ -142,38 +154,38 @@ internal static ExportResult DeserializeExportResult(JsonElement element, ModelR } } serializedAdditionalRawData = rawDataDictionary; - return new ExportResult(configuration, skippedResources ?? new ChangeTrackingList(), errors ?? new ChangeTrackingList(), serializedAdditionalRawData); + return new TerraformExportResult(configuration, skippedResources ?? new ChangeTrackingList(), errors ?? new ChangeTrackingList(), serializedAdditionalRawData); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ExportResult)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(TerraformExportResult)} does not support writing '{options.Format}' format."); } } - ExportResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + TerraformExportResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeExportResult(document.RootElement, options); + return DeserializeTerraformExportResult(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ExportResult)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(TerraformExportResult)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.cs similarity index 74% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.cs index e6759be2d909f..68a442fa99f7f 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResult.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformExportResult.cs @@ -7,11 +7,12 @@ using System; using System.Collections.Generic; +using Azure.Core; namespace Azure.ResourceManager.Terraform.Models { /// The Terraform export result. - public partial class ExportResult + public partial class TerraformExportResult { /// /// Keeps track of any properties unknown to the library. @@ -45,22 +46,22 @@ public partial class ExportResult /// private IDictionary _serializedAdditionalRawData; - /// Initializes a new instance of . - internal ExportResult() + /// Initializes a new instance of . + internal TerraformExportResult() { - SkippedResources = new ChangeTrackingList(); + SkippedResourceIds = new ChangeTrackingList(); Errors = new ChangeTrackingList(); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The Terraform configuration content. - /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. + /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. /// A list of errors derived during exporting each resource. /// Keeps track of any properties unknown to the library. - internal ExportResult(string configuration, IReadOnlyList skippedResources, IReadOnlyList errors, IDictionary serializedAdditionalRawData) + internal TerraformExportResult(string configuration, IReadOnlyList skippedResourceIds, IReadOnlyList errors, IDictionary serializedAdditionalRawData) { Configuration = configuration; - SkippedResources = skippedResources; + SkippedResourceIds = skippedResourceIds; Errors = errors; _serializedAdditionalRawData = serializedAdditionalRawData; } @@ -68,7 +69,7 @@ internal ExportResult(string configuration, IReadOnlyList skippedResourc /// The Terraform configuration content. public string Configuration { get; } /// A list of Azure resources which are not exported to Terraform due to there is no corresponding resources in Terraform. - public IReadOnlyList SkippedResources { get; } + public IReadOnlyList SkippedResourceIds { get; } /// A list of errors derived during exporting each resource. public IReadOnlyList Errors { get; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs index 12a756dae0ce2..8774d65bbf6ae 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.Serialization.cs @@ -103,8 +103,8 @@ internal static TerraformOperationStatus DeserializeTerraformOperationStatus(Jso { return null; } - ExportResult properties = default; - ResourceProvisioningState status = default; + TerraformExportResult properties = default; + TerraformResourceProvisioningState status = default; string name = default; DateTimeOffset? startTime = default; DateTimeOffset? endTime = default; @@ -120,12 +120,12 @@ internal static TerraformOperationStatus DeserializeTerraformOperationStatus(Jso { continue; } - properties = ExportResult.DeserializeExportResult(property.Value, options); + properties = TerraformExportResult.DeserializeTerraformExportResult(property.Value, options); continue; } if (property.NameEquals("status"u8)) { - status = new ResourceProvisioningState(property.Value.GetString()); + status = new TerraformResourceProvisioningState(property.Value.GetString()); continue; } if (property.NameEquals("name"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs index 4a88942e2e30e..4ae95bbb75d63 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformOperationStatus.cs @@ -47,7 +47,7 @@ public partial class TerraformOperationStatus /// Initializes a new instance of . /// The operation status. - internal TerraformOperationStatus(ResourceProvisioningState status) + internal TerraformOperationStatus(TerraformResourceProvisioningState status) { Status = status; } @@ -61,7 +61,7 @@ internal TerraformOperationStatus(ResourceProvisioningState status) /// The progress made toward completing the operation. /// Errors that occurred if the operation ended with Canceled or Failed status. /// Keeps track of any properties unknown to the library. - internal TerraformOperationStatus(ExportResult properties, ResourceProvisioningState status, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, double? percentComplete, ResponseError error, IDictionary serializedAdditionalRawData) + internal TerraformOperationStatus(TerraformExportResult properties, TerraformResourceProvisioningState status, string name, DateTimeOffset? startOn, DateTimeOffset? endOn, double? percentComplete, ResponseError error, IDictionary serializedAdditionalRawData) { Properties = properties; Status = status; @@ -79,9 +79,9 @@ internal TerraformOperationStatus() } /// RP-specific properties for the operationStatus resource, only appears when operation ended with Succeeded status. - public ExportResult Properties { get; } + public TerraformExportResult Properties { get; } /// The operation status. - public ResourceProvisioningState Status { get; } + public TerraformResourceProvisioningState Status { get; } /// The name of the operationStatus resource. public string Name { get; } /// Operation start time. diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformResourceProvisioningState.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformResourceProvisioningState.cs new file mode 100644 index 0000000000000..9c9f12b2e4b41 --- /dev/null +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/TerraformResourceProvisioningState.cs @@ -0,0 +1,54 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace Azure.ResourceManager.Terraform.Models +{ + /// The provisioning state of a resource type. + public readonly partial struct TerraformResourceProvisioningState : IEquatable + { + private readonly string _value; + + /// Initializes a new instance of . + /// is null. + public TerraformResourceProvisioningState(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SucceededValue = "Succeeded"; + private const string FailedValue = "Failed"; + private const string CanceledValue = "Canceled"; + + /// Resource has been created. + public static TerraformResourceProvisioningState Succeeded { get; } = new TerraformResourceProvisioningState(SucceededValue); + /// Resource creation failed. + public static TerraformResourceProvisioningState Failed { get; } = new TerraformResourceProvisioningState(FailedValue); + /// Resource creation was canceled. + public static TerraformResourceProvisioningState Canceled { get; } = new TerraformResourceProvisioningState(CanceledValue); + /// Determines if two values are the same. + public static bool operator ==(TerraformResourceProvisioningState left, TerraformResourceProvisioningState right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(TerraformResourceProvisioningState left, TerraformResourceProvisioningState right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator TerraformResourceProvisioningState(string value) => new TerraformResourceProvisioningState(value); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TerraformResourceProvisioningState other && Equals(other); + /// + public bool Equals(TerraformResourceProvisioningState other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + /// + public override string ToString() => _value; + } +} diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs index 52693880f4bbf..2fcaae5bb5923 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs @@ -58,7 +58,7 @@ internal static UnknownCommonExportProperties DeserializeUnknownCommonExportProp return null; } Type type = "Unknown"; - TargetProvider? targetProvider = default; + TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; IDictionary serializedAdditionalRawData = default; @@ -76,7 +76,7 @@ internal static UnknownCommonExportProperties DeserializeUnknownCommonExportProp { continue; } - targetProvider = new TargetProvider(property.Value.GetString()); + targetProvider = new TargetTerraformProvider(property.Value.GetString()); continue; } if (property.NameEquals("fullProperties"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs index ac17049b65b99..7ed3b508eba25 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs @@ -19,7 +19,7 @@ internal partial class UnknownCommonExportProperties : CommonExportProperties /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal UnknownCommonExportProperties(Type type, TargetProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal UnknownCommonExportProperties(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { Type = type; } From 3963ac662bd063bbee5541d35124fcb3eb61d20c Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 25 Oct 2024 09:15:08 +1100 Subject: [PATCH 28/33] Renamed ExportResource, removed InheritanceCheckTest exclusion --- ...esourceManager.Terraform.netstandard2.0.cs | 28 +++++++------- .../CommonExportProperties.Serialization.cs | 2 +- .../Models/CommonExportProperties.cs | 2 +- ... ExportResourceTerraform.Serialization.cs} | 38 +++++++++---------- ...Resource.cs => ExportResourceTerraform.cs} | 14 +++---- .../tests/ExportTerraformTests.cs | 2 +- .../tests/InheritanceCheckTests.cs | 7 ---- 7 files changed, 43 insertions(+), 50 deletions(-) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResource.Serialization.cs => ExportResourceTerraform.Serialization.cs} (78%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResource.cs => ExportResourceTerraform.cs} (79%) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index 9b1333907aa1d..a68484ef68585 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -50,20 +50,6 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportResource : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel - { - public ExportResource(System.Collections.Generic.IEnumerable resourceIds) { } - public string NamePattern { get { throw null; } set { } } - public System.Collections.Generic.IList ResourceIds { get { throw null; } } - public string ResourceName { get { throw null; } set { } } - public string ResourceType { get { throw null; } set { } } - protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResource System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - } public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ExportResourceGroup(string resourceGroupName) { } @@ -76,6 +62,20 @@ protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter write string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } + public partial class ExportResourceTerraform : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public ExportResourceTerraform(System.Collections.Generic.IEnumerable resourceIds) { } + public string NamePattern { get { throw null; } set { } } + public System.Collections.Generic.IList ResourceIds { get { throw null; } } + public string ResourceName { get { throw null; } set { } } + public string ResourceType { get { throw null; } set { } } + protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResourceTerraform System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResourceTerraform System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct TargetTerraformProvider : System.IEquatable { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs index dab8d34f771ac..5eef8dd0284ce 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs @@ -93,7 +93,7 @@ internal static CommonExportProperties DeserializeCommonExportProperties(JsonEle switch (discriminator.GetString()) { case "ExportQuery": return ExportQuery.DeserializeExportQuery(element, options); - case "ExportResource": return ExportResource.DeserializeExportResource(element, options); + case "ExportResource": return ExportResourceTerraform.DeserializeExportResourceTerraform(element, options); case "ExportResourceGroup": return ExportResourceGroup.DeserializeExportResourceGroup(element, options); } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs index 2182d34655b53..167e01f9a5fca 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs @@ -13,7 +13,7 @@ namespace Azure.ResourceManager.Terraform.Models /// /// The base export parameter /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public abstract partial class CommonExportProperties { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs similarity index 78% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs index f7744fbcec025..2cb99156ba9be 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.ResourceManager.Terraform.Models { - public partial class ExportResource : IUtf8JsonSerializable, IJsonModel + public partial class ExportResourceTerraform : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOp /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResource)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ExportResourceTerraform)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); @@ -64,19 +64,19 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri } } - ExportResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ExportResourceTerraform IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResource)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ExportResourceTerraform)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeExportResource(document.RootElement, options); + return DeserializeExportResourceTerraform(document.RootElement, options); } - internal static ExportResource DeserializeExportResource(JsonElement element, ModelReaderWriterOptions options = null) + internal static ExportResourceTerraform DeserializeExportResourceTerraform(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -166,7 +166,7 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo } } serializedAdditionalRawData = rawDataDictionary; - return new ExportResource( + return new ExportResourceTerraform( type, targetProvider, fullProperties, @@ -178,35 +178,35 @@ internal static ExportResource DeserializeExportResource(JsonElement element, Mo namePattern); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ExportResource)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportResourceTerraform)} does not support writing '{options.Format}' format."); } } - ExportResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ExportResourceTerraform IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeExportResource(document.RootElement, options); + return DeserializeExportResourceTerraform(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ExportResource)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportResourceTerraform)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs similarity index 79% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs index f2f32795b01bf..c384dfe76b2ea 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResource.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs @@ -13,12 +13,12 @@ namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for individual resources. - public partial class ExportResource : CommonExportProperties + public partial class ExportResourceTerraform : CommonExportProperties { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The id of the resource to be exported. /// is null. - public ExportResource(IEnumerable resourceIds) + public ExportResourceTerraform(IEnumerable resourceIds) { Argument.AssertNotNull(resourceIds, nameof(resourceIds)); @@ -26,7 +26,7 @@ public ExportResource(IEnumerable resourceIds) Type = Type.ExportResource; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. @@ -36,7 +36,7 @@ public ExportResource(IEnumerable resourceIds) /// The Terraform resource name. Only works when `resourceIds` contains only one item. /// The Terraform resource type. Only works when `resourceIds` contains only one item. /// The name pattern of the Terraform resources. - internal ExportResource(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResourceTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { ResourceIds = resourceIds; ResourceName = resourceName; @@ -45,8 +45,8 @@ internal ExportResource(Type type, TargetTerraformProvider? targetProvider, bool Type = type; } - /// Initializes a new instance of for deserialization. - internal ExportResource() + /// Initializes a new instance of for deserialization. + internal ExportResourceTerraform() { } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs index 5182de3a1f956..2adff9de0179b 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs @@ -54,7 +54,7 @@ public async Task ExportQueryTest() public async Task ExportResourceTest() { string vnetName = s_env.VNetName; - ExportResource exportResource = new(new[] { s_env.VNetId }); + ExportResourceTerraform exportResource = new(new[] { s_env.VNetId }); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResource); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs index 7c7e4717e8dd6..51ecf6d1dc7e0 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/InheritanceCheckTests.cs @@ -1,16 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using NUnit.Framework; - namespace Azure.ResourceManager.TestFramework { public partial class InheritanceCheckTests { - [OneTimeSetUp] - public void SetExceptionList() - { - ExceptionList = new string[] { "ExportResource" }; - } } } From d9d105cec6cda1713157b70ff9e8e4a233ea89bb Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 25 Oct 2024 12:11:57 +1100 Subject: [PATCH 29/33] Fixed test variables use --- .../Azure.ResourceManager.Terraform/assets.json | 2 +- .../tests/ExportTerraformTests.cs | 14 ++++++-------- .../tests/TerraformManagementTestEnvironment.cs | 3 --- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json index 291ef5cc33ece..255b73238d74e 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/assets.json +++ b/sdk/terraform/Azure.ResourceManager.Terraform/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/terraform/Azure.ResourceManager.Terraform", - "Tag": "net/terraform/Azure.ResourceManager.Terraform_1db6dacdb1" + "Tag": "net/terraform/Azure.ResourceManager.Terraform_ac6492ee96" } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs index 2adff9de0179b..f005b063d400d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs @@ -10,8 +10,6 @@ namespace Azure.ResourceManager.Terraform.Tests { public class ExportTerraformTests : TerraformManagementTestBase { - private static readonly TerraformManagementTestEnvironment s_env = new(); - public ExportTerraformTests(bool isAsync) : base(isAsync) { } @@ -20,8 +18,8 @@ public ExportTerraformTests(bool isAsync) : base(isAsync) [RecordedTest] public async Task ExportResourceGroupTest() { - string resourceGroupName = s_env.ResourceGroup; - string vnetName = s_env.VNetName; + string resourceGroupName = TestEnvironment.ResourceGroup; + string vnetName = TestEnvironment.VNetName; ExportResourceGroup exportResourceGroup = new(resourceGroupName); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResourceGroup); @@ -38,8 +36,8 @@ public async Task ExportResourceGroupTest() [RecordedTest] public async Task ExportQueryTest() { - string resourceGroupName = s_env.ResourceGroup; - string vnetName = s_env.VNetName; + string resourceGroupName = TestEnvironment.ResourceGroup; + string vnetName = TestEnvironment.VNetName; ExportQuery exportQuery = new($"resourceGroup =~ \"{resourceGroupName}\""); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportQuery); @@ -53,8 +51,8 @@ public async Task ExportQueryTest() [RecordedTest] public async Task ExportResourceTest() { - string vnetName = s_env.VNetName; - ExportResourceTerraform exportResource = new(new[] { s_env.VNetId }); + string vnetName = TestEnvironment.VNetName; + ExportResourceTerraform exportResource = new(new[] { TestEnvironment.VNetId }); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResource); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs index a47894359c315..97a16cba6aec6 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/TerraformManagementTestEnvironment.cs @@ -9,9 +9,6 @@ namespace Azure.ResourceManager.Terraform.Tests public class TerraformManagementTestEnvironment : TestEnvironment { public string VNetName => GetRecordedVariable("VNET_NAME"); - public ResourceIdentifier VNetId => new(GetRecordedVariable("VNET_ID")); - - public TerraformManagementTestEnvironment() { } } } From e558d5473a10985c5b21d943335b6913e36b18b5 Mon Sep 17 00:00:00 2001 From: Gerry Tan Date: Fri, 25 Oct 2024 12:47:12 +1100 Subject: [PATCH 30/33] add Terraform suffix to ExportQuery and ExportResourceGroup --- ...esourceManager.Terraform.netstandard2.0.cs | 32 ++++++++-------- .../Sample_SubscriptionResourceExtensions.cs | 2 +- .../src/Generated/ArmTerraformModelFactory.cs | 16 ++++---- .../CommonExportProperties.Serialization.cs | 4 +- .../Models/CommonExportProperties.cs | 2 +- ... => ExportQueryTerraform.Serialization.cs} | 38 +++++++++---------- ...ExportQuery.cs => ExportQueryTerraform.cs} | 14 +++---- ...rtResourceGroupTerraform.Serialization.cs} | 38 +++++++++---------- ...oup.cs => ExportResourceGroupTerraform.cs} | 14 +++---- .../tests/ExportTerraformTests.cs | 4 +- 10 files changed, 82 insertions(+), 82 deletions(-) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportQuery.Serialization.cs => ExportQueryTerraform.Serialization.cs} (76%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportQuery.cs => ExportQueryTerraform.cs} (81%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResourceGroup.Serialization.cs => ExportResourceGroupTerraform.Serialization.cs} (72%) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{ExportResourceGroup.cs => ExportResourceGroupTerraform.cs} (75%) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index a68484ef68585..63568e178fb97 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -19,8 +19,8 @@ namespace Azure.ResourceManager.Terraform.Models { public static partial class ArmTerraformModelFactory { - public static Azure.ResourceManager.Terraform.Models.ExportQuery ExportQuery(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } - public static Azure.ResourceManager.Terraform.Models.ExportResourceGroup ExportResourceGroup(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportQueryTerraform ExportQueryTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportResourceGroupTerraform ExportResourceGroupTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.TerraformExportResult TerraformExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResourceIds = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.TerraformExportResult properties = null, Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } @@ -37,30 +37,30 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportQuery : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public partial class ExportQueryTerraform : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - public ExportQuery(string query) { } + public ExportQueryTerraform(string query) { } public string NamePattern { get { throw null; } set { } } public string Query { get { throw null; } } public bool? Recursive { get { throw null; } set { } } protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportQuery System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + Azure.ResourceManager.Terraform.Models.ExportQueryTerraform System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportQueryTerraform System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } - public partial class ExportResourceGroup : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + public partial class ExportResourceGroupTerraform : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { - public ExportResourceGroup(string resourceGroupName) { } + public ExportResourceGroupTerraform(string resourceGroupName) { } public string NamePattern { get { throw null; } set { } } public string ResourceGroupName { get { throw null; } } protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } - Azure.ResourceManager.Terraform.Models.ExportResourceGroup System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } - System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + Azure.ResourceManager.Terraform.Models.ExportResourceGroupTerraform System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Terraform.Models.ExportResourceGroupTerraform System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } } public partial class ExportResourceTerraform : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs index c75110c9e5d88..ac302321fa08c 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -36,7 +36,7 @@ public async Task ExportTerraform_ExportTerraform() SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); // invoke the operation - CommonExportProperties body = new ExportResourceGroup("rg1"); + CommonExportProperties body = new ExportResourceGroupTerraform("rg1"); ArmOperation lro = await subscriptionResource.ExportTerraformAsync(WaitUntil.Completed, body); TerraformOperationStatus result = lro.Value; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 507b3526b1d47..0cf237f47b95b 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -15,17 +15,17 @@ namespace Azure.ResourceManager.Terraform.Models /// Model factory for models. public static partial class ArmTerraformModelFactory { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// The name pattern of the Terraform resources. /// Whether to recursively list child resources of the query result. - /// A new instance for mocking. - public static ExportQuery ExportQuery(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) + /// A new instance for mocking. + public static ExportQueryTerraform ExportQueryTerraform(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) { - return new ExportQuery( + return new ExportQueryTerraform( Type.ExportQuery, targetProvider, fullProperties, @@ -36,16 +36,16 @@ public static ExportQuery ExportQuery(TargetTerraformProvider? targetProvider = recursive); } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. /// Mask sensitive attributes in the Terraform configuration. /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. - /// A new instance for mocking. - public static ExportResourceGroup ExportResourceGroup(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) + /// A new instance for mocking. + public static ExportResourceGroupTerraform ExportResourceGroupTerraform(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) { - return new ExportResourceGroup( + return new ExportResourceGroupTerraform( Type.ExportResourceGroup, targetProvider, fullProperties, diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs index 5eef8dd0284ce..449540dc99609 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs @@ -92,9 +92,9 @@ internal static CommonExportProperties DeserializeCommonExportProperties(JsonEle { switch (discriminator.GetString()) { - case "ExportQuery": return ExportQuery.DeserializeExportQuery(element, options); + case "ExportQuery": return ExportQueryTerraform.DeserializeExportQueryTerraform(element, options); case "ExportResource": return ExportResourceTerraform.DeserializeExportResourceTerraform(element, options); - case "ExportResourceGroup": return ExportResourceGroup.DeserializeExportResourceGroup(element, options); + case "ExportResourceGroup": return ExportResourceGroupTerraform.DeserializeExportResourceGroupTerraform(element, options); } } return UnknownCommonExportProperties.DeserializeUnknownCommonExportProperties(element, options); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs index 167e01f9a5fca..75265c18d3e5d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs @@ -13,7 +13,7 @@ namespace Azure.ResourceManager.Terraform.Models /// /// The base export parameter /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. - /// The available derived classes include , and . + /// The available derived classes include , and . /// public abstract partial class CommonExportProperties { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs similarity index 76% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs index 969898ed1c07f..a039b7a6b9989 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.ResourceManager.Terraform.Models { - public partial class ExportQuery : IUtf8JsonSerializable, IJsonModel + public partial class ExportQueryTerraform : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptio /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportQuery)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ExportQueryTerraform)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); @@ -49,19 +49,19 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri } } - ExportQuery IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ExportQueryTerraform IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportQuery)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ExportQueryTerraform)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeExportQuery(document.RootElement, options); + return DeserializeExportQueryTerraform(document.RootElement, options); } - internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelReaderWriterOptions options = null) + internal static ExportQueryTerraform DeserializeExportQueryTerraform(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -137,7 +137,7 @@ internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelRea } } serializedAdditionalRawData = rawDataDictionary; - return new ExportQuery( + return new ExportQueryTerraform( type, targetProvider, fullProperties, @@ -148,35 +148,35 @@ internal static ExportQuery DeserializeExportQuery(JsonElement element, ModelRea recursive); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ExportQuery)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportQueryTerraform)} does not support writing '{options.Format}' format."); } } - ExportQuery IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ExportQueryTerraform IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeExportQuery(document.RootElement, options); + return DeserializeExportQueryTerraform(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ExportQuery)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportQueryTerraform)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs similarity index 81% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs index 2b2437383fe7e..7bed96c6f67e2 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQuery.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs @@ -11,12 +11,12 @@ namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for resources queried by ARG (Azure Resource Graph). - public partial class ExportQuery : CommonExportProperties + public partial class ExportQueryTerraform : CommonExportProperties { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// is null. - public ExportQuery(string query) + public ExportQueryTerraform(string query) { Argument.AssertNotNull(query, nameof(query)); @@ -24,7 +24,7 @@ public ExportQuery(string query) Type = Type.ExportQuery; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. @@ -33,7 +33,7 @@ public ExportQuery(string query) /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// The name pattern of the Terraform resources. /// Whether to recursively list child resources of the query result. - internal ExportQuery(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportQueryTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { Query = query; NamePattern = namePattern; @@ -41,8 +41,8 @@ internal ExportQuery(Type type, TargetTerraformProvider? targetProvider, bool? f Type = type; } - /// Initializes a new instance of for deserialization. - internal ExportQuery() + /// Initializes a new instance of for deserialization. + internal ExportQueryTerraform() { } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs similarity index 72% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs index 9f884e691cc2b..7f7b8762f493a 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs @@ -13,11 +13,11 @@ namespace Azure.ResourceManager.Terraform.Models { - public partial class ExportResourceGroup : IUtf8JsonSerializable, IJsonModel + public partial class ExportResourceGroupTerraform : IUtf8JsonSerializable, IJsonModel { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); JsonModelWriteCore(writer, options); @@ -28,10 +28,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWri /// The client options for reading and writing models. protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support writing '{format}' format."); + throw new FormatException($"The model {nameof(ExportResourceGroupTerraform)} does not support writing '{format}' format."); } base.JsonModelWriteCore(writer, options); @@ -44,19 +44,19 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri } } - ExportResourceGroup IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + ExportResourceGroupTerraform IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; if (format != "J") { - throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support reading '{format}' format."); + throw new FormatException($"The model {nameof(ExportResourceGroupTerraform)} does not support reading '{format}' format."); } using JsonDocument document = JsonDocument.ParseValue(ref reader); - return DeserializeExportResourceGroup(document.RootElement, options); + return DeserializeExportResourceGroupTerraform(document.RootElement, options); } - internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement element, ModelReaderWriterOptions options = null) + internal static ExportResourceGroupTerraform DeserializeExportResourceGroupTerraform(JsonElement element, ModelReaderWriterOptions options = null) { options ??= ModelSerializationExtensions.WireOptions; @@ -122,7 +122,7 @@ internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement e } } serializedAdditionalRawData = rawDataDictionary; - return new ExportResourceGroup( + return new ExportResourceGroupTerraform( type, targetProvider, fullProperties, @@ -132,35 +132,35 @@ internal static ExportResourceGroup DeserializeExportResourceGroup(JsonElement e namePattern); } - BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": return ModelReaderWriter.Write(this, options); default: - throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support writing '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportResourceGroupTerraform)} does not support writing '{options.Format}' format."); } } - ExportResourceGroup IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + ExportResourceGroupTerraform IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) { - var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; switch (format) { case "J": { using JsonDocument document = JsonDocument.Parse(data); - return DeserializeExportResourceGroup(document.RootElement, options); + return DeserializeExportResourceGroupTerraform(document.RootElement, options); } default: - throw new FormatException($"The model {nameof(ExportResourceGroup)} does not support reading '{options.Format}' format."); + throw new FormatException($"The model {nameof(ExportResourceGroupTerraform)} does not support reading '{options.Format}' format."); } } - string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs similarity index 75% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs index 608a96f15d464..056271047470d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroup.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs @@ -11,12 +11,12 @@ namespace Azure.ResourceManager.Terraform.Models { /// Export parameter for a resource group. - public partial class ExportResourceGroup : CommonExportProperties + public partial class ExportResourceGroupTerraform : CommonExportProperties { - /// Initializes a new instance of . + /// Initializes a new instance of . /// The name of the resource group to be exported. /// is null. - public ExportResourceGroup(string resourceGroupName) + public ExportResourceGroupTerraform(string resourceGroupName) { Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); @@ -24,7 +24,7 @@ public ExportResourceGroup(string resourceGroupName) Type = Type.ExportResourceGroup; } - /// Initializes a new instance of . + /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. @@ -32,15 +32,15 @@ public ExportResourceGroup(string resourceGroupName) /// Keeps track of any properties unknown to the library. /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. - internal ExportResourceGroup(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResourceGroupTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) { ResourceGroupName = resourceGroupName; NamePattern = namePattern; Type = type; } - /// Initializes a new instance of for deserialization. - internal ExportResourceGroup() + /// Initializes a new instance of for deserialization. + internal ExportResourceGroupTerraform() { } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs index f005b063d400d..f86e7e6a5f08d 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tests/ExportTerraformTests.cs @@ -20,7 +20,7 @@ public async Task ExportResourceGroupTest() { string resourceGroupName = TestEnvironment.ResourceGroup; string vnetName = TestEnvironment.VNetName; - ExportResourceGroup exportResourceGroup = new(resourceGroupName); + ExportResourceGroupTerraform exportResourceGroup = new(resourceGroupName); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportResourceGroup); string hcl = operationStatus.Value.Properties.Configuration; @@ -38,7 +38,7 @@ public async Task ExportQueryTest() { string resourceGroupName = TestEnvironment.ResourceGroup; string vnetName = TestEnvironment.VNetName; - ExportQuery exportQuery = new($"resourceGroup =~ \"{resourceGroupName}\""); + ExportQueryTerraform exportQuery = new($"resourceGroup =~ \"{resourceGroupName}\""); ArmOperation operationStatus = await DefaultSubscription.ExportTerraformAsync(WaitUntil.Completed, exportQuery); string hcl = operationStatus.Value.Properties.Configuration; From f9544be0f13dcdf38a70fbd4e5d6ac8b81bf07f2 Mon Sep 17 00:00:00 2001 From: Arthur Ma Date: Tue, 29 Oct 2024 10:53:03 +0800 Subject: [PATCH 31/33] update --- ...esourceManager.Terraform.netstandard2.0.cs | 10 +++---- .../src/Generated/ArmTerraformModelFactory.cs | 28 +++++++++---------- .../CommonExportProperties.Serialization.cs | 8 +++--- .../Models/CommonExportProperties.cs | 16 +++++------ .../Models/{Type.cs => CommonExportType.cs} | 28 +++++++++---------- .../ExportQueryTerraform.Serialization.cs | 8 +++--- .../Generated/Models/ExportQueryTerraform.cs | 14 +++++----- ...ortResourceGroupTerraform.Serialization.cs | 4 +-- .../Models/ExportResourceGroupTerraform.cs | 8 +++--- .../ExportResourceTerraform.Serialization.cs | 4 +-- .../Models/ExportResourceTerraform.cs | 8 +++--- ...ownCommonExportProperties.Serialization.cs | 4 +-- .../Models/UnknownCommonExportProperties.cs | 6 ++-- .../tsp-location.yaml | 2 +- 14 files changed, 74 insertions(+), 74 deletions(-) rename sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/{Type.cs => CommonExportType.cs} (50%) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs index 63568e178fb97..6ba77b806a8b8 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/api/Azure.ResourceManager.Terraform.netstandard2.0.cs @@ -19,16 +19,16 @@ namespace Azure.ResourceManager.Terraform.Models { public static partial class ArmTerraformModelFactory { - public static Azure.ResourceManager.Terraform.Models.ExportQueryTerraform ExportQueryTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string query = null, string namePattern = null, bool? recursive = default(bool?)) { throw null; } - public static Azure.ResourceManager.Terraform.Models.ExportResourceGroupTerraform ExportResourceGroupTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? fullProperties = default(bool?), bool? maskSensitive = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportQueryTerraform ExportQueryTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? isOutputFullPropertiesEnabled = default(bool?), bool? isMaskSensitiveEnabled = default(bool?), string query = null, string namePattern = null, bool? isRecursive = default(bool?)) { throw null; } + public static Azure.ResourceManager.Terraform.Models.ExportResourceGroupTerraform ExportResourceGroupTerraform(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? targetProvider = default(Azure.ResourceManager.Terraform.Models.TargetTerraformProvider?), bool? isOutputFullPropertiesEnabled = default(bool?), bool? isMaskSensitiveEnabled = default(bool?), string resourceGroupName = null, string namePattern = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.TerraformExportResult TerraformExportResult(string configuration = null, System.Collections.Generic.IEnumerable skippedResourceIds = null, System.Collections.Generic.IEnumerable errors = null) { throw null; } public static Azure.ResourceManager.Terraform.Models.TerraformOperationStatus TerraformOperationStatus(Azure.ResourceManager.Terraform.Models.TerraformExportResult properties = null, Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState status = default(Azure.ResourceManager.Terraform.Models.TerraformResourceProvisioningState), string name = null, System.DateTimeOffset? startOn = default(System.DateTimeOffset?), System.DateTimeOffset? endOn = default(System.DateTimeOffset?), double? percentComplete = default(double?), Azure.ResponseError error = null) { throw null; } } public abstract partial class CommonExportProperties : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { protected CommonExportProperties() { } - public bool? FullProperties { get { throw null; } set { } } - public bool? MaskSensitive { get { throw null; } set { } } + public bool? IsMaskSensitiveEnabled { get { throw null; } set { } } + public bool? IsOutputFullPropertiesEnabled { get { throw null; } set { } } public Azure.ResourceManager.Terraform.Models.TargetTerraformProvider? TargetProvider { get { throw null; } set { } } protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.CommonExportProperties System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } @@ -40,9 +40,9 @@ protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer public partial class ExportQueryTerraform : Azure.ResourceManager.Terraform.Models.CommonExportProperties, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel { public ExportQueryTerraform(string query) { } + public bool? IsRecursive { get { throw null; } set { } } public string NamePattern { get { throw null; } set { } } public string Query { get { throw null; } } - public bool? Recursive { get { throw null; } set { } } protected override void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } Azure.ResourceManager.Terraform.Models.ExportQueryTerraform System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs index 0cf237f47b95b..72b56c7b2a602 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/ArmTerraformModelFactory.cs @@ -17,39 +17,39 @@ public static partial class ArmTerraformModelFactory { /// Initializes a new instance of . /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// The name pattern of the Terraform resources. - /// Whether to recursively list child resources of the query result. + /// Whether to recursively list child resources of the query result. /// A new instance for mocking. - public static ExportQueryTerraform ExportQueryTerraform(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string query = null, string namePattern = null, bool? recursive = null) + public static ExportQueryTerraform ExportQueryTerraform(TargetTerraformProvider? targetProvider = null, bool? isOutputFullPropertiesEnabled = null, bool? isMaskSensitiveEnabled = null, string query = null, string namePattern = null, bool? isRecursive = null) { return new ExportQueryTerraform( - Type.ExportQuery, + CommonExportType.ExportQuery, targetProvider, - fullProperties, - maskSensitive, + isOutputFullPropertiesEnabled, + isMaskSensitiveEnabled, serializedAdditionalRawData: null, query, namePattern, - recursive); + isRecursive); } /// Initializes a new instance of . /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. /// A new instance for mocking. - public static ExportResourceGroupTerraform ExportResourceGroupTerraform(TargetTerraformProvider? targetProvider = null, bool? fullProperties = null, bool? maskSensitive = null, string resourceGroupName = null, string namePattern = null) + public static ExportResourceGroupTerraform ExportResourceGroupTerraform(TargetTerraformProvider? targetProvider = null, bool? isOutputFullPropertiesEnabled = null, bool? isMaskSensitiveEnabled = null, string resourceGroupName = null, string namePattern = null) { return new ExportResourceGroupTerraform( - Type.ExportResourceGroup, + CommonExportType.ExportResourceGroup, targetProvider, - fullProperties, - maskSensitive, + isOutputFullPropertiesEnabled, + isMaskSensitiveEnabled, serializedAdditionalRawData: null, resourceGroupName, namePattern); diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs index 449540dc99609..03cdc7db205e9 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.Serialization.cs @@ -41,15 +41,15 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WritePropertyName("targetProvider"u8); writer.WriteStringValue(TargetProvider.Value.ToString()); } - if (Optional.IsDefined(FullProperties)) + if (Optional.IsDefined(IsOutputFullPropertiesEnabled)) { writer.WritePropertyName("fullProperties"u8); - writer.WriteBooleanValue(FullProperties.Value); + writer.WriteBooleanValue(IsOutputFullPropertiesEnabled.Value); } - if (Optional.IsDefined(MaskSensitive)) + if (Optional.IsDefined(IsMaskSensitiveEnabled)) { writer.WritePropertyName("maskSensitive"u8); - writer.WriteBooleanValue(MaskSensitive.Value); + writer.WriteBooleanValue(IsMaskSensitiveEnabled.Value); } if (options.Format != "W" && _serializedAdditionalRawData != null) { diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs index 75265c18d3e5d..54010f3bd17e3 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportProperties.cs @@ -57,25 +57,25 @@ protected CommonExportProperties() /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal CommonExportProperties(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) + internal CommonExportProperties(CommonExportType type, TargetTerraformProvider? targetProvider, bool? isOutputFullPropertiesEnabled, bool? isMaskSensitiveEnabled, IDictionary serializedAdditionalRawData) { Type = type; TargetProvider = targetProvider; - FullProperties = fullProperties; - MaskSensitive = maskSensitive; + IsOutputFullPropertiesEnabled = isOutputFullPropertiesEnabled; + IsMaskSensitiveEnabled = isMaskSensitiveEnabled; _serializedAdditionalRawData = serializedAdditionalRawData; } /// The parameter type. - internal Type Type { get; set; } + internal CommonExportType Type { get; set; } /// The target Azure Terraform Provider. public TargetTerraformProvider? TargetProvider { get; set; } /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - public bool? FullProperties { get; set; } + public bool? IsOutputFullPropertiesEnabled { get; set; } /// Mask sensitive attributes in the Terraform configuration. - public bool? MaskSensitive { get; set; } + public bool? IsMaskSensitiveEnabled { get; set; } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportType.cs similarity index 50% rename from sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs rename to sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportType.cs index 4862340f9945f..e46504cb4119a 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/Type.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/CommonExportType.cs @@ -11,13 +11,13 @@ namespace Azure.ResourceManager.Terraform.Models { /// The parameter type. - internal readonly partial struct Type : IEquatable + internal readonly partial struct CommonExportType : IEquatable { private readonly string _value; - /// Initializes a new instance of . + /// Initializes a new instance of . /// is null. - public Type(string value) + public CommonExportType(string value) { _value = value ?? throw new ArgumentNullException(nameof(value)); } @@ -27,23 +27,23 @@ public Type(string value) private const string ExportQueryValue = "ExportQuery"; /// ExportResource. - public static Type ExportResource { get; } = new Type(ExportResourceValue); + public static CommonExportType ExportResource { get; } = new CommonExportType(ExportResourceValue); /// ExportResourceGroup. - public static Type ExportResourceGroup { get; } = new Type(ExportResourceGroupValue); + public static CommonExportType ExportResourceGroup { get; } = new CommonExportType(ExportResourceGroupValue); /// ExportQuery. - public static Type ExportQuery { get; } = new Type(ExportQueryValue); - /// Determines if two values are the same. - public static bool operator ==(Type left, Type right) => left.Equals(right); - /// Determines if two values are not the same. - public static bool operator !=(Type left, Type right) => !left.Equals(right); - /// Converts a to a . - public static implicit operator Type(string value) => new Type(value); + public static CommonExportType ExportQuery { get; } = new CommonExportType(ExportQueryValue); + /// Determines if two values are the same. + public static bool operator ==(CommonExportType left, CommonExportType right) => left.Equals(right); + /// Determines if two values are not the same. + public static bool operator !=(CommonExportType left, CommonExportType right) => !left.Equals(right); + /// Converts a to a . + public static implicit operator CommonExportType(string value) => new CommonExportType(value); /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object obj) => obj is Type other && Equals(other); + public override bool Equals(object obj) => obj is CommonExportType other && Equals(other); /// - public bool Equals(Type other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + public bool Equals(CommonExportType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs index a039b7a6b9989..78e0755004304 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.Serialization.cs @@ -42,10 +42,10 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri writer.WritePropertyName("namePattern"u8); writer.WriteStringValue(NamePattern); } - if (Optional.IsDefined(Recursive)) + if (Optional.IsDefined(IsRecursive)) { writer.WritePropertyName("recursive"u8); - writer.WriteBooleanValue(Recursive.Value); + writer.WriteBooleanValue(IsRecursive.Value); } } @@ -72,7 +72,7 @@ internal static ExportQueryTerraform DeserializeExportQueryTerraform(JsonElement string query = default; string namePattern = default; bool? recursive = default; - Type type = default; + CommonExportType type = default; TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; @@ -101,7 +101,7 @@ internal static ExportQueryTerraform DeserializeExportQueryTerraform(JsonElement } if (property.NameEquals("type"u8)) { - type = new Type(property.Value.GetString()); + type = new CommonExportType(property.Value.GetString()); continue; } if (property.NameEquals("targetProvider"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs index 7bed96c6f67e2..2d7c71a05d0cb 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportQueryTerraform.cs @@ -21,23 +21,23 @@ public ExportQueryTerraform(string query) Argument.AssertNotNull(query, nameof(query)); Query = query; - Type = Type.ExportQuery; + Type = CommonExportType.ExportQuery; } /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. /// The ARG where predicate. Note that you can combine multiple conditions in one `where` predicate, e.g. `resourceGroup =~ "my-rg" and type =~ "microsoft.network/virtualnetworks"`. /// The name pattern of the Terraform resources. - /// Whether to recursively list child resources of the query result. - internal ExportQueryTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? recursive) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + /// Whether to recursively list child resources of the query result. + internal ExportQueryTerraform(CommonExportType type, TargetTerraformProvider? targetProvider, bool? isOutputFullPropertiesEnabled, bool? isMaskSensitiveEnabled, IDictionary serializedAdditionalRawData, string query, string namePattern, bool? isRecursive) : base(type, targetProvider, isOutputFullPropertiesEnabled, isMaskSensitiveEnabled, serializedAdditionalRawData) { Query = query; NamePattern = namePattern; - Recursive = recursive; + IsRecursive = isRecursive; Type = type; } @@ -51,6 +51,6 @@ internal ExportQueryTerraform() /// The name pattern of the Terraform resources. public string NamePattern { get; set; } /// Whether to recursively list child resources of the query result. - public bool? Recursive { get; set; } + public bool? IsRecursive { get; set; } } } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs index 7f7b8762f493a..427a6a7573866 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.Serialization.cs @@ -66,7 +66,7 @@ internal static ExportResourceGroupTerraform DeserializeExportResourceGroupTerra } string resourceGroupName = default; string namePattern = default; - Type type = default; + CommonExportType type = default; TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; @@ -86,7 +86,7 @@ internal static ExportResourceGroupTerraform DeserializeExportResourceGroupTerra } if (property.NameEquals("type"u8)) { - type = new Type(property.Value.GetString()); + type = new CommonExportType(property.Value.GetString()); continue; } if (property.NameEquals("targetProvider"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs index 056271047470d..85f983fd38c47 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceGroupTerraform.cs @@ -21,18 +21,18 @@ public ExportResourceGroupTerraform(string resourceGroupName) Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); ResourceGroupName = resourceGroupName; - Type = Type.ExportResourceGroup; + Type = CommonExportType.ExportResourceGroup; } /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. /// The name of the resource group to be exported. /// The name pattern of the Terraform resources. - internal ExportResourceGroupTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResourceGroupTerraform(CommonExportType type, TargetTerraformProvider? targetProvider, bool? isOutputFullPropertiesEnabled, bool? isMaskSensitiveEnabled, IDictionary serializedAdditionalRawData, string resourceGroupName, string namePattern) : base(type, targetProvider, isOutputFullPropertiesEnabled, isMaskSensitiveEnabled, serializedAdditionalRawData) { ResourceGroupName = resourceGroupName; NamePattern = namePattern; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs index 2cb99156ba9be..20779d9bdedba 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.Serialization.cs @@ -88,7 +88,7 @@ internal static ExportResourceTerraform DeserializeExportResourceTerraform(JsonE string resourceName = default; string resourceType = default; string namePattern = default; - Type type = default; + CommonExportType type = default; TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; @@ -130,7 +130,7 @@ internal static ExportResourceTerraform DeserializeExportResourceTerraform(JsonE } if (property.NameEquals("type"u8)) { - type = new Type(property.Value.GetString()); + type = new CommonExportType(property.Value.GetString()); continue; } if (property.NameEquals("targetProvider"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs index c384dfe76b2ea..37d65bb28dfd9 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/ExportResourceTerraform.cs @@ -23,20 +23,20 @@ public ExportResourceTerraform(IEnumerable resourceIds) Argument.AssertNotNull(resourceIds, nameof(resourceIds)); ResourceIds = resourceIds.ToList(); - Type = Type.ExportResource; + Type = CommonExportType.ExportResource; } /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. /// The id of the resource to be exported. /// The Terraform resource name. Only works when `resourceIds` contains only one item. /// The Terraform resource type. Only works when `resourceIds` contains only one item. /// The name pattern of the Terraform resources. - internal ExportResourceTerraform(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal ExportResourceTerraform(CommonExportType type, TargetTerraformProvider? targetProvider, bool? isOutputFullPropertiesEnabled, bool? isMaskSensitiveEnabled, IDictionary serializedAdditionalRawData, IList resourceIds, string resourceName, string resourceType, string namePattern) : base(type, targetProvider, isOutputFullPropertiesEnabled, isMaskSensitiveEnabled, serializedAdditionalRawData) { ResourceIds = resourceIds; ResourceName = resourceName; diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs index 2fcaae5bb5923..0d73067c1f588 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.Serialization.cs @@ -57,7 +57,7 @@ internal static UnknownCommonExportProperties DeserializeUnknownCommonExportProp { return null; } - Type type = "Unknown"; + CommonExportType type = "Unknown"; TargetTerraformProvider? targetProvider = default; bool? fullProperties = default; bool? maskSensitive = default; @@ -67,7 +67,7 @@ internal static UnknownCommonExportProperties DeserializeUnknownCommonExportProp { if (property.NameEquals("type"u8)) { - type = new Type(property.Value.GetString()); + type = new CommonExportType(property.Value.GetString()); continue; } if (property.NameEquals("targetProvider"u8)) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs index 7ed3b508eba25..1da2d03b3b7f6 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs +++ b/sdk/terraform/Azure.ResourceManager.Terraform/src/Generated/Models/UnknownCommonExportProperties.cs @@ -16,10 +16,10 @@ internal partial class UnknownCommonExportProperties : CommonExportProperties /// Initializes a new instance of . /// The parameter type. /// The target Azure Terraform Provider. - /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. - /// Mask sensitive attributes in the Terraform configuration. + /// Whether to output all non-computed properties in the generated Terraform configuration? This probably needs manual modifications to make it valid. + /// Mask sensitive attributes in the Terraform configuration. /// Keeps track of any properties unknown to the library. - internal UnknownCommonExportProperties(Type type, TargetTerraformProvider? targetProvider, bool? fullProperties, bool? maskSensitive, IDictionary serializedAdditionalRawData) : base(type, targetProvider, fullProperties, maskSensitive, serializedAdditionalRawData) + internal UnknownCommonExportProperties(CommonExportType type, TargetTerraformProvider? targetProvider, bool? isOutputFullPropertiesEnabled, bool? isMaskSensitiveEnabled, IDictionary serializedAdditionalRawData) : base(type, targetProvider, isOutputFullPropertiesEnabled, isMaskSensitiveEnabled, serializedAdditionalRawData) { Type = type; } diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index 54a1b15e31196..d4fa1e3940737 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: 637adebd6042eab6c721be8eda4ff3f5d4d0c2b8 +commit: 0756ab6749f87d935a6a0c497523fa021a4a55e3 repo: Azure/azure-rest-api-specs From 240bf6d2db8fd9514243478bc97071cfab201d24 Mon Sep 17 00:00:00 2001 From: Arthur Ma Date: Tue, 29 Oct 2024 11:19:42 +0800 Subject: [PATCH 32/33] update --- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index d4fa1e3940737..af0d6128de9f5 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: 0756ab6749f87d935a6a0c497523fa021a4a55e3 +commit: f0f1de59d208c0955fbb4a19d2186c82bd3b2cae repo: Azure/azure-rest-api-specs From 37cb0c3060a1650129e80e7473eba59105e6d343 Mon Sep 17 00:00:00 2001 From: Arthur Ma Date: Thu, 31 Oct 2024 12:01:30 +0800 Subject: [PATCH 33/33] Update changelog --- sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md | 2 +- sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md index a97f1297b3fbe..da00c15054249 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md +++ b/sdk/terraform/Azure.ResourceManager.Terraform/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0-beta.1 (Unreleased) +## 1.0.0-beta.1 (2024-10-31) ### Features Added diff --git a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml index af0d6128de9f5..d676e0dde7f99 100644 --- a/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml +++ b/sdk/terraform/Azure.ResourceManager.Terraform/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/terraform/Microsoft.AzureTerraform.Management -commit: f0f1de59d208c0955fbb4a19d2186c82bd3b2cae +commit: a4fc4c6bda9ff2315671bca69f9de40a43e2bd8c repo: Azure/azure-rest-api-specs