-
Notifications
You must be signed in to change notification settings - Fork 301
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
azuread_application resource: appRoles are created multiple times #308
Comments
I see this issue has the If this is an upstream problem: do we have an issue at the terraform repository that I can go and vote on? Thanks! |
Hi @daniel-chambers, @dimbleby, sorry for the delay in responding. Whilst the upstream-label is technically appropriate, it isn't going to aid us in the short term and since this issue was opened we have narrowed down a bunch of related issues with plans to remediate. That said... I believe the root cause here is a lack of consistency with the AAD Graph API. As you correctly noted, we perform a blanket disabling of all roles before patching any role updates, and this behavior is baked into the create and update funcs. The reason we do this is because it's infeasible to identity roles reliably in order to selectively disable them before updating. The error you are getting is due to API consistency (or lack of), where roles are disabled but the API doesn't actually reflect that (either in the update or read direction) by the time the provider code tries to subsequently update them. The long version is that roles are identified by their In good news, I believe your issue will be eliminated by using the Furthermore, these sorts of consistency issues are greatly reduced in the Microsoft Graph API, which we are in the process of moving to, and we have plans to try to improve exactly this situation in the event that consistency errors occur. These constitute a breaking changes, so will only land in the next major provider version. Hope this clarifies the predicament we have with this, and note that all of the above issues and consequences apply to both app roles and oauth2 permission scopes. Unfortunately there isn't much more we can do to resolve this bug until we've migrated to MS Graph or the next major version - and both of those are scheduled to happen at the same time. I'll happily keep this issue open so that we can track this particular error, and ensure we have mitigated it when that happens. |
Thanks for the update. My terraform definitions actually currently do use the
... and I am hitting the same error. Actually, before you made the above update, I decided to try experimenting with inlining these as |
@dimbleby Sorry for the delay in replying! Actually on balance, for the suspected root cause of API inconsistency, due to our current implementation it's possible you may encounter this error with both the Apologies for the inconvenience this causes, and that we can't get a fix out right away, but as promised we are actively working on an improved solution in v2.0. |
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. |
Community Note
Terraform (and AzureAD Provider) Version
Terraform v0.12.28 (Yes, this is older than 0.13, but I believe the issue is in this provider, not in Terraform itself)
provider.azuread v0.11.0
provider.azurerm v2.23.0
Affected Resource(s)
azuread_application
Terraform Configuration Files
Debug Output
If you don't mind I've encrypted the debug logs (which contain stuff like our subscription ID etc and a lot of stuff I don't understand and don't want to try to sanitise) to the Hashicorp keybase user.
tflog.log.gz.encrypted.saltpack.zip
The error at the end is:
Panic Output
None
Expected Behavior
The appRoles should be created once, and I should never experience the above error.
Actual Behavior
During resource creation, the appRoles are created (PATCH-ed onto the app), then they are disabled (PATCH-ed into
isEnabled: false
). Then they are deleted and replaced with new copies (new appRoles with new IDs are PATCH-ed onto the app).Then, sometimes (not always) I experience a
Property value cannot be deleted or updated unless it is disabled first.
error. This looks like a dodgy error and behaviour from Azure AD, however I think it may be being exacerbated by the fact that we delete and recreate app roles close together while creating an app (they fact that this occurs only sometimes makes this feel like a race condition and Azure AD is full of frustrating eventual consistency).I've had a poke through the provider code, and I believe we:
resourceApplicationCreate
: https://github.com/terraform-providers/terraform-provider-azuread/blob/3892ca120ee9dcc6d63fabcc124306cebea019e7/azuread/resource_application.go#L389-L399resourceApplicationUpdate
at the end ofresourceApplicationCreate
. Inside this function, we patch the the appRoles disabled here: https://github.com/terraform-providers/terraform-provider-azuread/blob/3892ca120ee9dcc6d63fabcc124306cebea019e7/azuread/resource_application.go#L516-L519 (this appears to be because the ResourceData still thinks there are no appRoles, even though we previously created them, so HasChanges must be returning true)Seems to me like we could just delete the code that is creating the app roles inside
resourceApplicationCreate
and leave it toresourceApplicationUpdate
to create them?I'm not certain that this is the thing that's causing the above error, but I believe only the oauth2Permissions and the appRoles have this sort "disable before deleting" error, and it seems reasonable that we should only create appRoles once during application creation.
Steps to Reproduce
terraform apply
If the bug does not happen, you may need to repeat the following steps as quickly as you can:
2.
terraform destroy
3.
terraform apply
Eventually, it happens.
The text was updated successfully, but these errors were encountered: