Is it possible to "render" a Terraform configuration?

Hi @CyrusJavan,

Sorry for not replying sooner. I’ve been taking some time away from work.

Unfortunately my short answer is that there is no direct way to get the result you’re looking for, because Terraform’s normal mode of operation is to resolve these values dynamically based on the plan in progress, rather than simply to plug in the existing values in state (which I assume is what you were hoping to do here).

Thinking more about your stated goal than your current strategy, I have an alternative strategy to suggest:

In recent versions of Terraform we included a streaming JSON output mode for terraform plan and terraform apply, which was originally intended to allow different UI layers wrapping Terraform but could also potentially serve as a (admittedly rather coarse) means to measure how long various different Terraform actions are taking.

If you run terraform plan -refresh-only -json then Terraform should create a refresh-only plan while producing on stdout a series of JSON objects that report the sequence of actions it’s taking to do so.

In your case, you could monitor for the refresh_start and refresh_complete messages in particular, correlate them by hook.resource.resource, and then use the difference in @timestamp to get a somewhat-accurate elapsed time for each refreshed resource instance.

Terraform would still do the various other work involved in creating a plan, but you could ignore those messages and thus gather only the data you care about. (Might be interesting to experiment with running with and without --parallelism=1 to see if concurrent non-refresh actions have any material impact on how long a refresh action takes; I’d expect it would be immaterial because refreshing is I/O-bound, but I’ve never actually measured it!)

An interesting thing about this approach is that in principle you could instrument your routine Terraform runs in this way, both generating the plan and gathering the timing information you want. The trick there would be that Terraform’s designed to either produce JSON output or human-readable output, not both, and so to do this would mean you’d lose the typical human-readable log output. You could at least still get the main plan diff part though:

terraform plan -refresh-only -json -out=tfplan
terraform show tfplan