Skip to main content
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.

Installation

To get started, you first need to install Terraform. Next, switch to a new folder for your project, and create your main.tf file:
Terminal
Start by adding the following to your main.tf:
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. api key tab in checkly settings Get your User API key and add it to your env using your terminal:
Terminal
You also need to set your target account ID, which you can find under your account settings. account id in checkly settings If you don’t have access to account settings, please contact your account owner/admin.
Terminal
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:
Terminal
You can now start adding resources to your file. You can check the official documentation to see available parameters for each resource type.

Your first browser check

As an example, you could add a basic browser check resource at the bottom of your main.tf.
main.tf

Applying changes

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.
Terminal
Your Checkly account should now show the first check up and running: checkly dashboard with running check

Adding an API check

You can also add an API check to monitor an API endpoint:
main.tf
You can now choose to re-run terraform apply or wait until we have added an alert channel and have Terraform create both resources at once.

Setting up alerts

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:
main.tf
Next, subscribe each check to the alert channel:
main.tf
You can now run terraform apply for the last time and have Terraform create your checks and alert channel for you. checkly dashboard with running check 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 vice-versa, is likely to cause issues.