Configure Grafana with Terraform
This guide shows you how to configure Grafana settings and dashboards with the Grafana Terraform provider.
Before you begin
Step 1: Create a stack for Grafana settings
Step 2: Remove the default stack configuration
Step 3: Set up the module
ok get-template "_versions_grafana_settings.tf.template"
# Configure the template
ENV_FILE="../env.yaml"
export TEAM_NAME=$(yq .metadata.team $ENV_FILE)
export ENVIRONMENT=$(yq .metadata.environment $ENV_FILE)
export AWS_REGION=$(yq .aws.region $ENV_FILE)
export AWS_ACCOUNT_ID=$(yq .aws.accountID $ENV_FILE)
export STATE_NAME=$(basename $(pwd))
cat _versions_grafana_settings.tf.template | envsubst '$TEAM_NAME,$ENVIRONMENT,$AWS_REGION,$AWS_ACCOUNT_ID,$STATE_NAME' > _versions_grafana_settings.tf
rm "_versions_grafana_settings.tf.template"
ok get-template _dependencies_grafana_settings.tf
ok get-template grafana_settings.tf
mkdir templates
cd templates
ok get-template grafana-dashboard-golden-path.json.tpl
cd ..
Step 4: Apply the configuration
Initialize Terraform and apply the configuration:
Grafana API key
A valid Grafana API key is required. You should already have one if you just completed the Grafana workspace guide. You don't have to do anything - it's loaded from SSM Parameter Store automatically.
What happens if the API key has expired?
If the API key has expired, terraform apply
will fail. To resolve this issue, see common issues.
Verify
Open Grafana. You should be able to see a dashboard. For more settings, see the grafana-settings.tf
file in the module.