Today we will dive in to tool which can be very usefull in some casses if you are working with terraform.
Main features:
1. Modern CLI (cobra-based) with autocomplete
2. Read logs straight from your Terraform process (using pipe) or a log file
3. Can generate global stats, resource-level stats or visualizations
4. Provides many levels of granularity and aggregation and customizable outputs
Let's check some of the usecases:
-
Developers and operators can leverage autocomplete to quickly navigate and explore available commands, options, and resources. It facilitates efficient command-line interaction with Terraform, reducing manual effort and increasing efficiency.
-
Operators and developers can use the CLI tool to monitor and analyze Terraform logs in real-time, enabling them to identify errors, track changes, and debug issues during provisioning or updates. It simplifies the troubleshooting process and aids in maintaining a stable infrastructure.
-
Users can generate high-level statistics such as total resource count, infrastructure cost, or deployment success rate across all Terraform projects. This provides a holistic view of the overall infrastructure health.
-
Operators can gather detailed information about specific resources, including usage, performance metrics, or compliance data. This aids in optimizing resource allocation and identifying bottlenecks.
-
Users can generate visual representations of their infrastructure, such as dependency graphs or resource topology diagrams. Visualizations help in understanding complex infrastructures, identifying relationships, and planning changes effectively.
-
Users can choose the level of detail they require, such as per-resource, per-module, or per-environment stats. This allows them to focus on specific areas of interest or zoom out for a broader overview.
-
Operators can aggregate stats based on different criteria like environment, region, or tags. This facilitates grouping and analyzing data in various ways, helping in resource management and cost allocation.
-
Users can customize the output format and structure to match their requirements, making it easier to integrate the CLI tool into existing workflows or extract specific information for further analysis.
Overall, this CLI tool with its modern interface, log analysis capabilities, stats generation, and customizable outputs significantly enhances the Terraform workflow, enabling efficient infrastructure management, monitoring, troubleshooting, and decision-making.
Prerequisites:
- Install Go - here
- Install Brew - here
- Install Tf Profile tool:
- Run
brew tap datarootsio/tf-profile
- Run
brew install tf-profile
- Run
tf-profile --help
to check available commands
- Run
Let's check this out:
I will use simple terraform code to create a couple of resources as example. After we installed our prerequisites we can go to our terraform folder
-
Run
terraform apply -auto-approve > log.txt
You will not see any output, it will be saved to log.txt file in your folder.
-
Run
tf-profile stats log.txt
For more information, refer to the reference for the stats command.
- Let's run another command
tf-profile table log.txt
- In order to filter a Terraform log to only selected resources you can use
tf-profile filter "resource.filter" log.txt
or you can use wildcards to filter on multiple resourcestf-profile filter "resource.*" log.txt
For a full description of the options, see the reference page.