Eclipsys Blog

How to Automate Creation of Multiple OCI Alarms using Terraform Observability Module

Written by Manoj Kumar | Aug 13, 2024 3:00:00 PM

Recently, I needed to monitor a client’s cloud environment using observability and management OCI service.

And I found I need to create each alarm manually for each metric using the OCI console which is very time-consuming.

After research, I found Terraform already has an Observability Module which we can use to create multiple Alarms in one shot.

Here is the link for the module… Terraform Module

This module has three submodules. alarm, logan_sources, and serviceconnector.

I am using the alarm creation submodule and will show you how to create multiple alarms.

 

Pre-requisites:

  1. git is installed
  2. Terraform 1.3.0 or higher version is installed
  3. Required keys for OCI authentication.

I used below git hub code below from the Oracle Community

Alarm example

 

Steps:

1. First I clone the repository to the local system

 

2. Go to the ../example/multiplealarm directory

 

3. Rename the provider.tf.example to provider.tf and fill in the OCI provider info, region, fingerprint, private_key_path, tenancy_ocid and user_ocid.

You can check this link for more info… OCI Authentication

 

4. I created an alarm.csv file like below in the same folder, this is just an example, you can create as many rows depend on a number of alarms. 

To create an Alarm, four fields are required.. destination, display_name, query, and namespace, and other fields are optional.

In the above CSV file, the destination is basically a topic name(in my case topic name is email).

and last field create_topic, I used false as the topic already exists in my case. But if you want to create a topic as well, you can set create_topic to true

 

5. Below is my main.tf file code, where I utilize the Terraform Module “alarm” to create alarms as per my CSV file.

You can see the above code in the git repo as well I mentioned above.

 

6. Now once all files are ready, run the below commands to create alarms.

terraform init  = to initialize the OCI provider and download the module

now run 

terraform plan = To check the code and plan what it would create. (showing the partial output below).

and now we can run

terraform apply = to apply the code and create the alarms. (showing the partial output below)

 

7. Now we can check on the OCI console if these alarms were created or not.

So alarms were created. 

NOTE: We can add more columns if we need more info like trigger, body, message_format, resolution, etc.