Use the Grafana Terraform provider to manage OnCall resources, such as schedules, escalation chains and more within your “as-code” workflow.
To learn more:
- read our Get started with Grafana OnCall and Terraform blog post
- refer to the Terraform provider documentation
- check out the Terraform provider source code
Refer to Terraform provider README.md for more details.
-
Clone Grafana OnCall Go Client repo and make local changes
-
Clone Grafana Terraform plugin repo, check Readme and make local changes
-
Set env variables
Warning: you might want to set another OS_ARCH, provided value are for Apple Silicon
export BINARY=terraform-provider-grafana OS_ARCH=darwin_arm64 HOSTNAME=grafana.com NAMESPACE=raintank NAME=grafana VERSION=1.0.0
-
Build provider
go build -o ${BINARY}
-
If there are changes to
grafana/amixr-api-go-client/
make sure to replace it in provider's go.mod:Warning: this command is example, name or version of api client might and will change, check provider's go.mod
// TODO: remove this after testing replace github.com/grafana/amixr-api-go-client v0.0.8 => /YOUR_LOCAL_PATH/amixr-api-go-client
-
Create a
.terraformrc
in$HOME
directory and paste the followingprovider_installation { dev_overrides { "grafana/grafana" = "/path/to/your/grafana/terraform-provider" # this path is the directory where the binary is built } }
-
Create a new directory and a
main.tf
file with the following content:terraform { required_providers { grafana = { source = "grafana/grafana" version = "1.0.0" } } } provider "grafana" { alias = "oncall" oncall_access_token = oncall_url = }
-
Run the following commands to initialize Terraform and apply the configuration:
terrafrom init terraform plan/apply