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
Some data sources can be slightly more expensive to fetch than others and do not change often or only under specific predictable circumstances. Terraform is doing quite a lot of refreshing of data sources, which is fine for smaller data sources, but can be slow and wasteful for heavier ones. It would be great if providers could check whether a data source needs to be actually fetched.
Attempted Solutions
I would expect that a provider could on every read check whether the data needs refetching, using (computed) attributes from a previous run. However, Terraform seems to always reset the ResourceData on every refresh.
funcdataSourceHeavyRead(d*schema.ResourceData, minterface{}) error {
ifneedsUpdate(d.Get("last_update")) {
// Only fetch if data is out of sync...lastUpdate:=...d.Set("last_update", lastUpdate)
}
returnnil
}
This does not work, because last_update gets reset by Terraform on every read.
Proposal
My proposal would be to not reset the data source attributes on every read. That way, providers have the option to look at the previous state and decide for themselves whether to refetch the data or not.
I don't see how this change could have an impact on existing providers, because they override the attributes on every read anyway.
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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
ghost
locked and limited conversation to collaborators
Feb 26, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Current Terraform Version
Use-cases
Some data sources can be slightly more expensive to fetch than others and do not change often or only under specific predictable circumstances. Terraform is doing quite a lot of refreshing of data sources, which is fine for smaller data sources, but can be slow and wasteful for heavier ones. It would be great if providers could check whether a data source needs to be actually fetched.
Attempted Solutions
I would expect that a provider could on every read check whether the data needs refetching, using (computed) attributes from a previous run. However, Terraform seems to always reset the ResourceData on every refresh.
This does not work, because
last_update
gets reset by Terraform on every read.Proposal
My proposal would be to not reset the data source attributes on every read. That way, providers have the option to look at the previous state and decide for themselves whether to refetch the data or not.
I don't see how this change could have an impact on existing providers, because they override the attributes on every read anyway.
References
hashicorp/terraform#17034
The text was updated successfully, but these errors were encountered: