« Back to Index

Terraform: what should and shouldn’t be there

View original Gist on GitHub

Tags: #tf #terraform #fastly

Terraform - what should and shouldn’t be there.markdown

Summary
Store configuration, NOT data.

Why?
Data is going to be stored in the tfstate file and because of how the terraform command-line interface works (e.g. it communicates with a separate ‘core’ process over gRPC) there’s a size limitation of 4mb going over the wire.

Additional Comments
Populating resources with data externally from Terraform is very dangerous, as you’re side-stepping the protection guarantees that Terraform is designed to provide. If Terraform’s tfstate file doesn’t know about data that’s been created/pushed externally (i.e. data not defined within a terraform file and CRUD’ed using the terraform CLI), then Terraform is going to delete that data on the next plan/apply operation because (as far as Terraform is concerned) it shouldn’t exist.

Consider the Fastly terraform provider. We’ve seen the following situations:

NOTE: if you manage data in terraform, and only add ignore_changes until much later (e.g. after adding 50k ACL records you finally add ignore_changes), then you’ll discover that terraform’s tfstate file will still know about the data and try to move it around (e.g. terraform plan will attempt to pull down 50k records and pass it internally to its ‘core’ process, thus triggering the gRPC 4mb limit error). The only way to solve the issue from the point is to remove the data from the tfstate file using terraform rm.