Terraform Integration

Last updated on 03 November, 2022

The Official LogicMonitor Terraform provider, also known as an integration, is a REST API-based provider which can be used to interact with resources in LogicMonitor. With LogicMonitor and Terraform, you can model your environment by using declarative templates and then use Terraform to manage your cloud environment. You can leverage infrastructure as code to ensure that any scaling, onboarding, and offboarding is done in a controlled and repeatable manner. When you make changes to your environment using Terraform, LogicMonitor is kept in sync with the changes in the infrastructure it monitors. This ensures that services are deployed with the required monitoring, and the monitoring automatically adapts as systems or application environments are promoted from QA to staging to production.

Integrating LogicMonitor with Terraform involves building a LogicMonitor Provider and then configuring it to enable Terraform to manage your LogicMonitor resources. See the following documentation from Terraform for more information: Providers

With this integration you are able to build Terraform configurations to manage your collectors, collector groups, devices, and device groups. You are also able to add your AWS accounts to LogicMonitor through the LogicMonitor Provider in Terraform. This process requires authenticating with the LogicMonitor API so Terraform can interact with the resources in LogicMonitor.

Requirements

To build a LogicMonitor Provider plugin to integrate with Terraform, you need the following:

Building the LogicMonitor Provider Plugin

  1. Clone the following repository:
$ git clone ssh://[email protected]:logicmonitor/terraform-provider-logicmonitor
  1. Enter the provider directory and build the provider:
$ cd terraform-integration/terraform-provider-logicmonitor/
$ make

The make file generates the code, builds the binary, and copies it to the Terraform plugin directory. This completes the installation process.

Configuring the LogicMonitor Provider

You must add the following information to your Terraform configuration to enable Terraform to interact with the resources in LogicMonitor:

  • API ID
  • API Key
  • LogicMonitor portal or company name
  • Bulk Resource – (Optional) Set as true while working with bulk resources that can exceed the rate limit. The default value is false.

Note:

  • The LogicMonitor portal or company name is included in your LogicMonitor portal URL. For example, if your portal is “teamintegrations.logicmonitor.com”, your LogicMonitor portal or company name is “teamintegrations”.
  • You can use Bulk Resource to handle the resources in bulk. Please note that this is a Beta feature and can affect the performance.

To generate an API ID and Key, see API Tokens for more information about creating an API token.

You can use one of the following methods to set required arguments:

  • Provider Initialization Method
provider "logicmonitor" {
api_id = var.logicmonitor_api_id
api_key = var.logicmonitor_api_key
company = var.logicmonitor_company
bulk_resource = true //optional//
}
  • Environment Variables Method
export LM_API_ID=<your API ID>
export LM_API_KEY=<your API Key>
export LM_COMPANY=<your portal name>

Configuring the provider using the Provider Initialization method requires you to supply your credentials in the Terraform configuration file that you run. If no credentials are provided, the LogicMonitor provider code checks if the corresponding credentials are available using the Environment Variables method.

LogicMonitor Resource Management Using the LogicMonitor Terraform Provider

After you build and configure the LogicMonitor Provider plugin, you can manage the following resources using Terraform configurations:

  • Collectors
  • Collector Group
  • Devices
  • Device Group
  • AWS Accounts
  • Alert Rule
  • Escalation Chain
  • Website
  • Website Group

LogicMonitor Collector Management with the LogicMonitor Terraform Provider

The LogicMonitor Provider offers support for the following import functions for LogicMonitor Collectors:

  • import collector by ID
  • import collector group and device by ID or name
  • import device group by ID or full path

See About the LogicMonitor Collector for more information.

The following table displays the LogicMonitor API endpoints and methods use by the LogicMonitor Terraform Provider to manage the LogicMonitor Collector:

Use CaseEndpoint
Install/ProvisionAdd collector to LM account (portal)
POST /setting/collector/collectors
Assign collector to a collector groupSpecified in collectorGroupId field of body sent with POST request to add a collector (/setting/collector/collectors)
Get details for all collectorsGET /setting/collector/collectors
Get details for a single collectorGET /setting/collector/collectors/{id}
Delete collector*DELETE /setting/collector/collectors/{id}
* If a device is associated with a collector, it must be reassigned or permanently deleted before the collector can be deleted.

Collector Group Management with the LogicMonitor Terraform Provider

Grouping your Collectors into logical units can streamline account management, simplify end user permission settings, and improve efficiency.

The following table displays the LogicMonitor API endpoints and methods use by the LogicMonitor Terraform Provider to manage LogicMonitor Collector Groups:

Use CaseEndpoint
Create collector groupPOST /setting/collector/groups
Get details for all collector groupsGET /setting/collector/groups
Get details for a single collector groupGET /setting/collector/groups/{id}
Delete collector groupDELETE /setting/collector/groups/{id}

Device Management with the LogicMonitor Terraform Provider

After a device has been added and communication with that device is established, LogicMonitor adds the device to the Resources page of your LogicMonitor account. Device information is stored as system properties which are visible on the device’s Info tab.

DataSources and other LogicModules are automatically applied to the device based on the device information discovered.

The following table displays the LogicMonitor API endpoints and methods use by the LogicMonitor Terraform Provider to manage devices:

Use CaseEndpoint
Add devicePOST /device/devices
Assign device to a collectorSpecified in preferredCollectorId field of body sent with POST request to add a device (/device/devices)
Get details for all devicesGET /device/devices
Get details for a single deviceGET /device/devices/{id}
Get device propertiesGET /device/devices/{deviceId}/properties
Update devicePUT /device/devices/{id}
Update assigned collector for a deviceSpecified in preferredCollectorId field of body sent with PUT request to update a device (/device/devices/{id})
Delete deviceDELETE /device/devices/{id}

Device Group Management with the LogicMonitor Terraform Provider

Device groups allow you to organize your devices and cloud resources in LogicMonitor to make management easier by saving time when configuring alert thresholds, dashboards, reports, alert routing, and device properties.

The following table displays the LogicMonitor API endpoints and methods use by the LogicMonitor Terraform Provider to manage the device groups:

Use CaseEndpoint
Create device groupPOST /device/groups
Assign a device group to a collectorSpecified in defaultCollectorId field of body sent with POST request to add a device group (/device/groups)
Delete device groupDELETE /device/groups/{id}
Update device groupUPDATE /device/groups/{id}
Get details for all device groupsGET /device/groups
Get details for a single deviceGET /device/groups/{id}
Get device group propertiesGET /device/groups/{gid}/properties
Change assigned collector for a device groupSpecified in defaultCollectorId field of body sent with PUT request to update a device (/device/groups/{id})

AWS Account Management with the LogicMonitor Terraform Provider

Adding an AWS account involves the following steps:

  1. Provide name and other relevant information.
  2. Set access/permissions (generate aws external ID used to create role in AWS)
  3. Select monitoring services and configurations.

Note: The endpoints involved in adding, updating, deleting AWS Cloud accounts differ between the v3 & v4 API.  All v3 endpoints are the same as the add/update/delete device group endpoints (see DeviceGroupResourceV3.java). The v4 endpoints are contained in RegistrationEndpoint.java.

The following table displays the LogicMonitor API endpoints and methods use by the LogicMonitor Terraform Provider to manage an AWS account:

Use Casev3 Endpointv4 Endpoint
Get/regenerate/generate external ID (see step 2) above– GET /aws/externalId
– AWSFunctionsResourceV3.java
– Same as v3
– AWSFunctionsResourceV4.java
Add AWS servicePOST /device/groups– POST /cloudAccounts
– RegistrationEndpoint.java
Update AWS servicePUT /device/groups/{id}– PUT /cloudAccounts/{id}
– RegistrationEndpoint.java
Delete AWS serviceDELETE /device/groups/{id}– DELETE /cloudAccounts
– RegistrationEndpoint.java

Alert Rule Management with the LogicMonitor Terraform Provider

You can create, update, get, and remove alert rules in LogicMonitor through LogicMonitor Provider in Terraform. 

To manage alert rules, LogicMonitor Terraform Provider uses the following LogicMonitor API endpoints and methods:

Use CaseEndpoint
Create alert rulePOST/setting/alert/rules
Update alert rulePUT/setting/alert/rules/{id}
Delete alert ruleDELETE/setting/alert/rules/{id}
Get alert ruleGET/setting/alert/rules

For more information on adding alert rules using the LogicMonitor portal, see Alert Rules.

Escalation Chain Management with the LogicMonitor Terraform Provider

You can create, update, and remove escalation chains in LogicMonitor through LogicMonitor Provider in Terraform.

To manage escalation chain, LogicMonitor Terraform Provider uses the following LogicMonitor API endpoints and methods:

Use CaseEndpoint
Create escalation chainPOST/setting/alert/chains
Update escalation chainPUT/setting/alert/chains/{id}
Delete escalation chainDELETE/setting/alert/chains/{id}

For more information on adding escalation chain using the LogicMonitor portal, see Escalation Chains.

Website Management with the LogicMonitor Terraform Provider

You can create, update, get, and remove webcheck and pingcheck to LogicMonitor through LogicMonitor Provider in Terraform.

To manage websites, LogicMonitor Terraform Provider uses the following LogicMonitor API endpoints and methods:

Use CaseEndpoint
Create WebsitePOST /setting/website/websites
Update WebsitePUT /setting/website/websites/{id}
Delete WebsiteDELETE /setting/website/websites/{id}
Get WebsiteGET /setting/website/websites

For more information on websites monitoring using the LogicMonitor portal, see What is Websites Monitoring.

Website Group Management with the LogicMonitor Terraform Provider

You can create, update, get, and remove website group to LogicMonitor through LogicMonitor Provider in Terraform.

To manage website group, LogicMonitor Terraform Provider uses the following LogicMonitor API endpoints and methods:

Use CaseEndpoint
Create Website GroupPOST /setting/website/groups
Update Website GroupPUT /setting/website/groups/{id}
Delete Website GroupDELETE /setting/website/groups/{id}
Get Website GroupGET /setting/website/groups

For more information on adding website groups using the LogicMonitor portal, see Adding Website Groups.

In This Article