-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify Update and Delete azurerm_role_definition #1724
Modify Update and Delete azurerm_role_definition #1724
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shelleybess,
Thank you for opening this PR, I have two comments:
- Is there a reason not to use
parseAzureResourceID()
here? - do the test functions
testCheckAzureRMRoleDefinitionExists
andtestCheckAzureRMRoleDefinitionDestroy
need to be updated with the new logic?
Look forward to getting this merged once those comments are addressed 🙂
@@ -82,8 +83,8 @@ func resourceArmRoleDefinitionCreateUpdate(d *schema.ResourceData, meta interfac | |||
client := meta.(*ArmClient).roleDefinitionsClient | |||
ctx := meta.(*ArmClient).StopContext | |||
|
|||
roleDefinitionId := d.Get("role_definition_id").(string) | |||
if roleDefinitionId == "" { | |||
roleDefinitionId := filepath.Base(d.Id()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to not use parseAzureResourceID()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this route because I encountered an issue parsing the role definition Ids. They do not contain a resource group and parseAzureResourceID()
makes assumptions about the structure of the URLs.
[ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
* azurerm_role_definition.shelley-dev: Error retrieving resource Id for resource "/subscriptions/<subscription_ID>/providers/Microsoft.Authorization/roleDefinitions/<role_def_id>": No resource group name found in: "subscriptions/<subscription_id>/providers/Microsoft.Authorization/roleDefinitions/<role_def_id>"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, sounds good to me.
scope := d.Get("scope").(string) | ||
|
||
resp, err := client.Delete(ctx, scope, roleDefinitionId) | ||
resp, err := client.Delete(ctx, scope, filepath.Base(d.Id())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
Running the tests i believe you will need to update the logic as these three are failing:
|
I'll take a look at the tests since this may be because the tests are using the old logic. |
@katbyte Thank you for reviewing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates! Everything looks good to me except just one test is failing now:
------- Stdout: -------
=== RUN TestAccAzureRMRoleDefinition_update
--- FAIL: TestAccAzureRMRoleDefinition_update (30.67s)
testing.go:513: Step 1 error: Check failed: Check 5/6 error: azurerm_role_definition.test: Attribute 'permissions.0.not_actions.#' expected "1", got "0"
FAIL
I updated the other tests to check (i hope you don't mind) and they pass, it seems to only be an issue for the update.
hey @shelleybess Thanks for this PR - apologies for the delayed movement here. I hope you don't mind but we've ended up taking a (similar) but slightly different approach in #1887 which I'm going to close this PR in favour of. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
This pull request addresses the issue described in #1540 where the azurerm_role_definition was unable to be updated or deleted.
Changes to Delete:
Changes have been made to get the path of the resource and pull the id from the end.
Changes to CreateOrUpdate:
Now retrieves the id from the end of the path if it exists or generates one if the resource path is empty.
(fixes #1540)