Skip to content

Commit 70ee437

Browse files
committed
Cleanup resource_sumologic_folder.go
1 parent a920b80 commit 70ee437

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

sumologic/resource_sumologic_folder.go

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,17 @@ func resourceSumologicFolder() *schema.Resource {
3939
}
4040

4141
func resourceSumologicFolderRead(d *schema.ResourceData, meta interface{}) error {
42-
log.Println("====Begin Folder Read====")
43-
4442
c := meta.(*Client)
45-
//retrieve the folder Id from the state
43+
// Retrieve the folder Id from the state
4644
id := d.Id()
47-
log.Printf("Folder Id from schema: %s", id)
45+
log.Printf("[DEBUG] Folder id from schema: %s", id)
4846

4947
folder, err := c.GetFolder(id)
50-
51-
//Error retrieving folder
5248
if err != nil {
5349
return err
5450
}
5551

56-
//ensure the Folder is populated
52+
// Ensure the Folder is populated
5753
if folder == nil {
5854
log.Printf("Folder not found, removing from state: %v - %v", id, err)
5955
d.SetId("")
@@ -66,73 +62,47 @@ func resourceSumologicFolderRead(d *schema.ResourceData, meta interface{}) error
6662
d.Set("description", folder.Description)
6763
d.SetId(folder.ID)
6864

69-
log.Println("====End Folder Read====")
7065
return nil
7166
}
7267

7368
func resourceSumologicFolderDelete(d *schema.ResourceData, meta interface{}) error {
74-
log.Println("====Begin Folder Delete====")
75-
log.Printf("Deleting Folder Id: %s", d.Id())
7669
c := meta.(*Client)
77-
log.Println("====End Folder Delete====")
70+
log.Printf("[DEBUG] Deleting folder: %s", d.Id())
7871
return c.DeleteFolder(d.Id(), d.Timeout(schema.TimeoutDelete))
7972
}
8073

8174
func resourceSumologicFolderCreate(d *schema.ResourceData, meta interface{}) error {
82-
log.Println("====Begin Folder Create====")
8375
c := meta.(*Client)
8476

85-
//If there is no id in the state, then we need to create the object
77+
// If there is no id in the state, then we need to create the object
8678
if d.Id() == "" {
87-
88-
//Load all the data we have from the schema into a Folder Struct
79+
// Load all the data we have from the schema into a Folder Struct
8980
folder := resourceToFolder(d)
90-
log.Println("Newly populated folder values:")
91-
log.Printf("ParentId: %s", folder.ParentId)
92-
log.Printf("Name: %s", folder.Name)
93-
log.Printf("Description: %s", folder.Description)
9481

95-
//Call create folder with our newly populated struct
9682
id, err := c.CreateFolder(folder)
97-
98-
//Error during CreateFolder
9983
if err != nil {
10084
return err
10185
}
10286

103-
log.Println("Saving Id to state...")
10487
d.SetId(id)
105-
log.Printf("FolderId: %s", id)
10688
}
10789

108-
log.Println("====End Folder Create====")
109-
110-
//After creating an object, we read it again to make sure the state is properly saved
11190
return resourceSumologicFolderRead(d, meta)
11291
}
11392

11493
func resourceSumologicFolderUpdate(d *schema.ResourceData, meta interface{}) error {
115-
log.Println("====Begin Folder Update====")
116-
11794
c := meta.(*Client)
11895

119-
//Load all data from the schema into a Folder Struct
96+
// Load all data from the schema into a Folder Struct
12097
folder := resourceToFolder(d)
12198

122-
log.Printf("Parent Id: %s", folder.ParentId)
123-
log.Printf("Folder Id: %s", folder.ID)
124-
log.Printf("Name: %s", folder.Name)
125-
log.Printf("Description: %s", folder.Description)
126-
127-
//Update the folder and return any errors
99+
// Update the folder and return any errors
128100
return c.UpdateFolder(folder)
129-
130101
}
131102

132103
func resourceToFolder(d *schema.ResourceData) Folder {
133-
log.Println("Loading data from schema to Folder struct...")
134-
135104
var folder Folder
105+
136106
folder.ID = d.Id()
137107
folder.ParentId = d.Get("parent_id").(string)
138108
folder.Name = d.Get("name").(string)

0 commit comments

Comments
 (0)