Talal is a DevOps engineer and he has deployed the production infrastructure using Terraform. He is using a very large configuration file to maintain and update the actual infrastructure. As the infrastructure have grown to a very complex and large, he has started experiencing slowness when he run runs terraform plan .
What are the options for him to resolve this slowness?
A . Use -refresh=true flag as well as the -target flag with terraform plan in order to work around this.
B . Run terraform refresh every time before running terraform plan.
C . Break large configurations into several smaller configurations that can each be independently applied.
D . Use -refresh=false flag as well as the -target flag with terraform plan in order to work around this.
Answer: C,D
Explanation:
For larger infrastructures, querying every resource is too slow. Many cloud providers do not
provide APIs to query multiple resources at once, and the round trip time for each resource is hundreds of milliseconds. On top of this, cloud providers almost always have API rate limiting so Terraform can only request a certain number of resources in a period of time. Larger users of Terraform make heavy use of the -refresh=false flag as well as the -target flag in order to work around this. In these scenarios, the cached state is treated as the record of truth.
Although ‘Use -refresh=false flag as well as the -target flag with terraform plan in order to work around this.’ is a solution, but its not always recommended. Instead of using -target as a means to operate on isolated portions of very large configurations, prefer instead to break large configurations into several smaller configurations that can each be independently applied. Data sources can be used to access information about resources created in other configurations, allowing a complex system architecture to be broken down into more manageable parts that can be updated independently.
Option ‘Run terraform refresh every time before running terraform plan.’ and ‘Use – refresh=true flag as well as the -target flag with terraform plan in order to work around this.’ is not correct because in both the cases terraform will query every resources of the infrastructure.