-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from logicmonitor/DEV-171165-ProviderFixAndAut…
…oDiscoveryFeatureUpdate Auto Discovery Feature Added And Provider Documentation Update
- Loading branch information
Showing
28 changed files
with
1,216 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
logicmonitor/schemata/auto_discovery_configuration_schema.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} |
Oops, something went wrong.