2

I am working on a requirement where I need to show terraform plan output in a nicer way so that user can understand what resources it is going to create etc.

Currently we are printing terraform plan output in jenkins console in json format but we need this output in graphical format like we have Blue Ocean plugin in jenkins. I did research for various plugins bit not find any.

Do we have any kind of Jenkins plugin which shows terraform plan in the form of any visual representation like graph or do we have any alternate option where we can show the terraform plan output anywhere where user can understand it easily as we are looking for good visual representation.

svw1105
  • 127
  • 1
  • 15

3 Answers3

1

Here is a link for output options of the terraform plan command. I don't think there are any visual representations regarding the plan. We are using json format and find it very readable.

54m
  • 719
  • 2
  • 7
  • 18
  • 1
    I found one resource where we can see visual representation of tf plan. https://github.com/hieven/terraform-visual – svw1105 Jun 08 '21 at 05:13
1

You can install the AnsiColor plugin and enable the 'Color ANSI Console Output' checkbox (under Build Environments) in job configuration.

pppai
  • 71
  • 5
0

I found a few workarounds that are not jenkins specific but still work nicely in a pipeline. For simple stuff you can pipe through dot and render it using:

terraform graph -var-file=config/$TARGET.tfvars | dot -Tpng > qa-graph.png

It ain't pretty, but it works...

Now: graphviz will take that dot output and render it a little nicer. It even gives you some pretty sexy rendering options - but even though you can put lipstick on a pig, it's still a pig! The problem is the graph, itself... I think programmers have been trying to solve this for like 30 or 40 years. The '(not-so) old-school' solution is here --> stackoverflow://1494492/graphviz-how-to-go-from-dot-to-a-graph

Currently, I have been playing with graph beautifier which takes the output of tf-graph and renders it as javascript. I just push the html to nginx instead of the output from graphviz. Then, I just print the url to the output of jenkins, and open the link in a new tab. I know it's kinda-hacky, but I couldn't find any cleaner way - which brought me here, today...

ANYWAY: depending on how modular your tf-code is, the graph-beautifier creates a nice little spider-web screenshot of graph-beautifier

Below is a bash snip-it from the end of my jenkinsfile which rendered that screenshot

#------------------------------------------------------------------------------
# * VISUALIZER: data analysis tool to help make deployments & audits faster 
# creates a tf-graph file & publish to the web using local nginx server
#> requires nginx & graphviz -- https://graphviz.org  
#------------------------------------------------------------------------------
WEBHOST='myserver.example.com'
WEBROOT='/usr/share/nginx/html'  
WEBPATH="graphviz/$BRANCH"
WEBDEST="$WEBROOT/$WEBPATH"
WEBPAGE="index.html"
# * create the target dir if it doesn't exist 
[ -d $WEBDEST ] || mkdir -vp $WEBDEST 

##------------------------------------------------------------------------------
## 21-1124JN - unhappy with just an image I switched to an interactive visualizer
## ? -- https://github.com/pcasteran/terraform-graph-beautifier
##------------------------------------------------------------------------------
terraform graph | /usr/share/go/bin/terraform-graph-beautifier \
    --exclude="module.root.provider" \
    --output-type=cyto-html \
    --embed-modules=true \
    > $WEBDEST/$WEBPAGE 
echo -en "\n\n  tf-graph --> http://$WEBHOST/$WEBPATH \n\n"

##------------------------------------------------------------------------------    
## NOTE: the beautifier is just a POC. it's something I have used before and 
##> threw together in a few hours for demo. There are newer projects that 
##> are actively maintained & seem to have a lot cleaner ways of working with 
##> larger data-sets & graphs. One is called the Rover - Terraform Visualizer
##> and is available here --> https://github.com/im2nguyen/rover check it out
##------------------------------------------------------------------------------    

last but not least (as I mention in my code comments) is the Rover Terraform Visualizer - a new one that came out of the brain of one of the hashicorp-kids which is super-promising and has recently been released to open source. It is also written in go, but I haven't gotten it to work yet in my pipeline. Check out his demo.

ouflak
  • 2,458
  • 10
  • 44
  • 49