Skip to content

Commit d723970

Browse files
author
Sean Sain
committed
forcing new resource on update, and fix json equivalency code
1 parent 6b86b37 commit d723970

File tree

2 files changed

+14
-62
lines changed

2 files changed

+14
-62
lines changed

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1U
8787
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
8888
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
8989
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
90+
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
9091
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
92+
github.com/bmatcuk/doublestar v1.1.5 h1:2bNwBOmhyFEFcoB3tGvTD5xanq+4kyOZlB8wFYbMjkk=
9193
github.com/bmatcuk/doublestar v1.1.5/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
9294
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
9395
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -207,6 +209,7 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh
207209
github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
208210
github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
209211
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
212+
github.com/hashicorp/go-retryablehttp v0.5.2 h1:AoISa4P4IsW0/m4T6St8Yw38gTl5GtBAgfkhYh1xAz4=
210213
github.com/hashicorp/go-retryablehttp v0.5.2/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
211214
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
212215
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
@@ -232,6 +235,7 @@ github.com/hashicorp/hcl/v2 v2.0.0 h1:efQznTz+ydmQXq3BOnRa3AXzvCeTq1P4dKj/z5GLlY
232235
github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90=
233236
github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE=
234237
github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8=
238+
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 h1:2yzhWGdgQUWZUCNK+AoO35V+HTsgEmcM4J9IkArh7PI=
235239
github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE=
236240
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
237241
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
@@ -334,6 +338,7 @@ github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eI
334338
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
335339
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
336340
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
341+
github.com/mitchellh/hashstructure v1.0.0 h1:ZkRJX1CyOoTkar7p/mLS5TZU4nJ1Rn/F8u9dGS02Q3Y=
337342
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
338343
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
339344
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=

sumologic/resource_sumologic_content.go

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ package sumologic
33
import (
44
"encoding/json"
55
"log"
6-
"reflect"
76

87
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
99
)
1010

1111
func resourceSumologicContent() *schema.Resource {
1212
return &schema.Resource{
1313
Create: resourceSumologicContentCreate,
1414
Read: resourceSumologicContentRead,
1515
Delete: resourceSumologicContentDelete,
16-
Update: resourceSumologicContentUpdate,
17-
// Importer: &schema.ResourceImporter{
18-
// State: resourceSumologicContentImport,
19-
// },
2016

2117
Schema: map[string]*schema.Schema{
2218
"parent_id": {
@@ -27,30 +23,15 @@ func resourceSumologicContent() *schema.Resource {
2723
"config": {
2824
Type: schema.TypeString,
2925
Required: true,
30-
ForceNew: false,
26+
ForceNew: true,
27+
StateFunc: func(v interface{}) string {
28+
json, _ := structure.NormalizeJsonString(v)
29+
return json
30+
},
3131
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
32-
log.Println("====Begin Config Comparison====")
33-
//convert the json strings to content structs for comparison
34-
var a Content
35-
var b Content
36-
err := json.Unmarshal([]byte(old), &a)
37-
log.Println("old config:")
38-
log.Println(a)
39-
log.Println(err)
40-
41-
err = json.Unmarshal([]byte(new), &b)
42-
log.Println("new config:")
43-
log.Println(b)
44-
log.Println(err)
45-
46-
//Set the Children element for each content object to an empty array
47-
a.Children = []Content{}
48-
b.Children = []Content{}
49-
//Make the comparison
50-
result := reflect.DeepEqual(a, b)
51-
log.Printf("Equivalent: %t", result)
52-
log.Println("====End Config Comparison====")
53-
return result
32+
newJSON, _ := structure.NormalizeJsonString(new)
33+
oldJSON, _ := structure.NormalizeJsonString(old)
34+
return newJSON == oldJSON
5435
},
5536
},
5637
},
@@ -133,33 +114,6 @@ func resourceSumologicContentCreate(d *schema.ResourceData, meta interface{}) er
133114
return resourceSumologicContentRead(d, meta)
134115
}
135116

136-
func resourceSumologicContentUpdate(d *schema.ResourceData, meta interface{}) error {
137-
log.Println("====Begin Content Update====")
138-
139-
c := meta.(*Client)
140-
141-
//Load all data from the schema into a Content Struct
142-
content := resourceToContent(d)
143-
144-
log.Printf("Parent Id: %s", content.ParentId)
145-
log.Printf("Content Id: %s", content.ID)
146-
147-
//Due to API limitations, updating contentobjects means they must be deleted & remade
148-
log.Printf("Deleting Content with Id: %s", content.ID)
149-
err := c.DeleteContent(content.ID)
150-
151-
//error during delete operation
152-
if err != nil {
153-
return err
154-
}
155-
156-
// reset the Id and remake the object with new config
157-
d.SetId("")
158-
159-
log.Println("Remaking Deleted Content...")
160-
return resourceSumologicContentCreate(d, meta)
161-
}
162-
163117
func resourceToContent(d *schema.ResourceData) *Content {
164118
log.Println("Loading data from schema to Content struct...")
165119
var content Content
@@ -173,10 +127,3 @@ func resourceToContent(d *schema.ResourceData) *Content {
173127

174128
return &content
175129
}
176-
177-
//func resourceSumologicContentImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {
178-
// if err := resourceSumologicContentRead(d, m); err != nil {
179-
// return nil, err
180-
// }
181-
// return []*schema.ResourceData{d}, nil
182-
//}

0 commit comments

Comments
 (0)