ResourceModules icon indicating copy to clipboard operation
ResourceModules copied to clipboard

[Bug Report]: resources/resource-group - ResourceGroupManagedByMismatch

Open coolhome opened this issue 3 years ago • 9 comments

Describe the bug

Azure defaults ResourceGroup.managedBy as null but the ResourceModule template defaults to empty string. It is also not possible to set null with this module.

image

If I check if empty and send null then I get another error:

InvalidTemplate - Long running operation failed with status 'Failed'.
     | Additional Info:'Deployment template validation failed: 'The template
     | resource 'RG-Workday' at line '1' and column '2529' is not valid:
     | Evaluation result of language expression
     | '[if(empty(parameters('managedBy')), null(), parameters('managedBy'))]'
     | is type 'Null', expected type is 'String'.. Please see
     | https://aka.ms/arm-functions for usage details.'.

To reproduce

  1. Create a resource group through azure portal
  2. Create bicep for this resource group
module ResourceGroup '.carml/resources/resource-groups/main.bicep' = {
  name: '${deployment().name}-ResourceGroup'
  params: {
    name: resourceGroupName
    location: resourceGroupLocation
  }
}
  1. Deploy Bicep
The managed by property of the resource group cannot be changed from its current value '<null>'

Code snippet

No response

Relevant log output

{
  "code": "DeploymentFailed",
  "target": "/subscriptions/***",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
  "details": [
    {
      "code": "ResourceGroupManagedByMismatch",
      "message": "The managed by property of the resource group cannot be changed from its current value '<null>'."
    }
  ]
}

coolhome avatar Jun 29 '23 21:06 coolhome

This also happens to any Resource Group deployed using CARML modules with v <= 0.8.0, when trying to deploy again the same BICEP with CARML v >= 0.9.0: the deployment will fail.

The PR that introduced the managedBy parameter is https://github.com/Azure/ResourceModules/pull/2319 which was also erroneously marked as non-breaking change.. but as stated this breaks any existing deployment.

zydio avatar Jul 25 '23 15:07 zydio

Any news on this?

adnkai avatar Aug 29 '23 07:08 adnkai

I wonder if we should report this as a Resource Provider bug because I think the value should always be an immutable string. Alternatively, maybe there should be a ManagedResourceGroup module that separates this functionality out.

If you consume this module, I suggest removing the managedBy param.

coolhome avatar Sep 11 '23 16:09 coolhome

I wonder if we should report this as a Resource Provider bug because I think the value should always be an immutable string. Alternatively, maybe there should be a ManagedResourceGroup module that separates this functionality out.

If you consume this module, I suggest removing the managedBy param.

I believe anyone using the module has been removing the managedBy param but this is a (painful) temporary workaround because it forces us to not use the stock modules: a proper fix should be available in CARML.

zydio avatar Sep 12 '23 06:09 zydio

While I recallr reading the original issue, I didn't get around looking deeper into this. Sorry everybody, and thanks @coolhome to give it a shot. I just notified the module owner to take a look so that it's also included in AVM, and further commented on the PR. I'd hope that nullable helps us out.

AlexanderSehr avatar Dec 10 '23 21:12 AlexanderSehr

Anyone know of a way to fix this without redeploying the Resource Group? I have a bunch of Resource Groups that have this issue.

russellds avatar May 29 '24 19:05 russellds

Anyone know of a way to fix this without redeploying the Resource Group? I have a bunch of Resource Groups that have this issue.

That's a tough one. From the top of my head it would only come to mind to deploy 'new' resource groups and migrate all existing resources to those resource groups. :-/

AlexanderSehr avatar Jun 01 '24 14:06 AlexanderSehr

Similar to @russellds ... in our case we updated core RG's some time ago and we have now discovered this issue, recreate is not an option so I assume it's now a 'live with it' or can Msft do anything on the backend?

AengusMo avatar Jun 06 '24 09:06 AengusMo

Hey @AengusMo, for that I'd ask you to open a support ticket, as we don't have access to the backend - yet alone a customer's backend. :-/

AlexanderSehr avatar Jun 06 '24 17:06 AlexanderSehr