Skip to content

Commit

Permalink
Merge pull request #512 from terraform-providers/gzu/bump_client
Browse files Browse the repository at this point in the history
  • Loading branch information
gzussa authored May 13, 2020
2 parents 39c5e27 + f623793 commit 79f6816
Show file tree
Hide file tree
Showing 70 changed files with 2,583 additions and 2,023 deletions.
11 changes: 8 additions & 3 deletions datadog/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

c := cleanhttp.DefaultClient()
c.Transport = logging.NewTransport("Datadog", c.Transport)
communityClient.ExtraHeader["User-Agent"] = getUserAgent("")
communityClient.ExtraHeader["User-Agent"] = getUserAgent(fmt.Sprintf(
"datadog-api-client-go/%s (go %s; os %s; arch %s)",
"go-datadog-api",
runtime.Version(),
runtime.GOOS,
runtime.GOARCH,
))
communityClient.HttpClient = c

if validate {
Expand Down Expand Up @@ -228,9 +234,8 @@ func translateClientError(err error, msg string) error {
}

func getUserAgent(clientUserAgent string) string {
return fmt.Sprintf("terraform-provider-datadog/%s (go %s; terraform %s; terraform-cli %s) %s",
return fmt.Sprintf("terraform-provider-datadog/%s (terraform %s; terraform-cli %s) %s",
version.ProviderVersion,
runtime.Version(),
meta.SDKVersionString(),
datadogProvider.TerraformVersion,
clientUserAgent)
Expand Down
28 changes: 21 additions & 7 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func resourceDatadogMonitor() *schema.Resource {
}
}

func buildMonitorStruct(d *schema.ResourceData) *datadogV1.Monitor {
func buildMonitorStruct(d *schema.ResourceData) (*datadogV1.Monitor, *datadogV1.MonitorUpdateRequest) {

var thresholds datadogV1.MonitorThresholds

Expand Down Expand Up @@ -296,6 +296,13 @@ func buildMonitorStruct(d *schema.ResourceData) *datadogV1.Monitor {
m.SetMessage(d.Get("message").(string))
m.SetOptions(o)

u := datadogV1.NewMonitorUpdateRequest()
u.SetType(monitorType)
u.SetQuery(d.Get("query").(string))
u.SetName(d.Get("name").(string))
u.SetMessage(d.Get("message").(string))
u.SetOptions(o)

tags := make([]string, 0)
if attr, ok := d.GetOk("tags"); ok {
for _, s := range attr.(*schema.Set).List() {
Expand All @@ -304,8 +311,9 @@ func buildMonitorStruct(d *schema.ResourceData) *datadogV1.Monitor {
sort.Strings(tags)
}
m.SetTags(tags)
u.SetTags(tags)

return m
return m, u
}

func resourceDatadogMonitorExists(d *schema.ResourceData, meta interface{}) (b bool, e error) {
Expand Down Expand Up @@ -349,7 +357,7 @@ func resourceDatadogMonitorCreate(d *schema.ResourceData, meta interface{}) erro
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

m := buildMonitorStruct(d)
m, _ := buildMonitorStruct(d)
mCreated, _, err := datadogClientV1.MonitorsApi.CreateMonitor(authV1).Body(*m).Execute()
if err != nil {
return translateClientError(err, "error creating monitor")
Expand Down Expand Up @@ -466,8 +474,7 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

m := buildMonitorStruct(d)

_, m := buildMonitorStruct(d)
i, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return err
Expand All @@ -487,7 +494,8 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
silenced = true
}

if *m, _, err = datadogClientV1.MonitorsApi.UpdateMonitor(authV1, i).Body(*m).Execute(); err != nil {
monitorResp, _, err := datadogClientV1.MonitorsApi.UpdateMonitor(authV1, i).Body(*m).Execute()
if err != nil {
return translateClientError(err, "error updating monitor")
}

Expand All @@ -503,13 +511,16 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
// they're "drift")
unmutedScopes := getUnmutedScopes(d)
if newSilenced, ok := d.GetOk("silenced"); ok && !silenced {
// Because the Update method had a payload object which is not the same as the return result,
// we need to set this attribute from one to the other.
m.Options.SetSilenced(monitorResp.Options.GetSilenced())
mSilenced := m.Options.GetSilenced()
for k, _ := range mSilenced {
// Since the Datadog GO client doesn't support unmuting on all scopes, loop over GetSilenced() and set the
// end timestamp to time.Now().Unix()
mSilenced[k] = time.Now().Unix()
}
*m, _, err = datadogClientV1.MonitorsApi.UpdateMonitor(authV1, i).Body(*m).Execute()
monitorResp, _, err = datadogClientV1.MonitorsApi.UpdateMonitor(authV1, i).Body(*m).Execute()
if err != nil {
return translateClientError(err, "error updating monitor")
}
Expand All @@ -524,6 +535,9 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro

// Similarly, if the silenced attribute is -1, lets unmute those scopes
if len(unmutedScopes) != 0 {
// Because the Update method had a payload object which is not the same as the return result,
// we need to set this attribute from one to the other.
m.Options.SetSilenced(monitorResp.Options.GetSilenced())
silencedList := m.Options.GetSilenced()
for _, scope := range unmutedScopes {
if _, ok := silencedList[scope]; ok {
Expand Down
34 changes: 23 additions & 11 deletions datadog/resource_datadog_service_level_objective.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,21 @@ func ValidateServiceLevelObjectiveTypeString(v interface{}, k string) (ws []stri
return
}

func buildServiceLevelObjectiveStruct(d *schema.ResourceData) *datadogV1.ServiceLevelObjective {
func buildServiceLevelObjectiveStructs(d *schema.ResourceData) (*datadogV1.ServiceLevelObjective, *datadogV1.ServiceLevelObjectiveRequest) {

slo := &datadogV1.ServiceLevelObjective{
Id: datadogV1.PtrString(d.Id()),
Name: d.Get("name").(string),
Type: datadogV1.SLOType(d.Get("type").(string)),
}
slo := datadogV1.NewServiceLevelObjectiveWithDefaults()
slo.SetName(d.Get("name").(string))
slo.SetType(datadogV1.SLOType(d.Get("type").(string)))
slo.SetId(d.Id())

slor := datadogV1.NewServiceLevelObjectiveRequestWithDefaults()
slor.SetName(d.Get("name").(string))
slor.SetType(datadogV1.SLOType(d.Get("type").(string)))
slor.SetId(d.Id())

if attr, ok := d.GetOk("description"); ok {
slo.SetDescription(attr.(string))
slor.SetDescription(attr.(string))
}

switch slo.GetType() {
Expand All @@ -170,13 +175,15 @@ func buildServiceLevelObjectiveStruct(d *schema.ResourceData) *datadogV1.Service
s = append(s, int64(v.(int)))
}
slo.SetMonitorIds(s)
slor.SetMonitorIds(s)
}
if attr, ok := d.GetOk("groups"); ok {
s := make([]string, 0)
for _, v := range attr.(*schema.Set).List() {
s = append(s, v.(string))
}
slo.SetGroups(s)
slor.SetGroups(s)
}
default:
// metric type
Expand All @@ -193,6 +200,9 @@ func buildServiceLevelObjectiveStruct(d *schema.ResourceData) *datadogV1.Service
slo.SetQuery(*datadogV1.NewServiceLevelObjectiveQuery(
queries[0]["denominator"].(string),
queries[0]["numerator"].(string)))
slor.SetQuery(*datadogV1.NewServiceLevelObjectiveQuery(
queries[0]["denominator"].(string),
queries[0]["numerator"].(string)))
}
}
}
Expand All @@ -203,6 +213,7 @@ func buildServiceLevelObjectiveStruct(d *schema.ResourceData) *datadogV1.Service
s = append(s, v.(string))
}
slo.SetTags(s)
slor.SetTags(s)
}

if _, ok := d.GetOk("thresholds"); ok {
Expand Down Expand Up @@ -243,10 +254,11 @@ func buildServiceLevelObjectiveStruct(d *schema.ResourceData) *datadogV1.Service
}
if len(sloThresholds) > 0 {
slo.SetThresholds(sloThresholds)
slor.SetThresholds(sloThresholds)
}
}

return slo
return slo, slor
}

func floatOk(val interface{}) (float64, bool) {
Expand Down Expand Up @@ -276,13 +288,13 @@ func resourceDatadogServiceLevelObjectiveCreate(d *schema.ResourceData, meta int
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1

slo := buildServiceLevelObjectiveStruct(d)
sloResp, _, err := datadogClientV1.ServiceLevelObjectivesApi.CreateSLO(authV1).Body(*slo).Execute()
_, slor := buildServiceLevelObjectiveStructs(d)
sloResp, _, err := datadogClientV1.ServiceLevelObjectivesApi.CreateSLO(authV1).Body(*slor).Execute()
if err != nil {
return translateClientError(err, "error creating service level objective")
}

slo = &sloResp.GetData()[0]
slo := &sloResp.GetData()[0]
d.SetId(slo.GetId())

return resourceDatadogServiceLevelObjectiveRead(d, meta)
Expand Down Expand Up @@ -368,7 +380,7 @@ func resourceDatadogServiceLevelObjectiveUpdate(d *schema.ResourceData, meta int
providerConf := meta.(*ProviderConfiguration)
datadogClientV1 := providerConf.DatadogClientV1
authV1 := providerConf.AuthV1
slo := buildServiceLevelObjectiveStruct(d)
slo, _ := buildServiceLevelObjectiveStructs(d)

if _, _, err := datadogClientV1.ServiceLevelObjectivesApi.UpdateSLO(authV1, d.Id()).Body(*slo).Execute(); err != nil {
return translateClientError(err, "error updating service level objective")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/terraform-providers/terraform-provider-datadog

require (
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2.0.20200507190510-3fade721dd1a
github.com/cenkalti/backoff v2.1.1+incompatible // indirect
github.com/dnaeon/go-vcr v1.0.1
github.com/hashicorp/go-cleanhttp v0.5.1
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbf
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2 h1:tav6+lH/q19H4wEuxhkhvN6KRmotqkqIBWuhxGYxk7M=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2/go.mod h1:ZIerq9SI/pcS9fBjSAe1k68EfexOJrzcp9uiOpJQhrA=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2.0.20200507190510-3fade721dd1a h1:g0K3y0DSRd53VChY1NzCMZT+Bi2UbZf2e8JoKUT+EaY=
github.com/DataDog/datadog-api-client-go v1.0.0-beta.2.0.20200507190510-3fade721dd1a/go.mod h1:ZIerq9SI/pcS9fBjSAe1k68EfexOJrzcp9uiOpJQhrA=
github.com/DataDog/datadog-go v3.6.0+incompatible h1:ILg7c5Y1KvZFDOaVS0higGmJ5Fal5O1KQrkrT9j6dSM=
github.com/DataDog/datadog-go v3.6.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down Expand Up @@ -203,8 +203,7 @@ github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8=
github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8=
github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
github.com/zorkian/go-datadog-api v2.28.0+incompatible h1:bh/2jIkDFCZRjkuQKBFdmB+sScAMXf8fctKTT0ae+wE=
github.com/zorkian/go-datadog-api v2.28.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB9ZwAD45N1uhCW4MT/Wj7m36PbKss=
github.com/zorkian/go-datadog-api v2.29.0+incompatible h1:uZZg0POZ6tLmVFtjUSaTZYwR6Q6RrHx6f/blTEDn8dA=
github.com/zorkian/go-datadog-api v2.29.0+incompatible/go.mod h1:PkXwHX9CUQa/FpB9ZwAD45N1uhCW4MT/Wj7m36PbKss=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 79f6816

Please sign in to comment.