Skip to content

Commit 1530439

Browse files
authored
Merge pull request #219 from SumoLogic/vishal-fix-terraform-job
2 parents a3b4003 + 84a9d04 commit 1530439

8 files changed

+55
-300
lines changed

sumologic/data_source_sumologic_personal_folder.go

100755100644
File mode changed.

sumologic/resource_sumologic_content.go

100755100644
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/resource_sumologic_content_test.go

100755100644
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1010
)
1111

12-
//Testing create functionality for Content resources
1312
func TestAccContent_create(t *testing.T) {
1413
var content Content
1514

@@ -90,23 +89,23 @@ func testAccCheckContentDestroy(content Content) resource.TestCheckFunc {
9089
client := testAccProvider.Meta().(*Client)
9190
_, err := client.GetContent(content.ID, time.Minute)
9291
if err == nil {
93-
return fmt.Errorf("Content still exists")
92+
return fmt.Errorf("Content(id=%s) still exists", content.ID)
9493
}
9594
return nil
9695
}
9796
}
9897

9998
var updateConfigJson = `{
10099
"type": "SavedSearchWithScheduleSyncDefinition",
101-
"name": "test-121",
100+
"name": "tf-content-scheduled-search-01",
102101
"search": {
103102
"queryText": "\"warn\"",
104103
"defaultTimeRange": "-15m",
105104
"byReceiptTime": false,
106105
"viewName": "",
107106
"viewStartTime": "1970-01-01T00:00:00Z",
108107
"queryParameters": [],
109-
"parsingMode": "AutoParse"
108+
"parsingMode": "Manual"
110109
},
111110
"searchSchedule": {
112111
"cronExpression": "0 0 * * * ? *",
@@ -139,15 +138,15 @@ var updateConfigJson = `{
139138

140139
var configJson = `{
141140
"type": "SavedSearchWithScheduleSyncDefinition",
142-
"name": "test-121",
141+
"name": "tf-content-scheduled-search-01",
143142
"search": {
144143
"queryText": "\"error\"",
145144
"defaultTimeRange": "-15m",
146145
"byReceiptTime": false,
147146
"viewName": "",
148147
"viewStartTime": "1970-01-01T00:00:00Z",
149148
"queryParameters": [],
150-
"parsingMode": "AutoParse"
149+
"parsingMode": "Manual"
151150
},
152151
"searchSchedule": {
153152
"cronExpression": "0 0 * * * ? *",

sumologic/resource_sumologic_folder.go

100755100644
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)

sumologic/resource_sumologic_folder_test.go

100755100644
File mode changed.

sumologic/sumologic_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ func NewClient(accessID, accessKey, environment, base_url string) (*Client, erro
312312
}
313313

314314
type Error struct {
315-
Code string `json:"status"`
315+
Code string `json:"code"`
316316
Message string `json:"message"`
317317
Detail string `json:"detail"`
318318
}
319319

320320
type Status struct {
321-
Status string `json:"status"`
322-
StatusMessage string `json:"statusMessage"`
323-
Errors []Error `json:"errors"`
321+
Status string `json:"status"`
322+
StatusMessage string `json:"statusMessage"`
323+
Error Error `json:"error"`
324324
}
325325

326326
type FolderUpdate struct {

0 commit comments

Comments
 (0)