CI runs `terraform init` for 30 stacks and downloads the 400 MB AWS provider every time. How do you speed it up?
IntermediateScenarioWorkflow and Providers
Answer
Situation read → Repeated downloads waste time and bandwidth.
What I'd do →
- Set
TF_PLUGIN_CACHE_DIRto a persistent directory on the runner. - Cache that directory between jobs (for example
actions/cachekeyed on the lock file hash).
export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"
mkdir -p "$TF_PLUGIN_CACHE_DIR"
terraform init -input=false
Why → Terraform symlinks cached provider binaries instead of redownloading, so 30 inits share one copy.
Interview tip → The lock file still verifies checksums, so caching doesn't weaken integrity.
More on Workflow and Providers
A new teammate is about to run Terraform for the first time against a shared dev account. Which commands do you walk them through, and in what order?BeginnerYour manager asks why we bother with `terraform plan` when `apply` shows the same diff before asking for confirmation. What do you say?BeginnerTwo engineers get different provider versions and see different plans for the same code. How do you stop this?BeginnerSomeone committed the `.terraform/` directory to the repo. What should be in version control and what should not?BeginnerThe same configuration must create a VPC in `us-east-1` and a DR copy of a bucket in `eu-west-1`. How do you do it with one root module?IntermediateYou must deploy the same stack into 12 AWS accounts. How do you handle credentials and provider configuration?Intermediate