Apply and verify
With the plan confirmed, you can now apply it to deploy your alerting pipeline to Grafana.
To deploy and verify your alerting pipeline, complete the following steps:
Run
terraform apply:terraform applyTerraform displays the plan again and asks for confirmation. Type
yesand press Enter:Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yesWait for Terraform to complete. You should see:
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.Open your Grafana instance in a browser and navigate to Alerting > Alert rules in the left-side menu.
Look for the Terraform Alerts folder. Click into it.
Confirm the CPU alerts rule group appears with the High CPU usage rule.
Navigate to Alerting > Contact points and confirm Email alerts appears.
Navigate to Alerting > Notification policies and confirm the default route points to your contact point.
Updating a deployed alert rule
When you modify your HCL and run terraform apply again, Terraform detects the change and updates the existing resources in place. No duplicates, no manual intervention.
# After modifying alerts.tf:
terraform plan # Preview the update
terraform apply # Apply the updateWhat Terraform state tracks
Terraform stores the deployed resource IDs in its state file (terraform.tfstate). This is how it knows whether to create or update a resource on subsequent runs. Keep the state file safe. If you lose it, Terraform won’t know about existing resources.
Your alerting pipeline is now deployed and managed by Terraform.