Terraform Integration
Last updated on 04 September, 2024The 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:
- Go 1.15
See https://golang.org/doc/install for download and installation information. - Terraform 0.10x
See the Download Terraform information from HashiCorp for download information.
See the Install Terraform documentation from HashiCorp for installation information.
Building the LogicMonitor Provider Plugin
- Clone the following repository:
$ git clone ssh://[email protected]:logicmonitor/terraform-provider-logicmonitor
- 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 Case | Endpoint |
Install/Provision | Add collector to LM account (portal) POST /setting/collector/collectors |
Assign collector to a collector group | Specified in collectorGroupId field of body sent with POST request to add a collector (/setting/collector/collectors) |
Get details for all collectors | GET /setting/collector/collectors |
Get details for a single collector | GET /setting/collector/collectors/{id} |
Delete collector* | DELETE /setting/collector/collectors/{id} |
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 Case | Endpoint |
Create collector group | POST /setting/collector/groups |
Get details for all collector groups | GET /setting/collector/groups |
Get details for a single collector group | GET /setting/collector/groups/{id} |
Delete collector group | DELETE /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 Case | Endpoint |
Add device | POST /device/devices |
Assign device to a collector | Specified in preferredCollectorId field of body sent with POST request to add a device (/device/devices) |
Get details for all devices | GET /device/devices |
Get details for a single device | GET /device/devices/{id} |
Get device properties | GET /device/devices/{deviceId}/properties |
Update device | PUT /device/devices/{id} |
Update assigned collector for a device | Specified in preferredCollectorId field of body sent with PUT request to update a device (/device/devices/{id}) |
Delete device | DELETE /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 Case | Endpoint |
Create device group | POST /device/groups |
Assign a device group to a collector | Specified in defaultCollectorId field of body sent with POST request to add a device group (/device/groups) |
Delete device group | DELETE /device/groups/{id} |
Update device group | UPDATE /device/groups/{id} |
Get details for all device groups | GET /device/groups |
Get details for a single device | GET /device/groups/{id} |
Get device group properties | GET /device/groups/{gid}/properties |
Change assigned collector for a device group | Specified 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:
- Provide name and other relevant information.
- Set access/permissions (generate aws external ID used to create role in AWS)
- 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 Case | v3 Endpoint | v4 Endpoint |
Get/regenerate/generate external ID (see step 2) above | – GET /aws/externalId – AWSFunctionsResourceV3.java | – Same as v3 – AWSFunctionsResourceV4.java |
Add AWS service | POST /device/groups | – POST /cloudAccounts – RegistrationEndpoint.java |
Update AWS service | PUT /device/groups/{id} | – PUT /cloudAccounts/{id} – RegistrationEndpoint.java |
Delete AWS service | DELETE /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 Case | Endpoint |
Create alert rule | POST/setting/alert/rules |
Update alert rule | PUT/setting/alert/rules/{id} |
Delete alert rule | DELETE/setting/alert/rules/{id} |
Get alert rule | GET/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 Case | Endpoint |
Create escalation chain | POST/setting/alert/chains |
Update escalation chain | PUT/setting/alert/chains/{id} |
Delete escalation chain | DELETE/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 Case | Endpoint |
Create Website | POST /setting/website/websites |
Update Website | PUT /setting/website/websites/{id} |
Delete Website | DELETE /setting/website/websites/{id} |
Get Website | GET /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 Case | Endpoint |
Create Website Group | POST /setting/website/groups |
Update Website Group | PUT /setting/website/groups/{id} |
Delete Website Group | DELETE /setting/website/groups/{id} |
Get Website Group | GET /setting/website/groups |
For more information on adding website groups using the LogicMonitor portal, see Adding Website Groups.
Service Insight Management with the LogicMonitor Terraform Provider
You can create, update, get, and remove service insights through the LogicMonitor Provider in Terraform. LM™ Service Insight is based on a new LogicMonitor resource type, Services. Services comprise of instances across one or more monitored devices. DataSources with a collection method of ‘Aggregate data’ are applied to services, and the datapoints within these DataSources specify what data should be aggregated and how. Data is aggregated according to the DataSource across all instances that make up the Service.
To manage service insights through the LogicMonitor Provider in Terraform, do the following:
- Create a service using device API endpoints and methods. For more information, see Device Management with the LogicMonitor Terraform Provider.
Note: To create a service, you must add device resource from the provider with the device_type = 6.
- Add a datasource for your service using the following API endpoints and methods:
Use Case | Endpoint |
Create Service Insight | POST /setting/datasources |
Update Service Insight | PUT /setting/datasources/{id} |
Delete Service Insight | DELETE /setting/datasources/{id} |
Get Service Insight | GET /setting/datasources |
For more information on adding a service using the LogicMonitor portal, see Adding a Service.