Skip to content

Commit 9c60ed2

Browse files
author
Ashish Gaurav
committed
[Monitors] fix folder update logic and docs
Took 3 hours 47 minutes
1 parent 4cb4d46 commit 9c60ed2

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

sumologic/resource_sumologic_slo.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func resourceSumologicSLO() *schema.Resource {
4444
Type: schema.TypeList,
4545
Required: true,
4646
MinItems: 1,
47-
MaxItems: 1,
47+
MaxItems: 6,
4848
Elem: &schema.Resource{
4949
Schema: map[string]*schema.Schema{
5050
"query_group_type": {
@@ -113,7 +113,6 @@ func resourceSumologicSLO() *schema.Resource {
113113
"aggregation": {
114114
Type: schema.TypeString,
115115
Optional: true,
116-
Default: "Avg",
117116
ValidateFunc: validation.StringMatch(aggrRegex, `value must match : `+sloAggregationRegexString),
118117
},
119118
"size": {
@@ -309,7 +308,7 @@ func resourceSumologicSLOCreate(d *schema.ResourceData, meta interface{}) error
309308
func resourceSLORead(d *schema.ResourceData, meta interface{}) error {
310309
c := meta.(*Client)
311310

312-
slo, err := c.SLORead(d.Id(), nil)
311+
slo, err := c.SLORead(d.Id())
313312
if err != nil {
314313
return err
315314
}
@@ -623,11 +622,18 @@ func resourceSumologicSLOUpdate(d *schema.ResourceData, meta interface{}) error
623622

624623
slo.Type = "SlosLibrarySloUpdate"
625624
if d.HasChange("parent_id") {
626-
err := c.MoveSLOLibraryToFolder(*slo)
625+
err := c.MoveSLOLibraryToFolder(slo.ID, slo.ParentID)
627626
if err != nil {
628627
return err
629628
}
630629
}
630+
sloUpdated, err := c.SLORead(d.Id())
631+
632+
if err != nil {
633+
return err
634+
}
635+
slo.Version = sloUpdated.Version
636+
slo.ModifiedAt = sloUpdated.ModifiedAt
631637

632638
err = c.UpdateSLO(*slo)
633639
if err != nil {

sumologic/resource_sumologic_slo_folder.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,22 @@ func resourceSumologicSLOLibraryFolderUpdate(d *schema.ResourceData, meta interf
162162
c := meta.(*Client)
163163
sloFolder := resourceToSLOLibraryFolder(d)
164164
sloFolder.Type = "SlosLibraryFolderUpdate"
165-
err := c.UpdateSLOLibraryFolder(sloFolder)
165+
if d.HasChange("parent_id") {
166+
err := c.MoveSLOLibraryToFolder(sloFolder.ID, sloFolder.ParentID)
167+
if err != nil {
168+
return err
169+
}
170+
}
171+
172+
updatedFolder, err := c.GetSLOLibraryFolder(d.Id())
173+
if err != nil {
174+
return err
175+
}
176+
177+
sloFolder.ModifiedAt = updatedFolder.ModifiedAt
178+
sloFolder.Version = updatedFolder.Version
179+
180+
err = c.UpdateSLOLibraryFolder(sloFolder)
166181
if err != nil {
167182
return err
168183
}

sumologic/sumologic_slo_library_slo.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (s *Client) CreateSLO(slo SLOLibrarySLO, paramMap map[string]string) (strin
3838
return createdSLO.ID, nil
3939
}
4040

41-
func (s *Client) SLORead(id string, paramMap map[string]string) (*SLOLibrarySLO, error) {
41+
func (s *Client) SLORead(id string) (*SLOLibrarySLO, error) {
4242
urlWithoutParams := SLOBaseApiUrl + "/%s"
4343
paramString := ""
4444
sprintfArgs := []interface{}{}
@@ -93,21 +93,19 @@ func (s *Client) UpdateSLO(slo SLOLibrarySLO) error {
9393
return err
9494
}
9595

96-
func (s *Client) MoveSLOLibraryToFolder(slo SLOLibrarySLO) error {
97-
urlWithoutParams := SLOBaseApiUrl + "/%s"
96+
func (s *Client) MoveSLOLibraryToFolder(id, parentId string) error {
97+
urlWithoutParams := SLOBaseApiUrl + "/%s/move"
9898
paramString := ""
9999
sprintfArgs := []interface{}{}
100-
sprintfArgs = append(sprintfArgs, slo.ID)
100+
sprintfArgs = append(sprintfArgs, id)
101101

102102
paramString += "?"
103-
queryParam := fmt.Sprintf("parentId=%s&", slo.ParentID)
103+
queryParam := fmt.Sprintf("parentId=%s&", parentId)
104104
paramString += queryParam
105105

106106
urlWithParams := fmt.Sprintf(urlWithoutParams+paramString, sprintfArgs...)
107107

108-
slo.ID = ""
109-
110-
_, err := s.Put(urlWithParams, slo)
108+
_, err := s.Post(urlWithParams, nil)
111109

112110
return err
113111
}

website/docs/r/slo.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ The following arguments are supported:
8989
- `parent_id` - (Optional) The ID of the SLO Folder that contains this SLO. Defaults to the root folder.
9090
- `signal_type` - (Required) The type of SLO. Valid values are `Latency`, `Error`, `Throughput`, `Availability`
9191
, `Other`. Defaults to `Latency`.
92-
- `service` - (Optional) The notifications the SLO will send when the respective trigger condition is met.
93-
- `application` - (Optional) Whether to group notifications for individual items that meet the trigger condition.
92+
- `service` - (Optional) Name of the service.
93+
- `application` - (Optional) Name of the application.
9494
Defaults to true.
9595
- `compliance` - (Required) The compliance settings for the SLO.
9696
- `compliance_type` - (Required) The type of compliance to use. Valid values are `Rolling` or `Calendar`.

website/docs/r/slo_folder.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "sumologic_slo_folder" "tf_slo_folder" {
2626
2727
resource "sumologic_slo_folder" "tf_slo_folder" {
2828
name = "slo-tf-folder"
29-
description = "Root folder for SLO created for testing"
29+
description = "folder for SLO created for testing"
3030
parent_id = "0000000000000001"
3131
}
3232

0 commit comments

Comments
 (0)