terraform-cloud-exporter

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 11 Imported by: 0

README

Terraform Cloud/Enterprise Exporter

Prometheus exporter for Terraform Cloud/Enterprise metrics.

Go Test GitHub release Docker Release

Description

Sample Dashboard
Sample dashboard available in grafana/dashboards/general.json

Usage

  1. Create API Token:
    • For Terraform Cloud open: https://app.terraform.io/app/settings/tokens?source=terraform-login
    • For Terraform Enterprise see: https://www.terraform.io/docs/cloud/users-teams-organizations/api-tokens.html
  2. Save the token to a file or as the environment variable TF_API_TOKEN.
Native
  1. go get -u github.com/kaizendorks/terraform-cloud-exporter
  2. terraform-cloud-exporter -o <YourOrg> --api-token-file=/path/to/file
Docker
    docker run -it --rm \
        -p 9100:9100 \
        -e TF_API_TOKEN=<YourToken> \
    terraform-cloud-exporter -o <YourOrg>
Full list of Flags
    -h, --help                                     Show context-sensitive help.
    -o, --organization=STRING                      Name of the Organization to scrape from ($TF_ORGANIZATION).
    -t, --api-token=STRING                         User token for autheticating with the API ($TF_API_TOKEN).
        --api-token-file=/path/to/file             File containing user token for autheticating with the API.
        --api-address=https://app.terraform.io/    Terraform API address to scrape metrics from.
        --api-insecure-skip-verify                 Accept any certificate presented by the API.
        --listen-address="0.0.0.0:9100"            Address to listen on for web interface and telemetry.
        --log-level="info"                         Only log messages with the given severity or above. One of: [debug,info,warn,error]
        --log-format="logfmt"                      Output format of log messages. One of: [logfmt,json]

Contributing

Dev environment
  1. Create a .env file with your token:

     TF_API_TOKEN=<Your.atlasv1.Token>
     TF_ORGANIZATION=<YourOrg>
     TF_API_ADDRESS=<YourApiAddress - Optional: Only required for Terraform enterprise.>
    
  2. Run the Exporter, in one of two modes:

    1. Standalone exporter: docker-compose run --rm --service-ports --entrypoint sh exporter
      • Run code: go run main.go
      • View metricts: curl localhost:9100/metrics
    2. Full Prometheus stack: docker-compose up
      • Open Grafana: http://localhost:3000/
      • Clean up: docker-compode down
Go tests
  1. Apply style guides: go fmt ./...
  2. Static analysis: go vet ./...
  3. Run tests: go test -v ./... -coverprofile cover.out
  4. Examine code coverage: go tool cover -func=cover.out
Prod Image tests
  1. Todo: Clean this up....

  2. Build prod image:

     docker build --target prod \
         --build-arg tag=localv \
         --build-arg sha=locals \
     -t terraform-cloud-exporter .
    
  3. Run prod image

     docker run -it --rm \
         --env-file .env \
         -p 9100:9100 \
     terraform-cloud-exporter \
         --log-level debug
    
  4. Todo: Add dgoss tests

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
collector
Package collector includes all individual collectors to gather and export system metrics.
Package collector includes all individual collectors to gather and export system metrics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL