我发现了一些不是 jenkins 特有的解决方法,但在管道中仍然可以很好地工作。对于简单的东西,你可以通过dot 进行管道处理并使用:
terraform graph -var-file=config/$TARGET.tfvars | dot -Tpng > qa-graph.png
它不漂亮,但它有效......
现在:graphviz 将采用该点输出并将其渲染得更好一些。它甚至给了你一些pretty sexy rendering options - 但即使你可以在猪身上涂口红,它仍然是猪!问题在于图表本身……我认为程序员已经尝试解决这个问题 30 或 40 年了。 “(不那么)老派”的解决方案在这里 --> stackoverflow://1494492/graphviz-how-to-go-from-dot-to-a-graph
目前,我一直在使用graph beautifier,它获取 tf-graph 的输出并将其呈现为 javascript。我只是将 html 推送到 nginx 而不是 graphviz 的输出。然后,我只是将 url 打印到 jenkins 的输出中,然后在新选项卡中打开链接。我知道这有点 hacky,但我找不到任何更清洁的方法 - 今天把我带到这里......
无论如何:根据您的 tf 代码的模块化程度,图形美化器会创建一个漂亮的小蜘蛛网screenshot of graph-beautifier
下面是我的 jenkinsfile 末尾的 bash 片段,它呈现了该屏幕截图
#------------------------------------------------------------------------------
# * 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
##------------------------------------------------------------------------------
最后但并非最不重要的(正如我在代码 cmets 中提到的)是 Rover Terraform Visualizer - 一个新的来自 hashcorp-kids 的大脑,它非常有前途,最近已发布开放资源。它也是用 go 编写的,但我还没有让它在我的管道中工作。查看his demo。