aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
235 stars 77 forks source link

ResourceRecordSet object always has a `weight` property even when Weighted Routing is not enabled #344

Open appleoddity opened 3 months ago

appleoddity commented 3 months ago

Describe the bug

When I call the Get-R53ResourceRecordSet function for a hosted zone it returns a collection of ResourceRecordSet. The value of the weight property is 0 even when there is no Weighted Routing policy applied. In contrast, the documentation indicates that the weight property only applies to weighted resource record sets only. For this reason, it is impossible to determine if the exported resource is supposed to have a weighted routing policy or not.

I am using Powershell 7.

Expected Behavior

Similar to the aws cli, I expect the weight property to be null or undefined when the record does not have a weighted routing policy applied.

Current Behavior

The weight property is 0 even when no weighted routing policy is enabled. A value of 0 has special meaning and this created ambiguity. I assume because the weight property is typed to Int64 .NET is converting a null value to 0.

Reproduction Steps

(Get-R53ResourceRecordSet -HostedZoneId $zone.Id -MaxItem 1000).ResourceRecordSets

Observe the weight property on the exported resource records.

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWS Tools for PowerShell Version 4.1.547 Copyright 2012-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Amazon Web Services SDK for .NET Core Runtime Version 3.7.303.4 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Targeted .NET Platform

.NET Core

Operating System and version

Ubuntu w/ Powershell 7

ashishdhingra commented 2 months ago

@appleoddity Good morning. Thanks for reporting the issue. AWS Tools for PowerShell uses AWS .NET SDK behind the scenes. Looking at the property definition for Weight, even though it has the Nullable backing field, the getter for this property is using this._weight.GetValueOrDefault() which returns value 0 for null weight.

This is a breaking change for current version of SDK. Also, the property definition in this case is generated from service models. There is a similar issue https://github.com/aws/aws-sdk-net/issues/1721#issuecomment-702969647 in our backlog to be queued for fix in the next version of AWS .NET SDK.

CCing @normj for visibility.

Thanks, Ashish

ashishdhingra commented 2 months ago

@appleoddity In case you are blocked by this issue, we could do a customization to expose public Is<Property>Set property (e.g. IsWeightSet) in AWS .NET SDK, which you could then use in PowerShell CmdLet response to check if property is set. This is not a clean workaround, however, this is something which could be fully fixed only in next major version of SDK. Please advise.

Thanks, Ashish

appleoddity commented 2 months ago

Thank you for the fast response and explanation. If it's in the backlog, I will wait until the next release. I went ahead and worked around the problem now, because I didn't actually have any weighted records. The only thing I want to point out is I believe TTL has the same problem. If the record is an alias, there is no TTL value, yet it exports as 0. I'm assuming it is null behind the scenes.