Open scratch85 opened 3 months ago
Can confirm your report in the debugger @scratch85, screenshot attached. Good find 👍
However, if roleDefinitionID.RoleID
was assignable to either idParts that would make the format of the role assignment resource in tfstate variable, i.e. inconsistent. Gut instinct says the RoleDefinitionId
parser method should be made stricter; or the SchemaValidateFunc of the resource itself. Will take a pass at fixing and adding a test.
Is there an existing issue for this?
Community Note
Description
Import role definitions into tfstate requires to give an id + scope (see current docs).
According to the note, the Id consists is
{roleDefinitionId}|{scope}
. Azure Portal and other tools just return a UUID as roleDefinitionId.This lead me to use the import like this (for a tenant level role definition):
this will lead to uncaught error:
role_definition.go is not printing a proper error message if the split string got an invalid "roleDefinitionId" missing the keyword "roleDefinitions/".
This is the split: https://github.com/hashicorp/terraform-provider-azurerm/blob/1aef7c1bc3e8afa3a15a1091ae2dd4c823e816ed/internal/services/authorization/parse/role_definition.go#L52
The error from above is thrown, because "idParts" has a length of 1 only, and the check is valid for 0 elements only (<1). As it is 1, the else is causing trouble as idParts[1] is out of bounds. https://github.com/hashicorp/terraform-provider-azurerm/blob/1aef7c1bc3e8afa3a15a1091ae2dd4c823e816ed/internal/services/authorization/parse/role_definition.go#L63-L67
Maybe the code can be changed to something like this:
or
or
New or Affected Resource(s)/Data Source(s)
azurerm_role_definition
Potential Terraform Configuration
References
No response