I am trying to programmatically add tags to resources in Azure Government. When I try to set the tags on a resource that has no tags I am using the Set-AzureRmResource command. I have tried both setting the ApiVersion and without (without is supposed to use the latest) When I use the Debug flag it shows the version being set but I still get an error below.
Set-AzureRmResource : Cannot validate argument on parameter 'ResourceId'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:1 char:108
+ ... ONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-AzureRmResource], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implem
entation.SetAzureResourceCmdlet
The snippet I am trying to run is below.
Set-AzureRmResource -Tag @{ ENVIRONMENT=""; ORGANIZATION="" } -ResourceId $resource.ResourceId -Force
Edit: Specify Azure Government Edit 2: Removed explicit version setting from code
For anyone who sees this in the future. The problem is a known bug in the way Azure encodes the '#' symbol in a ResourceId. So do not use '#' in a resource string.
The code change we are making is to use the following:
$resource.ResourceId = $resource.ResourceId.Replace("#", "%23")
Simple fix if you have the # symbol, or change your governance to not name things with '#'.
Thanks for all the other replies. We had to open a ticket to get this information.