Skip to content
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

Closed

Conversation

shelleybess
Copy link
Contributor

@shelleybess shelleybess commented Aug 3, 2018

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)

Copy link
Collaborator

@katbyte katbyte left a 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 and testCheckAzureRMRoleDefinitionDestroy 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())
Copy link
Collaborator

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?

Copy link
Contributor Author

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>"

Copy link
Collaborator

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()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@katbyte
Copy link
Collaborator

katbyte commented Aug 3, 2018

Running the tests i believe you will need to update the logic as these three are failing:

------- Stdout: -------
=== RUN   TestAccAzureRMRoleDefinition_basic
--- FAIL: TestAccAzureRMRoleDefinition_basic (11.48s)
	testing.go:513: Step 0 error: Check failed: Check 1/1 error: Bad: Role Definition "azurerm_role_definition.test" (Scope: "/subscriptions/*******") does not exist
FAIL

------- Stdout: -------
=== RUN   TestAccAzureRMRoleDefinition_complete
--- FAIL: TestAccAzureRMRoleDefinition_complete (12.05s)
	testing.go:513: Step 0 error: Check failed: Check 1/1 error: Bad: Role Definition "azurerm_role_definition.test" (Scope: "/subscriptions/*******") does not exist
FAIL

------- Stdout: -------
=== RUN   TestAccAzureRMRoleDefinition_update
--- FAIL: TestAccAzureRMRoleDefinition_update (11.43s)
	testing.go:513: Step 0 error: Check failed: Check 1/5 error: Bad: Role Definition "azurerm_role_definition.test" (Scope: "/subscriptions/*******") does not exist
FAIL

@shelleybess
Copy link
Contributor Author

I'll take a look at the tests since this may be because the tests are using the old logic.

@shelleybess
Copy link
Contributor Author

@katbyte Thank you for reviewing!

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shelleybess,

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.

@tombuildsstuff
Copy link
Contributor

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!

@ghost
Copy link

ghost commented Mar 6, 2019

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!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot update or delete an azurerm_role_definition
3 participants