@@ -6,10 +6,12 @@ package signalfx
6
6
import (
7
7
"context"
8
8
"encoding/json"
9
+ "errors"
9
10
"fmt"
10
11
"log"
11
12
"strings"
12
13
14
+ "github.com/hashicorp/go-cty/cty"
13
15
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
14
16
"github.com/signalfx/signalfx-go/integration"
15
17
)
@@ -74,18 +76,31 @@ func pagerDutyIntegrationAPIToTF(d *schema.ResourceData, pd *integration.PagerDu
74
76
return nil
75
77
}
76
78
77
- func getPayloadPagerDutyIntegration (d * schema.ResourceData ) * integration.PagerDutyIntegration {
79
+ func getPayloadPagerDutyIntegration (d * schema.ResourceData ) (* integration.PagerDutyIntegration , error ) {
80
+ key , diags := d .GetRawConfigAt (cty .GetAttrPath ("api_key" ))
81
+ if diags .HasError () {
82
+ return nil , errors .New ("issue reading raw config" )
83
+ }
84
+
85
+ if ! key .Type ().Equals (cty .String ) {
86
+ return nil , errors .New ("api key not stored as string" )
87
+ }
88
+
78
89
return & integration.PagerDutyIntegration {
79
90
Type : "PagerDuty" ,
80
91
Name : d .Get ("name" ).(string ),
81
92
Enabled : d .Get ("enabled" ).(bool ),
82
- ApiKey : d . Get ( "api_key" ).( string ),
83
- }
93
+ ApiKey : key . AsString ( ),
94
+ }, nil
84
95
}
85
96
86
97
func integrationPagerDutyCreate (d * schema.ResourceData , meta interface {}) error {
87
98
config := meta .(* signalfxConfig )
88
- payload := getPayloadPagerDutyIntegration (d )
99
+
100
+ payload , err := getPayloadPagerDutyIntegration (d )
101
+ if err != nil {
102
+ return err
103
+ }
89
104
90
105
debugOutput , _ := json .Marshal (payload )
91
106
log .Printf ("[DEBUG] SignalFx: Create PagerDuty Integration Payload: %s" , string (debugOutput ))
@@ -103,7 +118,11 @@ func integrationPagerDutyCreate(d *schema.ResourceData, meta interface{}) error
103
118
104
119
func integrationPagerDutyUpdate (d * schema.ResourceData , meta interface {}) error {
105
120
config := meta .(* signalfxConfig )
106
- payload := getPayloadPagerDutyIntegration (d )
121
+
122
+ payload , err := getPayloadPagerDutyIntegration (d )
123
+ if err != nil {
124
+ return err
125
+ }
107
126
108
127
debugOutput , _ := json .Marshal (payload )
109
128
log .Printf ("[DEBUG] SignalFx: Update PagerDuty Integration Payload: %s" , string (debugOutput ))
0 commit comments