Hi team,
Please suggest how to profile terraform execution to get some useful metrics.
The origin of the question is that we have ~1K modules wrapped into tree structure with terragrunt and executed with python.
I can timeit execution itself and parse resources section of state file.
But I missing internals metrics to come up with module size metric, num of api calls e.g.
To things I’m trying to achive:
- optimize modules to avoid unnecessary calls
- deduce complexity of modules driven by some rationale numbers.
Regards,
Serhii
Hi @chell0veck,
For most (but not necessarily all) Terraform configurations, the most significant delays at runtime come from waiting for remote network APIs to respond, or to eventually become consistent.
You can potentially measure those by running terraform plan -json -out=tfplan
and terraform apply -json tfplan
, where the -json
argument will ask Terraform to produce machine-readable output in the form of a stream of JSON objects written to stdout.
If you write a wrapper program to consume that output and record the arrival times of certain interesting events then you should be able to determine which operations are taking the longest.
1 Like