Skip to content
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

Data source caching #134

Closed
florisvdg opened this issue Feb 20, 2019 · 2 comments
Closed

Data source caching #134

florisvdg opened this issue Feb 20, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@florisvdg
Copy link

Current Terraform Version

Terraform v0.11.11

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.

func dataSourceHeavyRead(d *schema.ResourceData, m interface{}) error {
	if needsUpdate(d.Get("last_update")) {
		// Only fetch if data is out of sync
		...
		lastUpdate := ...
		d.Set("last_update", lastUpdate)
	}
	return nil
}

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

@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@hashibot hashibot added the enhancement New feature or request label Oct 2, 2019
@paultyng
Copy link
Contributor

Merging with #7

@ghost
Copy link

ghost commented Feb 26, 2020

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 ghost locked and limited conversation to collaborators Feb 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants