Skip to content

[Bug] ArmCollection for Nested Resource assumes parent RP namespace is the same as the direct parent (extension resource) #2921

@brrusino

Description

@brrusino

Describe the issue or request
Our resource provider exposes a nested resource off of an extension resource: Microsoft.Chaos/targets/capabilities. Our target extension resource extends various Azure resources that we don't own. With the new Azure.ResourceManager.Chaos dotnet SDK, we noticed that CapabilityCollection assumes that the top level resource namespace is the same as the direct parent namespace, resulting in an incorrect URL generated.

Sample generated code from CapabilityCollection.cs:

        public virtual async Task<ArmOperation<CapabilityResource>> CreateOrUpdateAsync(WaitUntil waitUntil, string capabilityName, CapabilityData data, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNullOrEmpty(capabilityName, nameof(capabilityName));
            Argument.AssertNotNull(data, nameof(data));

            using var scope = _capabilityClientDiagnostics.CreateScope("CapabilityCollection.CreateOrUpdate");
            scope.Start();
            try
            {
                var response = await _capabilityRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.ResourceType.Namespace, Id.Parent.ResourceType.GetLastType(), Id.Parent.Name, Id.Name, capabilityName, data, cancellationToken).ConfigureAwait(false);
                var operation = new ChaosArmOperation<CapabilityResource>(Response.FromValue(new CapabilityResource(Client, response), response.GetRawResponse()));
                if (waitUntil == WaitUntil.Completed)
                    await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                return operation;
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }

Expected resource id in request:
/subscriptions/fb74b135-894b-4c1d-9b2e-8a3c231abc14/resourceGroups/rg-chaos-sdk-test-recording/providers/Microsoft.Compute/virtualMachineScaleSets/chaossdk-vmss-eastus-0/providers/Microsoft.Chaos/targets/Microsoft-VirtualMachineScaleSet/capabilities/Microsoft-VirtualMachineScaleSet/Shutdown-2.0?api-version=2022-10-01-preview

Actual resource id in request:
/subscriptions/fb74b135-894b-4c1d-9b2e-8a3c231abc14/resourceGroups/rg-chaos-sdk-test-recording/providers/Microsoft.Chaos/virtualMachineScaleSets/chaossdk-vmss-eastus-0/providers/Microsoft.Chaos/targets/Microsoft-VirtualMachineScaleSet/capabilities/Microsoft-VirtualMachineScaleSet/Shutdown-2.0?api-version=2022-10-01-preview

Describe your ideas for solutions
Parse out the top-level resource information inside the ArmCollection base class, saving to a ParentId variable if two providers are present inside the id:

        protected ArmCollection(ArmClient client, ResourceIdentifier id)
        {
            Argument.AssertNotNull(id, nameof(id));
            Argument.AssertNotNull(client, nameof(client));

            Client = client;
            Id = id;
            ParentId = TryParseParentId(id); // returns null if id does not contain two providers
        }

Metadata

Metadata

Assignees

Labels

MgmtThis issue is related to a management-plane library.v3Version 3 of AutoRest C# generator.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions