Sign inSign up

eversc/terraform_planner

By eversc

•Updated almost 6 years ago

terraform_planner automated build

Image
0

100K+

eversc/terraform_planner repository overview

⁠Terraform_Planner

This produces a Docker image⁠ that can be run periodically to run a terraform plan, and post the resulting status code to Datadog.

Currently only Google⁠ and Kubernetes⁠ providers are supported, though there's definitely scope for more to be added.

Only Github is supported, in terms of the repo where you hold your terraform config.

⁠Environment Variables

namerequired?defaultpurpose
CONFIG_PATHN./tf_planner.confPath to config file
DD_API_KEYyDatadog API key
DD_ENVyname of environment (used as a tag in Datadog metric)
DD_METRIC_NAMEyname of Datadog metric
DD_TEAMyname of team (used as a tag in Datadog metric)
GCP_PROJECT_NAMEnname of GCP project the gke cluster is running in
GCP_ZONEnname of GCP zone that the gke cluster is running in
GIT_CLONE_STRINGyssh string used to clone a repo, e.g. [email protected]:my_org/my_repo.git
GOOGLE_APPLICATION_CREDENTIALSypath to the service-account key.json
K8S_CLUSTER_NAMEnname of k8s cluster
POST_COMMIT_WAIT_MINSn10if a commit has been made to the git repo within this time, skip the run
TF_INIT_ARGSn""args to supply the terraform init command⁠
TF_PATHy
TF_PLAN_ARGSn""args to supply the terraform plan command⁠

Variables can also be pulled from a config file (default: /etc/tf_planner.conf)

E.g.:

DD_API_KEY=12345abcde
DD_ENV=prod
DD_METRIC_NAME=tf_plan
...
...

Variables from both config and env vars are joined. Config vars take precedence.

⁠Notes

  • It's recommended to create a Deploy Key⁠ to give the terraform_planner access to your git repo.

  • You'll need to drop the ssh key into ~/.ssh (/home/tf/.ssh). The plan.sh script verifies github's public key fingerprint, and upon a successful check, adds the key to known_hosts.

  • The script won't ever be running terraform apply, so the service-account used should be locked down to read-only scopes for the resources it needs.

  • If using the metric in Datadog Monitors with 'Notify if data is missing' enabled, it's recommended to set the 'missing data' threshold value in Datadog to more than the POST_COMMIT_WAIT_MINS value. Otherwise, every time a commit is made to the git repo, the missing data alert will be fired.

  • Ensure the time window in the Datadog monitor alert condition is less than the frequency of the terraform_planner run. This is to prevent the metric being included in two adjacent time chunks (meaning you would get a count of 2 if a status of 1 was outputted in subsequent runs).

  • Contributions are very welcome (please branch or fork and raise PR).

Tag summary

Content type

Image

Digest

Size

759.7 MB

Last updated

almost 6 years ago

docker pull eversc/terraform_planner