Skip to content

Commit

Permalink
Bug fix - Monitor group update crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Billy committed Jun 27, 2022
1 parent 82e6ad9 commit 11d9933
Show file tree
Hide file tree
Showing 28 changed files with 51 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
// Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type MonitorGroup struct {
Description string `json:"description,omitempty"`
Monitors []string `json:"monitors,omitempty"`
HealthThresholdCount int `json:"health_threshold_count,omitempty"`
DependencyResourceID []string `json:"dependency_resource_ids,omitempty"`
DependencyResourceIDs []string `json:"dependency_resource_ids,omitempty"`
SuppressAlert bool `json:"suppress_alert"`
DependencyResourceType int `json:"selection_type,omitempty"`
}
Expand Down
8 changes: 5 additions & 3 deletions docs/resources/monitor_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Use this resource to create, update and delete a monitor group in Site24x7.
## Example Usage

```hcl
// Site24x7 Monitor Group API doc - https://www.site24x7.com/help/api/#monitor-groups
resource "site24x7_monitor_group" "monitor_group_us" {
// (Required) Display Name for the Monitor Group.
Expand All @@ -24,12 +25,13 @@ resource "site24x7_monitor_group" "monitor_group_us" {
// Number of monitors' health that decide the group status. ‘0’ implies that all the monitors
// are considered for determining the group status. Default value is 1
health_threshold_count = 1
// (Optional) List of dependent resource ids.
dependency_resource_id = ["100000000005938013"]
// (Optional) List of dependent resource IDs. Suppress alert when dependent monitor(s) is down.
dependency_resource_ids = ["100000000005938013"]
// (Optional) Boolean value indicating whether to suppress alert when the dependent monitor is down
// Setting suppress_alert = true with an empty dependency_resource_id is meaningless.
suppress_alert = true
}
```

## Attributes Reference
Expand All @@ -42,7 +44,7 @@ resource "site24x7_monitor_group" "monitor_group_us" {

### Optional

* `dependency_resource_id` (List of String) List of dependent resource IDs. Suppress alert when dependent monitor(s) is down.
* `dependency_resource_ids` (List of String) List of dependent resource IDs. Suppress alert when dependent monitor(s) is down.
* `health_threshold_count` (Number) Number of monitors' health that decide the group status. ‘0’ implies that all the monitors are considered for determining the group status. Default value is 1.
* `id` (String) The ID of this resource.
* `suppress_alert` (Boolean) Boolean value indicating whether to suppress alert when the dependent monitor is down. Setting suppress_alert = true with an empty dependency_resource_id is meaningless.
Expand Down
6 changes: 3 additions & 3 deletions examples/all_resources_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
// Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
// Uncomment for local setup
# source = "registry.zoho.io/zoho/site24x7"
# version = "1.0.16"
# version = "1.0.17"
# source = "registry.terraform.io/site24x7/site24x7"
# version = "1.0.16"
# version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/amazon_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/data-sources/monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/data-sources/monitors_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/location_profile_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/monitor_group_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down Expand Up @@ -56,8 +56,8 @@ resource "site24x7_monitor_group" "monitor_group_us" {
// Number of monitors' health that decide the group status. ‘0’ implies that all the monitors
// are considered for determining the group status. Default value is 1
health_threshold_count = 1
// (Optional) List of dependent resource ids.
dependency_resource_id = ["100000000005938013"]
// (Optional) List of dependent resource IDs. Suppress alert when dependent monitor(s) is down.
dependency_resource_ids = ["100000000005938013"]
// (Optional) Boolean value indicating whether to suppress alert when the dependent monitor is down
// Setting suppress_alert = true with an empty dependency_resource_id is meaningless.
suppress_alert = true
Expand Down
2 changes: 1 addition & 1 deletion examples/notification_profile_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/opsgenie_integration_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pagerduty_integration_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rest_api_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/schedule_maintenance_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/server_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/servicenow_integration_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/slack_integration_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ssl_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tag_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/threshold_profile_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/url_it_automation_action_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/user_group_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web_page_speed_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/webhook_integration_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/website_monitor_us.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
source = "site24x7/site24x7"
# Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
version = "1.0.16"
version = "1.0.17"
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
site24x7 = {
# source = "site24x7/site24x7"
# // Update the latest version from https://registry.terraform.io/providers/site24x7/site24x7/latest
# version = "1.0.16"
# version = "1.0.17"
source = "registry.terraform.io/site24x7/site24x7"
version = "1.0.0"
}
Expand Down Expand Up @@ -66,5 +66,4 @@ resource "site24x7_website_monitor" "website_monitor_example" {
// (https://www.site24x7.com/help/api/#list-of-all-location-profiles) will be
// used.
location_profile_name = "North America"

}
25 changes: 12 additions & 13 deletions site24x7/monitor_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var MonitorGroupSchema = map[string]*schema.Schema{
Default: 1,
Description: "Number of monitors' health that decide the group status. ‘0’ implies that all the monitors are considered for determining the group status. Default value is 1.",
},
"dependency_resource_id": {
"dependency_resource_ids": {
Type: schema.TypeSet,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -153,12 +153,10 @@ func resourceDataToMonitorGroupCreate(d *schema.ResourceData) *api.MonitorGroup
}
}

var dependencyIDs []string
// If dependency_resource_id's are set in the configuration file iterate them and append to dependencyIDs
if _, monitorsExistsInConf := d.GetOk("dependency_resource_id"); monitorsExistsInConf {
for _, id := range d.Get("dependency_resource_id").([]interface{}) {
dependencyIDs = append(dependencyIDs, id.(string))
}
dependencyIDs := d.Get("dependency_resource_ids").(*schema.Set).List()
dependencyResourceIDs := make([]string, 0, len(dependencyIDs))
for _, dependencyResourceID := range dependencyIDs {
dependencyResourceIDs = append(dependencyResourceIDs, dependencyResourceID.(string))
}

return &api.MonitorGroup{
Expand All @@ -167,7 +165,7 @@ func resourceDataToMonitorGroupCreate(d *schema.ResourceData) *api.MonitorGroup
Description: d.Get("description").(string),
Monitors: monitorIDs,
HealthThresholdCount: healthThresholdCount,
DependencyResourceID: dependencyIDs,
DependencyResourceIDs: dependencyResourceIDs,
SuppressAlert: d.Get("suppress_alert").(bool),
DependencyResourceType: 2,
}
Expand Down Expand Up @@ -204,9 +202,10 @@ func resourceDataToMonitorGroupUpdate(d *schema.ResourceData, monitorGroup *api.
}
}

var dependencyResourceIDs []string
for _, dependencyID := range d.Get("dependency_resource_id").([]interface{}) {
dependencyResourceIDs = append(dependencyResourceIDs, dependencyID.(string))
dependencyIDs := d.Get("dependency_resource_ids").(*schema.Set).List()
dependencyResourceIDs := make([]string, 0, len(dependencyIDs))
for _, dependencyResourceID := range dependencyIDs {
dependencyResourceIDs = append(dependencyResourceIDs, dependencyResourceID.(string))
}

var suppressAlert bool
Expand All @@ -226,7 +225,7 @@ func resourceDataToMonitorGroupUpdate(d *schema.ResourceData, monitorGroup *api.
// Setting monitors from GET response. Empty "monitors" in PUT request dissociates all monitors from the monitor group.
Monitors: monitorGroup.Monitors,
HealthThresholdCount: healthThresholdCount,
DependencyResourceID: dependencyResourceIDs,
DependencyResourceIDs: dependencyResourceIDs,
SuppressAlert: suppressAlert,
DependencyResourceType: 2,
}
Expand All @@ -237,6 +236,6 @@ func updateMonitorGroupResourceData(d *schema.ResourceData, monitorGroup *api.Mo
d.Set("description", monitorGroup.Description)
// d.Set("monitors", monitorGroup.Monitors)
d.Set("health_threshold_count", monitorGroup.HealthThresholdCount)
d.Set("dependency_resource_id", monitorGroup.DependencyResourceID)
d.Set("dependency_resource_ids", monitorGroup.DependencyResourceIDs)
d.Set("suppress_alert", monitorGroup.SuppressAlert)
}
5 changes: 5 additions & 0 deletions site24x7/monitor_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestMonitorGroupCreate(t *testing.T) {
a := &api.MonitorGroup{
DisplayName: "foobar",
Description: "baz",
DependencyResourceIDs: []string{"234", "567"},
DependencyResourceType: 2,
}

Expand Down Expand Up @@ -121,5 +122,9 @@ func monitorGroupTestResourceData(t *testing.T) *schema.ResourceData {
"display_name": "foobar",
"description": "baz",
"selection_type": 2,
"dependency_resource_ids": []interface{}{
"234",
"567",
},
})
}

0 comments on commit 11d9933

Please sign in to comment.