Getting started with the Terraform provider for Checkly
On this page
The Checkly Terraform provider enables you to declare your monitoring setup as code using HashiCorp Terraform. You can get started with it in a matter of minutes by following the steps shown below.
If you prefer, you can also clone our sample repository and play around with the resources on your own.
For in-depth information on Terraform, please see HashiCorp’s official documentation.
Looking for Monitoring as Code but don’t want to use Terraform? Give our CLI solution a try.
To get started, you first need to install Terraform.
Next, switch to a new folder for your project, and create your main.tf file:
Start by adding the following to your main.tf:
This is all the code you need to set up the Checkly Terraform provider. You now need to set your credentials to give the provider access to your Checkly account.
First, you will need an API Key for your Checkly user. Go to the API keys tab in your user settings and click Create API key.
Get your User API key and add it to your env using your terminal:
You also need to set your target account ID, which you can find under your account settings.
If you don’t have access to account settings, please contact your account owner/admin.
Running terraform init will install the Checkly Terraform provider for you, as well as initialising your project. The output will look similar to the following:
You can now start adding resources to your file. You can check the official documentation to see available parameters for each resource type.
You can now have Terraform apply your changes on Checkly by running terraform apply. Terraform will draft a plan and ask you to confirm by typing yes. Once that is done, Terraform will go ahead and create the resources you have specified (one browser check, so far) for you.
Your Checkly account should now show the first check up and running:
Now that you have your checks set up, you’ll want to set up an alert channel for Checkly to promptly inform you when one of them fails. For example, you could create an email channel:
Next, subscribe each check to the alert channel:
You can now run terraform apply for the last time and have Terraform create your checks and alert channel for you.
Congratulations! You have created your first Checkly monitoring setup using Terraform.
Checkly resources should be managed either through Terraform or through the Checkly UI, not both.
Modifying Terraform-managed resources via the UI, and , is likely to cause issues.