Skip to content

Commit

Permalink
Merge pull request #95 from logicmonitor/DEV-171165-ProviderFixAndAut…
Browse files Browse the repository at this point in the history
…oDiscoveryFeatureUpdate

Auto Discovery Feature Added And Provider Documentation Update
  • Loading branch information
lm-madhvi authored Jul 5, 2024
2 parents af7d630 + 343897e commit 8c053bc
Show file tree
Hide file tree
Showing 28 changed files with 1,216 additions and 124 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ provider "logicmonitor" {
api_id = var.logicmonitor_api_id
api_key = var.logicmonitor_api_key
company = var.logicmonitor_company
bulk_resource = true/false
"When working with bulk resources, this feature is optional to handle the API's rate limit"
}
```
Example usage can be found in the /terraform-integration/examples directory.
Expand Down
31 changes: 30 additions & 1 deletion examples/datasource/datasource.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
resource "logicmonitor_datasource" "my_datasource"{
collect_interval = 100
has_multi_instances = true
applies_to = "system.deviceId == \"22\""
description = "test"
collect_method = "script"
eri_discovery_interval = 1
eri_discovery_interval = 15
enable_auto_discovery = true
enable_eri_discovery = true
eri_discovery_config {
name = "ad_script"
win_script = "string"
groovy_script = "string"
type = "string"
linux_cmdline = "string"
linux_script = "string"
win_cmdline = "string"
}
name = "Amazon Website test"
auto_discovery_config {
persistent_instance = false
schedule_interval = 0
delete_inactive_instance = true
method {
name = "ad_script"
}
instance_auto_group_method = "none"
instance_auto_group_method_params = ""
filters = [
{
comment = "test"
value = "test"
operation = "string"
attribute = "string"
}]
disable_instance = true
}
data_points = [{
name = "CallCountTotal_mean8"
description = "test"
Expand Down
31 changes: 30 additions & 1 deletion examples/datasource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@

resource "logicmonitor_datasource" "my_datasource"{
collect_interval = 100
has_multi_instances = true
applies_to = "system.deviceId == \"22\""
description = "test"
collect_method = "script"
eri_discovery_interval = 1
eri_discovery_interval = 15
enable_auto_discovery = true
enable_eri_discovery = true
eri_discovery_config {
name = "ad_script"
win_script = "string"
groovy_script = "string"
type = "string"
linux_cmdline = "string"
linux_script = "string"
win_cmdline = "string"
}
name = "Amazon Website test"
auto_discovery_config {
persistent_instance = false
schedule_interval = 0
delete_inactive_instance = true
method {
name = "ad_script"
}
instance_auto_group_method = "none"
instance_auto_group_method_params = ""
filters = [
{
comment = "test"
value = "test"
operation = "string"
attribute = "string"
}]
disable_instance = true
}
data_points = [{
name = "CallCountTotal_mean8"
description = "test"
Expand Down
1 change: 1 addition & 0 deletions examples/website/datasource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resource "logicmonitor_website" "my_website"{
description = "website test"
disable_alerting = true
stop_monitoring = true
schema = "http"
user_permission = "string"
test_location = [
{
Expand Down
1 change: 1 addition & 0 deletions examples/website/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resource "logicmonitor_website" "my_website"{
description = "website test"
disable_alerting = true
stop_monitoring = true
schema = "http"
user_permission = "string"
test_location = [
{
Expand Down
123 changes: 123 additions & 0 deletions logicmonitor/schemata/auto_discovery_configuration_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package schemata

import (
"terraform-provider-logicmonitor/logicmonitor/utils"
"terraform-provider-logicmonitor/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func AutoDiscoveryConfigurationSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"data_source_name": {
Type: schema.TypeString,
Computed: true,
},

"delete_inactive_instance": {
Type: schema.TypeBool,
Optional: true,
},

"disable_instance": {
Type: schema.TypeBool,
Optional: true,
},

"filters": {
Type: schema.TypeList, //GoType: []*AutoDiscoveryFilter
Elem: &schema.Resource{
Schema: AutoDiscoveryFilterSchema(),
},
ConfigMode: schema.SchemaConfigModeAttr,
Optional: true,
},

"instance_auto_group_method": {
Type: schema.TypeString,
Optional: true,
},

"instance_auto_group_method_params": {
Type: schema.TypeString,
Optional: true,
},

"method": {
Type: schema.TypeList, //GoType: AutoDiscoveryMethod
Elem: &schema.Resource{
Schema: AutoDiscoveryMethodSchema(),
},
Required: true,
},

"persistent_instance": {
Type: schema.TypeBool,
Optional: true,
},

"schedule_interval": {
Type: schema.TypeInt,
Optional: true,
},

}
}

func SetAutoDiscoveryConfigurationSubResourceData(m []*models.AutoDiscoveryConfiguration) (d []*map[string]interface{}) {
for _, autoDiscoveryConfiguration := range m {
if autoDiscoveryConfiguration != nil {
properties := make(map[string]interface{})
properties["data_source_name"] = autoDiscoveryConfiguration.DataSourceName
properties["delete_inactive_instance"] = autoDiscoveryConfiguration.DeleteInactiveInstance
properties["disable_instance"] = autoDiscoveryConfiguration.DisableInstance
properties["filters"] = SetAutoDiscoveryFilterSubResourceData(autoDiscoveryConfiguration.Filters)
properties["instance_auto_group_method"] = autoDiscoveryConfiguration.InstanceAutoGroupMethod
properties["instance_auto_group_method_params"] = autoDiscoveryConfiguration.InstanceAutoGroupMethodParams
properties["method"] = SetAutoDiscoveryMethodSubResourceData([]*models.AutoDiscoveryMethod{autoDiscoveryConfiguration.Method})
properties["persistent_instance"] = autoDiscoveryConfiguration.PersistentInstance
properties["schedule_interval"] = autoDiscoveryConfiguration.ScheduleInterval
d = append(d, &properties)
}
}
return
}

func AutoDiscoveryConfigurationModel(d map[string]interface{}) *models.AutoDiscoveryConfiguration {
// assume that the incoming map only contains the relevant resource data
deleteInactiveInstance := d["delete_inactive_instance"].(bool)
disableInstance := d["disable_instance"].(bool)
filters := utils.GetFilters(d["filters"].([]interface{}))
instanceAutoGroupMethod := d["instance_auto_group_method"].(string)
instanceAutoGroupMethodParams := d["instance_auto_group_method_params"].(string)
var method *models.AutoDiscoveryMethod = nil
methodList := d["method"].([]interface{})
if len(methodList) > 0 { // len(nil) = 0
method = AutoDiscoveryMethodModel(methodList[0].(map[string]interface{}))
}
persistentInstance := d["persistent_instance"].(bool)
scheduleInterval := int32(d["schedule_interval"].(int))

return &models.AutoDiscoveryConfiguration {
DeleteInactiveInstance: deleteInactiveInstance,
DisableInstance: disableInstance,
Filters: filters,
InstanceAutoGroupMethod: instanceAutoGroupMethod,
InstanceAutoGroupMethodParams: instanceAutoGroupMethodParams,
Method: method,
PersistentInstance: persistentInstance,
ScheduleInterval: scheduleInterval,
}
}

func GetAutoDiscoveryConfigurationPropertyFields() (t []string) {
return []string{
"delete_inactive_instance",
"disable_instance",
"filters",
"instance_auto_group_method",
"instance_auto_group_method_params",
"method",
"persistent_instance",
"schedule_interval",
}
}
69 changes: 69 additions & 0 deletions logicmonitor/schemata/auto_discovery_filter_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package schemata

import (
"terraform-provider-logicmonitor/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func AutoDiscoveryFilterSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"attribute": {
Type: schema.TypeString,
Required: true,
},

"comment": {
Type: schema.TypeString,
Optional: true,
},

"operation": {
Type: schema.TypeString,
Required: true,
},

"value": {
Type: schema.TypeString,
Optional: true,
},

}
}

func SetAutoDiscoveryFilterSubResourceData(m []*models.AutoDiscoveryFilter) (d []*map[string]interface{}) {
for _, autoDiscoveryFilter := range m {
if autoDiscoveryFilter != nil {
properties := make(map[string]interface{})
properties["attribute"] = autoDiscoveryFilter.Attribute
properties["comment"] = autoDiscoveryFilter.Comment
properties["operation"] = autoDiscoveryFilter.Operation
properties["value"] = autoDiscoveryFilter.Value
d = append(d, &properties)
}
}
return
}

func AutoDiscoveryFilterModel(d map[string]interface{}) *models.AutoDiscoveryFilter {
// assume that the incoming map only contains the relevant resource data
attribute := d["attribute"].(string)
comment := d["comment"].(string)
operation := d["operation"].(string)
value := d["value"].(string)

return &models.AutoDiscoveryFilter {
Attribute: &attribute,
Comment: comment,
Operation: &operation,
Value: value,
}
}

func GetAutoDiscoveryFilterPropertyFields() (t []string) {
return []string{
"attribute",
"comment",
"operation",
"value",
}
}
42 changes: 42 additions & 0 deletions logicmonitor/schemata/auto_discovery_method_schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package schemata

import (
"terraform-provider-logicmonitor/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func AutoDiscoveryMethodSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

}
}

func SetAutoDiscoveryMethodSubResourceData(m []*models.AutoDiscoveryMethod) (d []*map[string]interface{}) {
for _, autoDiscoveryMethod := range m {
if autoDiscoveryMethod != nil {
properties := make(map[string]interface{})
properties["name"] = autoDiscoveryMethod.Name
d = append(d, &properties)
}
}
return
}

func AutoDiscoveryMethodModel(d map[string]interface{}) *models.AutoDiscoveryMethod {
// assume that the incoming map only contains the relevant resource data
name := d["name"].(string)

return &models.AutoDiscoveryMethod {
Name: &name,
}
}

func GetAutoDiscoveryMethodPropertyFields() (t []string) {
return []string{
"name",
}
}
Loading

0 comments on commit 8c053bc

Please sign in to comment.