Prometheus exporter for Terraform Cloud/Enterprise metrics.
Note
There is a newer version of this exporter being maintained by a Senior Staff Solutions Engineer at HashiCorp: TFBI (Terraform Business Insights).
It provides significant updates to metrics and Grafana dashboards for Terraform Cloud and Enterprise.
![]() |
|---|
Source code: grafana/dashboards/general.json |
- 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
- For Terraform Cloud open:
- Save the token to a file or as the environment variable
TF_API_TOKEN.
go get -u github.com/kaizendorks/terraform-cloud-exporter
terraform-cloud-exporter \
--organizations=<YourOrg1>,<YourOrg2>,... \
--api-token-file=/path/to/file
docker run -it --rm \
-p 9100:9100 \
-e TF_API_TOKEN=<YourToken> \
terraform-cloud-exporter
-h, --help Show context-sensitive help.
-o, --organizations=ORG1,ORG2,... List of the Organization names to scrape from (Omit to scrape all) ($TF_ORGANIZATIONS).
-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]
-
Create a
.envfile with your token:TF_API_TOKEN=<Your.atlasv1.Token> TF_ORGANIZATIONS=<YourOrg1,...> TF_API_ADDRESS=<YourApiAddress - Optional: Only required for Terraform enterprise.> -
Run the Exporter, in one of two modes:
- Standalone exporter:
docker-compose run --rm --service-ports --entrypoint sh exporter- Run code:
go run main.go - View metricts:
curl localhost:9100/metrics
- Run code:
- Full Prometheus stack:
docker-compose up- Open Grafana:
http://localhost:3000/ - Clean up:
docker-compode down
- Open Grafana:
- Standalone exporter:
The examples/ directory contains two minimal configurations for generating test runs in HCP Terraform:
examples/success/— applies arandom_stringresource, run ends asappliedexamples/error/— uses aprecondition = false, run ends aserrored
From either directory:
export TF_CLOUD_ORGANIZATION=<YourOrg>
export TF_TOKEN_app_terraform_io=<YourToken>
terraform init
terraform apply -auto-approve
These are useful for verifying the exporter's tf_workspaces_info{current_run_status="..."} metric reflects real run states.
- Apply style guides:
go fmt ./... - Static analysis:
go vet ./... - Run tests:
go test -v ./... -coverprofile cover.out - Examine code coverage:
go tool cover -func=cover.out
-
Todo: Clean this up....
-
Build prod image:
docker build --target prod \ --build-arg tag=localv \ --build-arg sha=locals \ -t terraform-cloud-exporter . -
Run prod image
docker run -it --rm \ --env-file .env \ -p 9100:9100 \ terraform-cloud-exporter \ --log-level debug -
Todo: Add dgoss tests
