pre-commit-terraform icon indicating copy to clipboard operation
pre-commit-terraform copied to clipboard

feat: Add `terraform_graph` hook

Open jrdnbradford opened this issue 6 months ago β€’ 1 comments

Put an x into the box if that apply:

  • [ ] This PR introduces breaking change.
  • [ ] This PR fixes a bug.
  • [X] This PR adds new functionality.
  • [ ] This PR enhances existing functionality.

Description of your changes

This adds a terraform_graph hook that generates charts using terraform graph and GraphViz. My org finds something like this helpful to upkeep documentation.

Test results

200 runs 'terraform_graph v0.0.1:'

time command max min mean median
users seconds 14.71 9.51 13.6592 13.84
system seconds 1.48 0.95 1.28115 1.29
CPU % 415 149 371.545 377
Total time 8.71 3.16 4.054 3.99
Run details
  • Test Start: Mon 11 Dec 2023 04:41:22 PM UTC
  • Test End: Mon 11 Dec 2023 04:54:54 PM UTC
Variable name Value
TEST_NUM 200
TEST_COMMAND pre-commit try-repo -a /home/$user/Desktop/pre-commit-terraform terraform_graph
TEST_DIR /home/$user/$repo
TEST_DESCRIPTION 200 runs 'terraform_graph v0.0.1:'
RAW_TEST_RESULTS_FILE_NAME terraform_graph_results

Memory info (head -n 6 /proc/meminfo):

MemTotal:       32519148 kB
MemFree:         8189176 kB
MemAvailable:   27378808 kB
Buffers:          571396 kB
Cached:         14010628 kB
SwapCached:          120 kB

CPU info:

Real procs: 4
Virtual (hyper-threading) procs: 8
processor	: 7
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
stepping	: 12
microcode	: 0xf8
cpu MHz		: 3400.063
cache size	: 8192 KB
physical id	: 0
siblings	: 8
core id		: 3
cpu cores	: 4
apicid		: 7
initial apicid	: 7
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple shadow_vmcs pml ept_mode_based_exec
bugs		: spectre_v1 spectre_v2 spec_store_bypass swapgs taa itlb_multihit srbds mmio_stale_data retbleed eibrs_pbrsb gds
bogomips	: 4599.93
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

How can we test changes

Testing can be performed by running against a repo with *.tf files and ensuring that the correct *.svg files are output in each directory:

- repo: https://github.com/jrdnbradford/pre-commit-terraform
  rev: add-graph-hook
  hooks:
    - id: terraform_graph
      args:
      - --args=-type=plan-destroy
      - --hook-config=--path-to-file=test-config.svg

The most important configs for the hook are -type and a hook config --path-to-file that sets the name of the output *.svg.

I cannot say that I'm a particularly good shell scripter, so if there's interest in adding this please feel free to edit.

jrdnbradford avatar Dec 11 '23 17:12 jrdnbradford