tfcmt Documentation

website·Indexed 29 days ago

https://suzuki-shunsuke.github.io/tfcmt/

Documentation for tfcmt, a tool for posting Terraform plan and apply results to GitHub pull requests. It includes guides on installation via Homebrew and aqua, configuration using JSON Schema, masking sensitive data, and integration with CI platforms like Google Cloud Build and Terragrunt. It is a fork of mercari/tfnotify v0.7.0.

Tokens
12.5K
Snippets
85
Records
109
Agent score
75%

What's inside tfcmt

  1. Overview of tfcmt for Terraform CI

    tfcmt is a CLI tool designed to improve the Terraform CI experience by posting the results of terraform plan and terraform apply directly as comments on GitHub Pull Requests. It is a fork of mercari/tfnotify and provides several enhancements, including support for Terraform v0.15 and above, advanced formatting options, and the ability to exclude state refresh logs from plan results.

    Key capabilities include:

    • Parsing Terraform execution results.
    • Binding parsed results to Go templates for customizable output.
    • Updating GitHub Pull Request labels based on the plan/apply results.
    • Posting or updating comments on GitHub PRs to keep the conversation clean.
  2. Overview of github-comment subcommands

    github-comment is a CLI tool for managing GitHub comments. It provides the following subcommands:

    • init: Generate a configuration file template.
    • post: Create a comment on a pull request or commit.
    • exec: Execute a shell command and create a comment based on the result.
    • hide: Hide pull request or issue comments.
  3. Overview of github-comment CLI

    github-comment is a CLI tool written in Go that allows you to create and hide GitHub comments using the GitHub REST API. It is primarily used to improve CI user experience by notifying users of CI results, highlighting failed commands and logs, and providing guides to help users resolve issues without manually digging through CI logs.
  4. Mask sensitive data in Terraform outputs using tfcmt

    Starting with tfcmt >= v4.9.0, you can mask sensitive data in the standard output/error of Terraform commands, pull request comments generated by tfcmt plan and tfcmt apply, and local files created via the --output option. All matching strings are replaced with ***.

    Important Caveat: This feature acts as a guardrail for output visibility; it does not remove secrets from the Terraform State files. Use Terraform's native sensitive flags for variables and outputs as a primary defense, and use tfcmt masking as an additional layer of protection.

  5. Use native CI platform support in tfcmt

    tfcmt provides native support for several CI platforms, allowing it to automatically populate the -owner, -repo, -pr, -sha, and -build-url parameters using the platform's built-in environment variables. This functionality is powered by go-ci-env.

    Supported CI platforms include:

    • GitHub Actions
    • CircleCI
    • Drone
    • AWS CodeBuild
    • Google Cloud Build
  6. Understand tfcmt platform support limitations

    tfcmt is a specialized fork and does not support all platforms previously available in tfnotify.

    Supported Platforms:

    • CI: CircleCI, CodeBuild, CloudBuild, GitHub Actions
    • Notifier: GitHub

    Unsupported Platforms:

    • CI: Jenkins, Travis, GitLab, Drone, TeamCity
    • Notification: Slack, TypeTalk, GitLab

    For GitLab users, the fork hirosassa/tfcmt-gitlab is recommended.

  7. Changes to comment behavior and metadata in tfcmt

    tfcmt modifies how GitHub comments are handled compared to tfnotify:

    • Duplicate Comments: tfcmt no longer removes duplicate comments to avoid breaking comment links.
    • Metadata: tfcmt embeds metadata into comments using github-comment-metadata.
    • Deletion Warnings: Instead of posting a separate deletion warning comment, tfcmt uses a single comment based on the when_destroy.template.
  8. Supported CI platforms for automatic environment variable complementation

    github-comment uses suzuki-shunske/go-ci-env to automatically complement configuration options using built-in environment variables from the following supported platforms: CircleCI, GitHub Actions, Drone, AWS CodeBuild, Google Cloud Build, and Atlantis (supported in v6.4.0 and later).
  9. Manage tfcmt comment metadata and visibility

    tfcmt uses github-comment-metadata to embed metadata into comments. While tfcmt does not natively support hiding old comments, you can achieve this by using the hide command from the github-comment tool.
  10. Update existing Terraform plan comments using the patch option

    In tfcmt v3.2.0 and later, you can update an existing comment instead of creating a new one to keep pull requests clean. This can be achieved via the command line flag -patch or the configuration file option plan_patch. The command line flag takes precedence over the configuration file. To explicitly disable patching when plan_patch is set to true in the config, use -patch=false.
    # Using the command line flag
    tfcmt plan -patch -- terraform plan -no-color
    
    # Disabling patch via command line
    tfcmt plan -patch=false -- terraform plan -no-color
    # Using the configuration file
    plan_patch: true
  11. Configure shell completion for github-comment

    The completion command generates shell completion scripts for various shells. Source the output in your shell configuration file to enable autocomplete.
    # For bash (.bashrc)
    source <(github-comment completion bash)
    
    # For zsh (.zshrc)
    source <(github-comment completion zsh)
    
    # For fish
    github-comment completion fish > ~/.config/fish/completions/github-comment.fish