-
Notifications
You must be signed in to change notification settings - Fork 77
Conversation
@joshua-rutherford apologies for what may seem like a silly thing (I have not looked at this side of the code for a little while). The idea iirc is that if the user already exists we update the existing user. It should not be importing a new resource, just update an existing user. I do want the provider to be authoritative meaning that if you define a user and it already exists terraform shouldn't error out, but instead overwrite existing values. Perhaps there's a better way to do this..? |
Normally if you wish to bring an existing entity in the remote system under configuration control as a terraform resource you must Your resource already supports the
And import it with the following:
The next time I run Now that I have their accounts defined in a terraform module I can check it into the git repo and allow them to make changes there with my approval because they should be able to reset the recovery email but not their email address. I have to admit the idea that create would also import is intriguing but not really a pattern I've ever seen in terraform. |
I understand from the viewpoint of import, but if you do not do an import first you end up with the provider not becoming authoritative, meaning that if you have users today and you define them in terraform without importing, the provider would have to return an "already exists error". The pattern of the provider being more authoritative and returning less errors is fairly new but one that is becoming more and more prevalent. I think if the issue here is that we somehow end up with multiple resources managing the same primary_email, that should be (made) impossible- I'm not sure how removing the read and update for existing resources (i.e. import and overwrite existing on create) helps with this? |
I'm really just trying to prevent myself from locking existing users out of their account and provide enough feed back to administrators that they've got a bad configuration defined. Like I said, you already have support for import so I guess I can make do with out this but the cost of always assuming that terraform is right is that you always assume administrators are correct in the way they define their resources. At some point they will collide (see #118) and you have no way of knowing that with this module as the resource will simply flap. |
I do think that should be the policy of this provider: whatever is in terraform is leading. In your plan you should be able to see the current user that you may be overwriting. I don't entirely see how this would prevent #118 from happening either, a bad config (having the same primary_email twice and letting terraform flap between them) is not fixed by removing the import logic AFAICT. |
I agree that if a person reviews the plan they will see there is something strange about to happen (i.e., I added a new user and it wants to change an existing user instead of creating a new one). However, that has two drawbacks in my mind:
That aside, the fix to #118 is that new resources in my local state only ever call |
I'm thinking that if you are running this in an automated way and you want it to error out, we add a field for specifically enabling that, e.g. |
That would suit my needs fine. Can I make it global or do you want it per resource? |
@joshua-rutherford I suspect we should probably do both. We can set a default using a global parameter but override it per resource. Thoughts? |
Will cut a new release of the provider after this one is updated/merged. |
6cc514b
to
e8776bf
Compare
e8776bf
to
e19ed2b
Compare
Added a provider configuration and resource configuration for |
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.
👍 looks great, glad we found a solution that works for all use cases we could come up with!
@DeviaVir, fairly straight forward change to prevent the same user getting imported as multiple terraform resources by accident. This does change the behavior on initial creations (i.e., no longer imports so you'll have to explicitly import existing users).