Skip to content

Commit 10d68d9

Browse files
ojongeriusstack72
authored andcommitted
provider/datadog 9869: Validate credentials when initialising client. (hashicorp#10567)
* provider/datadog 9869: Validate credentials when initialising client. * provider/datadog Pull in new version of go-datadog-api. * provider/datadog Update testAccCheckDatadogMonitorConfigNoThresholds test config.
1 parent a33f362 commit 10d68d9

21 files changed

Lines changed: 235 additions & 208 deletions

builtin/providers/datadog/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ type Config struct {
1313
}
1414

1515
// Client returns a new Datadog client.
16-
func (c *Config) Client() (*datadog.Client, error) {
16+
func (c *Config) Client() *datadog.Client {
1717

1818
client := datadog.NewClient(c.APIKey, c.APPKey)
19-
2019
log.Printf("[INFO] Datadog Client configured ")
2120

22-
return client, nil
21+
return client
2322
}

builtin/providers/datadog/provider.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package datadog
33
import (
44
"log"
55

6+
"errors"
67
"github.com/hashicorp/terraform/helper/schema"
78
"github.com/hashicorp/terraform/terraform"
89
)
@@ -39,5 +40,17 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
3940
}
4041

4142
log.Println("[INFO] Initializing Datadog client")
42-
return config.Client()
43+
client := config.Client()
44+
45+
ok, err := client.Validate()
46+
47+
if err != nil {
48+
return client, err
49+
}
50+
51+
if ok == false {
52+
return client, errors.New(`No valid credential sources found for Datadog Provider. Please see https://terraform.io/docs/providers/datadog/index.html for more information on providing credentials for the Datadog Provider`)
53+
}
54+
55+
return client, nil
4356
}

builtin/providers/datadog/resource_datadog_monitor_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func TestAccDatadogMonitor_BasicNoTreshold(t *testing.T) {
7878
resource.TestCheckResourceAttr(
7979
"datadog_monitor.foo", "locked", "false"),
8080
resource.TestCheckResourceAttr(
81-
"datadog_monitor.foo", "tags.foo", "bar"),
81+
"datadog_monitor.foo", "tags.0", "foo:bar"),
8282
resource.TestCheckResourceAttr(
83-
"datadog_monitor.foo", "tags.bar", "baz"),
83+
"datadog_monitor.foo", "tags.1", "bar:baz"),
8484
),
8585
},
8686
},
@@ -305,10 +305,7 @@ resource "datadog_monitor" "foo" {
305305
include_tags = true
306306
require_full_window = true
307307
locked = false
308-
tags {
309-
"foo" = "bar"
310-
"bar" = "baz"
311-
}
308+
tags = ["foo:bar", "bar:baz"]
312309
}
313310
`
314311

vendor/github.com/zorkian/go-datadog-api/Makefile

Lines changed: 8 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/zorkian/go-datadog-api/README.md

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/zorkian/go-datadog-api/alerts.go

Lines changed: 14 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/zorkian/go-datadog-api/client.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/zorkian/go-datadog-api/comments.go

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/zorkian/go-datadog-api/dashboards.go

Lines changed: 10 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)