Skip to content

Commit

Permalink
feat(destinations): add new fields to destinations; secureUrl, custom…
Browse files Browse the repository at this point in the history
… headers auth and more (#2635)

Co-authored-by: pranav-new-relic <[email protected]>
  • Loading branch information
nzur-newrelic and pranav-new-relic authored Apr 22, 2024
1 parent 92361de commit afc2cdf
Show file tree
Hide file tree
Showing 10 changed files with 485 additions and 26 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.30.0
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.27.0
github.com/newrelic/newrelic-client-go/v2 v2.31.0
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
)
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/elazarl/goproxy v0.0.0-20230731152917-f99041a5c027 h1:1L0aalTpPz7YlMxETKpmQoWMBkeiuorElZIXoNmgiPE=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -263,8 +263,8 @@ github.com/newrelic/go-agent/v3 v3.30.0 h1:ZXHCT/Cot4iIPwcegCZURuRQOsfmGA6wilW+S
github.com/newrelic/go-agent/v3 v3.30.0/go.mod h1:9utrgxlSryNqRrTvII2XBL+0lpofXbqXApvVWPpbzUg=
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
github.com/newrelic/newrelic-client-go/v2 v2.27.0 h1:pSE3LQKk1NatM72OZL2UzHS66tbNSFui5QO8FZ8+JVg=
github.com/newrelic/newrelic-client-go/v2 v2.27.0/go.mod h1:SO5KJuFJ/+l3lT8nOdNLTrcE9FoZ4m60kechCVb+1N4=
github.com/newrelic/newrelic-client-go/v2 v2.31.0 h1:Zj6VaWfEQ3shhgj1VM+XurnT3lVE/rNi9UIx5K09LzU=
github.com/newrelic/newrelic-client-go/v2 v2.31.0/go.mod h1:xP8n2q2daNbAM7GxER5gqh8lW5ZpBkL6BuG7MWGt2v0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
14 changes: 14 additions & 0 deletions newrelic/data_source_newrelic_notifications_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func dataSourceNewRelicNotificationDestination() *schema.Resource {
Computed: true,
Description: "The status of the destination.",
},
"secure_url": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
Description: "URL in secure format",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"prefix": {
Type: schema.TypeString,
Required: true,
},
},
},
},
},
}
}
Expand Down
45 changes: 45 additions & 0 deletions newrelic/data_source_newrelic_notifications_destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ func TestAccNewRelicNotificationDestinationDataSource_ByName(t *testing.T) {
})
}

func TestAccNewRelicNotificationDestinationDataSource_WithSecureURL(t *testing.T) {
resourceName := "newrelic_notification_destination.foo"
rand := acctest.RandString(5)
rName := fmt.Sprintf("tf-notifications-test-%s", rand)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccNewRelicNotificationsDestinationDataSourceConfigWithSecureURL(rName),
Check: resource.ComposeTestCheckFunc(
testAccNewRelicNotificationDestination("data.newrelic_notification_destination.foo"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "secure_url.0.prefix", "https://webhook.site/"),
),
},
},
})
}

func testAccNewRelicNotificationsDestinationDataSourceConfigById(name string) string {
return fmt.Sprintf(`
resource "newrelic_notification_destination" "foo" {
Expand Down Expand Up @@ -92,6 +113,30 @@ func testAccNewRelicNotificationsDestinationDataSourceConfigByName(name string)
`, name)
}

func testAccNewRelicNotificationsDestinationDataSourceConfigWithSecureURL(name string) string {
return fmt.Sprintf(`
resource "newrelic_notification_destination" "foo" {
name = "%s"
type = "WEBHOOK"
active = true
property {
key = "source"
value = "terraform"
}
secure_url {
prefix = "https://webhook.site/"
secure_suffix = "aaaaa"
}
}
data "newrelic_notification_destination" "foo" {
name = newrelic_notification_destination.foo.name
}
`, name)
}

func testAccNewRelicNotificationDestination(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
r := s.RootModule().Resources[n]
Expand Down
42 changes: 40 additions & 2 deletions newrelic/resource_newrelic_notifications_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func resourceNewRelicNotificationDestination() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"auth_token"},
ConflictsWith: []string{"auth_token", "auth_custom_header"},
Description: "Basic username and password authentication credentials.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -74,7 +74,7 @@ func resourceNewRelicNotificationDestination() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"auth_basic"},
ConflictsWith: []string{"auth_basic", "auth_custom_header"},
Description: "Token authentication credentials.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -90,6 +90,25 @@ func resourceNewRelicNotificationDestination() *schema.Resource {
},
},
},
"auth_custom_header": {
Type: schema.TypeList,
Optional: true,
ConflictsWith: []string{"auth_basic", "auth_token"},
Description: "Custom header based authentication",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
},
"value": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
},
},
},
"active": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -113,6 +132,25 @@ func resourceNewRelicNotificationDestination() *schema.Resource {
Computed: true,
Description: "Destination entity GUID",
},
"secure_url": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "URL in secure format",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"prefix": {
Type: schema.TypeString,
Required: true,
},
"secure_suffix": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
},
},
},
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
Expand Down
Loading

0 comments on commit afc2cdf

Please sign in to comment.