hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

Make eventually-consistent resources poll on create/update #4993

Open spew opened 4 years ago

spew commented 4 years ago

Description

After a successful CREATE or UPDATE the terraform provider immediately does a GET on the same resource. This creates problems when the resource is eventually consistent as the GET may fetch the old state. Especially so for UPDATEs. Many services which have eventually consistent resources, return a copy of the resource in the response. Rather than GET the resource, the provider could use the response to alleviate some of the issues.

New or Affected Resource(s)

google__iampolicy google_iam_member google_pubsub_subscription

References

chrisst commented 4 years ago

@spew do you have a good example to repro this or a debug log from when this was causing a diff it shouldn't have? I played around with a couple of the resources you noted but haven't seen one where the update succeed but resulted in the state being set incorrectly.

rileykarson commented 4 years ago

https://gist.github.com/kibbles-n-bytes/3d2bb8a76c856354f65ff50cfc72cc44 is a terraform-less repro of the pubsub one

spew commented 4 years ago

It's eventually consistent so you won't expect to see it often -- I'd say it happens 1/50 times or so for iam_service_account (which isn't listed). Not sure about frequency of policy.

spew commented 4 years ago

Yes, the pubsub example is better.

chrisst commented 4 years ago

I think this would require changing these resources to no longer call into Read after create/update in order to accomplish this. Naturally any subsequent refresh phase will still call into read so it can't completely solve the issue. We could alternatively add polling for transitions of individual field values to ensure that an update has fully succeeded, but that would require a medium sized overhaul of the resource as well.

Given that the behavior of state setting in the future is still in question (see https://github.com/terraform-providers/terraform-provider-google/issues/4328) I won't be taking this on right now.

emilymye commented 4 years ago

https://github.com/GoogleCloudPlatform/magic-modules/pull/3155 added the ability to poll post create/update for PubSub and generic utils. We've moved this this near-term goals so we can track adding additional polling in other resources as we find them.