Skip to content

Commit f0dc950

Browse files
committed
Merge branch 'master' into vishal-search-tf-resource
2 parents 69ef4af + d46bd98 commit f0dc950

13 files changed

+647
-29
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.22.1 (Unreleased)
2-
2+
FEATURES:
3+
* resource/sumologic_slo: Added support for associating tags with an SLO
34
## 2.22.0 (March 23, 2023)
45
FEATURES:
56
* resource/sumologic_monitor: Added support for creating SLO Monitors with multiple burn rates (GH-499)

GNUmakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ WEBSITE_REPO=github.com/hashicorp/terraform-website
44
PKG_NAME=sumologic
55
PLUGIN_DIR=~/.terraform.d/plugins
66
UNAME=$(shell uname -m)
7+
DEBUG_FLAGS=-gcflags="all=-N -l"
78

89
default: build
910

@@ -22,9 +23,9 @@ install: fmtcheck
2223
install-dev: fmtcheck
2324
mkdir -vp $(PLUGIN_DIR)
2425
ifeq ($(UNAME), arm64)
25-
go build -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
26+
go build ${DEBUG_FLAGS} -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
2627
else
27-
go build -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_amd64/terraform-provider-sumologic
28+
go build ${DEBUG_FLAGS} -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_amd64/terraform-provider-sumologic
2829
endif
2930

3031
uninstall:

sumologic/resource_sumologic_content.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sumologic
33
import (
44
"encoding/json"
55
"log"
6+
"strings"
67
"time"
78

89
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -28,6 +29,7 @@ func resourceSumologicContent() *schema.Resource {
2829
ValidateFunc: validation.StringIsJSON,
2930
Required: true,
3031
DiffSuppressFunc: structure.SuppressJsonDiff,
32+
StateFunc: configStateFunc,
3133
},
3234
},
3335
Timeouts: &schema.ResourceTimeout{
@@ -39,6 +41,73 @@ func resourceSumologicContent() *schema.Resource {
3941
}
4042
}
4143

44+
func configStateFunc(value interface{}) string {
45+
return normalizeConfig(value.(string))
46+
}
47+
48+
// modify json config to remove logically equivalent changes in terrafrom diff output
49+
// e.g. absent map entry vs map entry with null value
50+
// or absent map entry vs map entry with default value
51+
func normalizeConfig(originalConfig string) string {
52+
config, err := structure.ExpandJsonFromString(originalConfig)
53+
54+
if err != nil {
55+
log.Println("Couldn't expand config json from string")
56+
return originalConfig
57+
}
58+
59+
removeEmptyValues(config)
60+
fillPanelQueriesDefaultValues(config)
61+
62+
if config["theme"] != nil {
63+
config["theme"] = strings.ToLower(config["theme"].(string))
64+
}
65+
66+
children, ok := config["children"].([]interface{})
67+
if ok {
68+
for _, childItemObject := range children {
69+
childItemMap, ok := childItemObject.(map[string]interface{})
70+
if ok {
71+
fillPanelQueriesDefaultValues(childItemMap)
72+
}
73+
}
74+
}
75+
configString, err := structure.FlattenJsonToString(config)
76+
if err != nil {
77+
log.Println("Couldn't flatten config json to string")
78+
return originalConfig
79+
}
80+
81+
return configString
82+
}
83+
84+
func fillPanelQueriesDefaultValues(config map[string]interface{}) {
85+
if config["panels"] != nil {
86+
panels := config["panels"].([]interface{})
87+
88+
for _, panelInterface := range panels {
89+
panelItem := panelInterface.(map[string]interface{})
90+
91+
for range panelItem {
92+
if panelItem["queries"] != nil {
93+
queries := panelItem["queries"].([]interface{})
94+
for _, queryInterface := range queries {
95+
queryItem := queryInterface.(map[string]interface{})
96+
97+
if queryItem["outputCardinalityLimit"] == nil {
98+
queryItem["outputCardinalityLimit"] = 1000
99+
}
100+
101+
if queryItem["transient"] == nil {
102+
queryItem["transient"] = false
103+
}
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}
110+
42111
func resourceSumologicContentRead(d *schema.ResourceData, meta interface{}) error {
43112
c := meta.(*Client)
44113
// Retrieve the content Id from the state
@@ -61,6 +130,9 @@ func resourceSumologicContentRead(d *schema.ResourceData, meta interface{}) erro
61130

62131
// Write the newly read content object into the schema
63132
d.Set("config", content.Config)
133+
134+
normalizedConfig := normalizeConfig(content.Config)
135+
d.Set("config", normalizedConfig)
64136
return nil
65137
}
66138

sumologic/resource_sumologic_kinesis_log_source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func resourceSumologicKinesisLogSource() *schema.Resource {
3636
}
3737
kinesisLogSource.Schema["authentication"] = &schema.Schema{
3838
Type: schema.TypeList,
39-
Optional: true,
39+
Required: true,
4040
MaxItems: 1,
4141
Elem: &schema.Resource{
4242
Schema: map[string]*schema.Schema{
@@ -63,7 +63,7 @@ func resourceSumologicKinesisLogSource() *schema.Resource {
6363

6464
kinesisLogSource.Schema["path"] = &schema.Schema{
6565
Type: schema.TypeList,
66-
Optional: true,
66+
Required: true,
6767
MaxItems: 1,
6868
Elem: &schema.Resource{
6969
Schema: map[string]*schema.Schema{

sumologic/resource_sumologic_slo.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ func resourceSumologicSLO() *schema.Resource {
276276
},
277277
},
278278
},
279+
"tags": {
280+
Type: schema.TypeMap,
281+
Optional: true,
282+
Elem: &schema.Schema{
283+
Type: schema.TypeString,
284+
},
285+
},
279286
"is_mutable": {
280287
Type: schema.TypeBool,
281288
Optional: true,
@@ -366,6 +373,7 @@ func resourceSLORead(d *schema.ResourceData, meta interface{}) error {
366373
d.Set("is_system", slo.IsSystem)
367374
d.Set("service", slo.Service)
368375
d.Set("application", slo.Application)
376+
d.Set("tags", slo.Tags)
369377

370378
flatCompliance, err := flattenSLOCompliance(slo.Compliance)
371379
if err != nil {
@@ -561,6 +569,7 @@ func resourceToSLO(d *schema.ResourceData) (*SLOLibrarySLO, error) {
561569
Indicator: *indicator,
562570
Service: d.Get("service").(string),
563571
Application: d.Get("application").(string),
572+
Tags: d.Get("tags").(map[string]interface{}),
564573
}
565574

566575
err = verifySLOObject(slo)

0 commit comments

Comments
 (0)