You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unable to change user_metadata on users associated with a google-oauth2 connection.
I have a Google OAuth2 connection defined by the following resource:
and a user that has been created outside of Terraform context (since Management API does not support creating users with this connection). Once the user has been created I import it into Terraform state, and wish to apply common set of user attributes:
resource "auth0_user" "users" {
for_each = { for user in local.admins : user.email => user }
email = each.key
email_verified = true
connection_name = auth0_connection.google.name
family_name = each.value.last_name
given_name = each.value.first_name
name = "${each.value.first_name} ${each.value.last_name}"
nickname = each.value.nickname
user_metadata = jsonencode(
{
some_key = "value"
}
)
}
Terraform plan makes sense:
# module.auth0.auth0_user.users["[email protected]"] will be updated in-place
~ resource "auth0_user" "users" {
id = "google-oauth2|..."
name = "My Name"
+ user_metadata = jsonencode(
{
+ some_key = "value"
}
)
# (12 unchanged attributes hidden)
}
but apply still fails with:
Error: 400 Bad Request: The following user attributes cannot be updated: family_name, given_name, name, nickname. The connection (prod-google-oauth2) must either be a database connection (using the Auth0 store), a passwordless connection (email or sms) or has disabled 'Sync user profile attributes at each login'. For more information, see https://auth0.com/docs/dashboard/guides/connections/configure-connection-sync
As you can see, plan does not change any of the mentioned attributes. If I add:
lifecycle {
ignore_changes = [
user_metadata
]
}
to auth0_user.users, the plan goes through but this beats the purpose of me using Terraform for Auth0 users in this case.
Expectation
Plan application to succeed and user_metadata to be updated.
After a bit of digging it seems the issue is not with the user_metadata property but with the fact that we're trying to always push an update to the API with name, given_name, family_name and nickname within the payload.
As a tip if you want to keep those attributes managed by your identity provider (google in this case) I'd suggest removing them from the terraform configuration block to prevent issues such as the one above.
Checklist
Description
Unable to change
user_metadata
on users associated with a google-oauth2 connection.I have a Google OAuth2 connection defined by the following resource:
and a user that has been created outside of Terraform context (since Management API does not support creating users with this connection). Once the user has been created I import it into Terraform state, and wish to apply common set of user attributes:
Terraform plan makes sense:
but apply still fails with:
As you can see, plan does not change any of the mentioned attributes. If I add:
to
auth0_user.users
, the plan goes through but this beats the purpose of me using Terraform for Auth0 users in this case.Expectation
Plan application to succeed and user_metadata to be updated.
Reproduction
Here's a close-to-minimal repro:
This should apply cleanly.
User goes to the app, logs in with Google in order to create a User object in Auth0.
Import the user:
Then, to add user metadata, change
local.admins
:Plan can be computed, by applying will fail due to mentioned error.
Auth0 Terraform Provider version
0.34, 0.40
Terraform version
v1.2.4
The text was updated successfully, but these errors were encountered: