Skip to content

Commit 0597839

Browse files
committed
Cleanup resource_sumologic_content.go
1 parent 70ee437 commit 0597839

File tree

2 files changed

+10
-48
lines changed

2 files changed

+10
-48
lines changed

sumologic/resource_sumologic_content.go

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -40,110 +40,73 @@ func resourceSumologicContent() *schema.Resource {
4040
}
4141

4242
func resourceSumologicContentRead(d *schema.ResourceData, meta interface{}) error {
43-
log.Println("====Begin Content Read====")
44-
4543
c := meta.(*Client)
46-
//retrieve the content Id from the state
44+
// Retrieve the content Id from the state
4745
id := d.Id()
48-
log.Printf("Search for Content Id: %s", id)
46+
log.Printf("[DEBUG] Looking for content with id: %s", id)
4947

50-
log.Println("Looking up content...")
5148
content, err := c.GetContent(id, d.Timeout(schema.TimeoutRead))
52-
53-
//Error retrieving content
5449
if err != nil {
5550
return err
5651
}
57-
5852
if content == nil {
5953
log.Printf("[WARN] Content not found, removing from state: %v - %v", id, err)
6054
d.SetId("")
6155
return nil
6256
}
6357

64-
log.Println("Read Values:")
65-
log.Printf("ParentId: %s", content.ParentId)
66-
log.Printf("Config: %s", content.Config)
67-
log.Printf("Name: %s", content.Name)
58+
log.Printf("[DEBUG] content: %s", content.Name)
59+
log.Printf("[DEBUG] parent of content: %s", content.ParentId)
60+
log.Printf("[DEBUG] content config: %s", content.Config)
6861

6962
// Write the newly read content object into the schema
7063
d.Set("config", content.Config)
71-
72-
log.Println("====End Content Read====")
7364
return nil
7465
}
7566

7667
func resourceSumologicContentDelete(d *schema.ResourceData, meta interface{}) error {
77-
log.Println("====Begin Content Delete====")
78-
log.Printf("Deleting Content Id: %s", d.Id())
7968
c := meta.(*Client)
80-
log.Println("====End Content Delete====")
69+
log.Printf("Deleting content with id: %s", d.Id())
8170
return c.DeleteContent(d.Id(), d.Timeout(schema.TimeoutDelete))
8271
}
8372

8473
func resourceSumologicContentCreate(d *schema.ResourceData, meta interface{}) error {
85-
log.Println("====Begin Content Create====")
8674
c := meta.(*Client)
8775

88-
//If there is no id in the state, then we need to create the object
76+
// If there is no id in the state, then we need to create the object
8977
if d.Id() == "" {
90-
91-
//Load all the data we have from the schema into a Content Struct
78+
// Load all the data we have from the schema into a Content Struct
9279
content := resourceToContent(d)
93-
log.Println("Newly populated content values:")
94-
log.Printf("ParentId: %s", content.ParentId)
95-
log.Printf("Config: %s", content.Config)
9680

97-
//Call create content with our newly populated struct
9881
id, err := c.CreateOrUpdateContent(*content, d.Timeout(schema.TimeoutCreate), false)
99-
100-
//Error during CreateOrUpdateContent
10182
if err != nil {
10283
return err
10384
}
10485

105-
log.Println("Saving Id to state...")
10686
d.SetId(id)
107-
log.Printf("ContentId: %s", id)
108-
log.Printf("ContentType: %s", content.Type)
109-
87+
log.Printf("Created content with id=%s, type=%s", id, content.Type)
11088
}
11189

112-
log.Println("====End Content Create====")
113-
114-
//After creating an object, we read it again to make sure the state is properly saved
11590
return resourceSumologicContentRead(d, meta)
11691
}
11792

11893
func resourceSumologicContentUpdate(d *schema.ResourceData, meta interface{}) error {
119-
log.Println("====Begin Content Update====")
12094
c := meta.(*Client)
12195

122-
//Load all data from the schema into a Content Struct
12396
content := resourceToContent(d)
12497

125-
//Call create content with overwrite set to true
12698
id, err := c.CreateOrUpdateContent(*content, d.Timeout(schema.TimeoutUpdate), true)
127-
128-
//Error during CreateOrUpdateContent
12999
if err != nil {
130100
return err
131101
}
132102

133-
log.Println("Saving Id to state...")
134103
d.SetId(id)
135-
log.Printf("ContentId: %s", id)
136-
log.Printf("ContentType: %s", content.Type)
104+
log.Printf("Updated content with id=%s, type=%s", id, content.Type)
137105

138-
log.Println("====End Content Update====")
139-
140-
//After updating an object, we read it to make sure the state is properly saved
141106
return resourceSumologicContentRead(d, meta)
142-
143107
}
144108

145109
func resourceToContent(d *schema.ResourceData) *Content {
146-
log.Println("Loading data from schema to Content struct...")
147110
var content Content
148111

149112
_ = json.Unmarshal([]byte(d.Get("config").(string)), &content)

sumologic/sumologic_content.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ func (s *Client) CreateOrUpdateContent(content Content, timeout time.Duration, o
102102

103103
// extract id of newly created content
104104
contentId := strings.Split(status.StatusMessage, ":")[1]
105-
log.Printf("New content id: %s", contentId)
106105
return contentId, nil
107106
}
108107

0 commit comments

Comments
 (0)