-
Notifications
You must be signed in to change notification settings - Fork 139
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
Attributes aren't refreshed if no attributes of that type exist in local state #629
Comments
Hi @jonnangle Thanks for opening this issue. With regards to...
Yes, this logic was intentional, see the following PR for more details: If you're reverting to an older service version via the UI, then you're working outside of Terraform and that can cause problems because Terraform expects to manage the entire lifecycle of resources. One option to get the refresh to work would be to do a reimport of the service after it has been reverted via the UI: terraform import fastly_service_vcl.cache-setting-test <SERVICE_ID> As this will cause the |
Thanks for the quick reply @Integralist!
I see what you mean, but the Terraform docs suggest that refreshing infrastructure state is a pretty core aspect of the tool - there's an implicit refresh before It's not unusual to have to make changes to services outside of terraform during incidents, where you may not be able to wait for a CI pipeline to run. We've even had occasions where Fastly support have made changes to services on our behalf. Also, we've bumped into problems with this even when working completely within terraform. For example, in the example above, if you remove the resource "fastly_service_vcl" "cache-setting-test" {
name = "cache-setting-test"
domain {
name = "cache-setting-test.example.com"
}
snippet {
name = "Only cache /render responses"
type = "fetch"
priority = 10
content = <<-EOT
if ( beresp.status != 200 || req.url !~ "^/render" ) {
return(pass);
}
EOT
}
} then it will fail with this error:
But you'll find that you have a terraform state that now has an empty
even though the cache setting still exists on the live service on Fastly. |
Hi @jonnangle Thanks for the reply and extra context, I appreciate you taking the time to provide this information. Re:
That's understandable. Re:
Thank you! I'll investigate further 👍🏻 With regards to the main issue reported, I'll have think about how we can handle this situation. My initial thinking says maybe within the service resource's read function we can make an API call to get the currently 'active' service version. That way if it doesn't match what the currently tracked version is within the provider, then we might be able to update the state with a new internal attribute that ensures the API call for each resource is executed. A similar approach might be that we provide an explicit attribute to force API reads, that would be less implementation code for us and would be a simple extra line of code in your configuration for those times when you want to get a full refresh. |
Hi @Integralist - sounds great, thanks! I like the idea of checking the service version, hopefully that would allow the provider to detect all of these situations in a reliable way whilst still keeping the performance optimizations in place on the happy path. |
@jonnangle just for your reference: |
Also, I've replicated the issue reported with regard to missing state values when there is an error but it's currently unclear to me how this bug is possible. When running an apply with There's no reported call into the cache_setting resource (nor any API call for it made), so why Terraform deletes the cache_setting resource from the state is unclear to me as the provider shouldn't have reached that step once the error occurred. I'll keep digging to see if I can make sense of this. |
re:
I'm going to open a separate issue for this as it's actually unrelated. UPDATE: #631 |
Terraform Version
Terraform v1.3.3
on darwin_arm64
Affected Resource(s)
Terraform Configuration Files
It appears that most of the attribute handlers intentionally avoid refreshing if the local state has no attributes of that type - for example:
https://github.com/fastly/terraform-provider-fastly/blob/main/fastly/block_fastly_service_cachesetting.go#L90-L93
This can cause problems if the local state has become out of sync - e.g. if the service has been rolled back. Is this intentional?
Expected Behavior
A terraform refresh should update the local state with the complete current state of the Fastly service.
Actual Behavior
A terraform refresh does not pick up attributes from the service if there are no attributes of that type already existing in the local state.
Steps to Reproduce
cache_setting
attribute block andterraform apply
, creating v2 of the serviceterraform apply
again - it will now report that no changes are needed, and so will not remove thecache_setting
attribute. Runningterraform refresh
does not help.The text was updated successfully, but these errors were encountered: