Skip to content

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

Manoj Kumar Aug 13, 2024 11:00:00 AM
How to Automate Creation of Multiple OCI Alarms using Terraform Observability Module
2:26

alarms

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

alarms2

 

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

alarms3

 

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

alarms4

 

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.

alarms5

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.

alarms6

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

alarms7

now run 

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

alarms8

and now we can run

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

alarms9

 

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

alarms10

So alarms were created. 

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

Leave a Comment