@@ -3,20 +3,16 @@ package sumologic
33import (
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
1111func 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-
163117func 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