Giter Site home page Giter Site logo

tf-profile's Introduction

tf-profile

Coverage

Go Linting, Verification, and Testing Go Report Card Go Reference

CLI tool to profile Terraform runs, written in Go.

Main features:

  • Modern CLI (cobra-based) with autocomplete
  • Read logs straight from your Terraform process (using pipe) or a log file
  • Can generate global stats, resource-level stats or visualizations
  • Provides many levels of granularity and aggregation and customizable outputs

Featured on: awesome-go | awesome-terraform

Installation

Brew install

❱ brew tap datarootsio/tf-profile 
❱ brew install tf-profile
❱ tf-profile --help
tf-profile is a CLI tool to profile Terraform runs

Usage:
  tf-profile [command]

Binary download

Using docker

If you want to try tf-profile without installing anything, you can run it using Docker (or similar).

❱ cat my_log_file.log | docker run -i qbruynseraede/tf-profile:0.2.0 stats

Key                                Value                                     
Number of resources created        1510                                      
                                                                             
Cumulative duration                36m19s                                    
Longest apply time                 7m18s                                     
Longest apply resource             time_sleep.foo[*]                         
...

Optionally, define an alias:

alias tf-profile=docker run -i qbruynseraede/tf-profile:0.2.0
❱ cat my_log_file.log | tf-profile

Build from source

This requires at least version 1.20 of the go cli.

❱ git clone [email protected]:QuintenBruynseraede/tf-profile.git
❱ cd tf-profile && go build .
❱ sudo ln -s $(pwd)/tf-profile /usr/local/bin  # Optional: only if you want to run tf-profile from other directories
❱ tf-profile --help
tf-profile is a CLI tool to profile Terraform runs

Usage:
  tf-profile [command]

Basic usage

tf-profile handles input from stdin and from files. These two commands are therefore equivalent:

❱ terraform apply -auto-approve | tf-profile table
❱ terraform apply -auto-approve > log.txt && tf-profile table log.txt

Four major commands are supported:

  • 🔗 tf-profile stats: provide general statistics about a Terraform run
  • 🔗 tf-profile table: provide detailed, resource-level statistics about a Terraform run
  • 🔗 tf-profile filter: filter logs to include only certain resources
  • 🔗 tf-profile graph: generate a visual overview of a Terraform run.

tf-profile stats

tf-profile stats is the most basic command. Given a Terraform log, it will only provide high-level statistics.

❱ terraform apply -auto-approve > log.txt
❱ tf-profile stats log.txt

Key                                Value    
-----------------------------------------------------------------                       
Number of resources in configuration        1510                            
                                                                   
Cumulative duration                         36m19s                          
Longest apply time                          7m18s                           
Longest apply resource                      time_sleep.foo[*]               

Resources marked for operation Create       892
Resources marked for operation None         18
Resources marked for operation Replace      412      
    
Resources in state AllCreated               800                             
Resources in state Created                  695                             
Resources in state Started                  15        
    
Resources in desired state                  1492 out of 1510 (98.8%)
Resources not in desired state              18 out of 1510 (0.01%)
                                                                
Number of top-level modules                 13                              
Largest top-level module                    module.core[2]                  
Size of largest top-level module            170                             
Deepest module                              module.core[2].module.role[47]  
Deepest module depth                        2                               
Largest leaf module                         module.dbt[4]                   
Size of largest leaf module                 40  

For more information, refer to the reference for the stats command.

tf-profile table

tf-profile table will parse a log and provide per-resource metrics.

❱ terraform apply -auto-approve > log.txt
❱ tf-profile table log.txt

resource              n  tot_time  modify_started  modify_ended  desired_state  operation  final_state  
aws_ssm_parameter.p6  1  0s        6               7             Created        Replace    Created      
aws_ssm_parameter.p1  1  0s        7               5             Created        Replace    Created      
aws_ssm_parameter.p3  1  0s        5               6             Created        Replace    Created      
aws_ssm_parameter.p4  1  0s        /               1             NotCreated     Destroy    NotCreated   
aws_ssm_parameter.p5  1  0s        4               4             Created        Modify     Created      
aws_ssm_parameter.p2  1  0s        /               /             Created        None       Created      

For a full description of the options, see the reference page.

tf-profile filter

tf-profile filter filters logs to include only certain resources. Wildcards are supported to filter on multiple resources.

❱ tf-profile filter "module.*.null_resource.*" log.txt

  # module.mod1.null_resource.foo will be created
  + resource "null_resource" "foo" {
    ...
    }

  # module.mod2.null_resource.bar will be created
  + resource "null_resource" "bar" {
    ...
    }

module.mod1.null_resource.foo: Creating...
module.mod2.null_resource.bar: Creating...
module.mod1.null_resource.foo: Creation complete after 1s [id=foo]
module.mod2.null_resource.bar: Creation complete after 1s [id=bar]

For a full description of the options, see the reference page.

tf-profile graph

tf-profile graph is used to visualize your terraform logs. It generates a Gantt-like chart that shows in which order resources were created. tf-profile does not actually create the final image, but generates a script file that Gnuplot understands.

❱ tf-profile graph my_log.log --out graph.png --size 2000,1000 | gnuplot

graph.png

Disclaimer: Terraform's logs do not contain any absolute timestamps. We can only derive the order in which resources started and finished their modifications. Therefore, the output of tf-profile graph gives only a general indication of how long something actually took. In other words: the X axis is meaningless, apart from the fact that it's monotonically increasing.

Screenshots

stats.png

table.png

graph2.png

tf-profile's People

Contributors

quintenbruynseraede avatar actions-user avatar araram96 avatar

Stargazers

Connor Edwards avatar Luke Taylor avatar fiskhest avatar Sergey Melnik avatar  avatar Samuel Maftoul avatar Hugh Wells avatar Jonathan Forget avatar Ivan Franjic avatar Louis Garman avatar Niv Penso avatar Daan De Wilde avatar  avatar Guy Vangeel avatar castaneai avatar tkancf avatar Koichi Shiraishi avatar Grigoriy0 avatar Marcos Soutullo Rodriguez avatar Lukas Valatka avatar  avatar Jeroen Flipts avatar  avatar Mahi Begoug avatar Oleksandr Sapozhnikov avatar Chauncey Garrett avatar  avatar Kevin Ridgway avatar Nick Tkach avatar Tim Kersey avatar Preston Turner avatar  avatar Hemendra sharma avatar Dave Bunten avatar Oleksii Kraievyi avatar REVL avatar Roman Makarov avatar Graham McMillan avatar Dieter De Meyer avatar David Alexander avatar hedy kim avatar Ian avatar Ryan Kim avatar  avatar brad210 avatar Nyamdorj Tsereg avatar Borja Lopez avatar Lucas Farias avatar Tane Piper avatar Vlad avatar  avatar Randy D. Wallace Jr. avatar sonny avatar Chris L. avatar  avatar  avatar Tom Hummel avatar  avatar Yukesh Hari avatar Maksim avatar Yannis Radhima avatar Max Az avatar Zoltán Reegn avatar Kirill Trofimov avatar Prelegal Wonder avatar  avatar Maksym Vlasov avatar Vlad Holubiev avatar Szabolcs Berecz avatar nakatanakatana avatar Daniel Kertesz avatar ryo. avatar Lam Tran avatar Michael Warkentin avatar Ian Bartholomew avatar Fizzy avatar Dmitrii Miroshnichenko avatar nitrocode avatar Filippo Giunchedi avatar Harry Dam avatar Alexander Jackson avatar Pierre Nicolas Durette avatar Jose Luis Salas avatar Chris Harrison avatar Piyush Sonigra avatar Damien Laureaux avatar Loren Gordon avatar Lucas Sant' Anna avatar Carlo Mencarelli avatar Nikolay Kolev avatar Andoni Alonso  avatar  avatar Jerome Ducret avatar Alberto Llamas avatar Eduardo Bellido Bellido avatar Maxime Sibellas avatar Harshad Ranganathan avatar NAITIVE avatar  avatar Edhar Rybak avatar

Watchers

Leen Toelen avatar Wim Van Leuven avatar  avatar Dylan Meeus avatar Gauthier Feuillen avatar Julien avatar Nelis Goeminne avatar  avatar Loren Gordon avatar Bram Vandendriessche avatar Wai Kit Tsang avatar Jonas Soenen avatar Kevin Algoet avatar Tim Leers avatar  avatar Dorian Van den Heede avatar Toon Van Craenendonck avatar Sneha Gauns Gaonkar avatar Tim Van Erum avatar Paolo Léonard avatar Charlotte De Baere avatar  avatar  avatar Nemish Mehta avatar

tf-profile's Issues

README badges

I would find the following interesting to see:

  • codecov
  • go report
  • go reference (if there is a public go API)
  • ref to awesome list (once there)

Add support for filtering on attributes

As a developer, when migrating resources on terraform from one state to another, I encounter cases where the change of the resource is only the tags attached to it. I want to be able to filter those out to check if there are any "real" changes to those resources.

Question : Use cases

HI,
As I understand, using this tool locally has some benefits
Probably better use case, would be to collect the metrics over time and understand performance of terraform code base over time?

Are use cases for this tool described somewhere? Sorry if missed it somewhere here on github

Something like :

  • add as a pipeline step and export the metrics to tool XYZ for building a dashboard; Graphana/Prometheus, New Relics and etc
  • comparison between different runs
  • introducing some best practices based on number of resources & time it takes for an apply

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.