6
6
"net/http"
7
7
"regexp"
8
8
9
+ "github.com/hashicorp/go-cty/cty"
9
10
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12
12
)
13
13
14
14
var integrationTypes = []string {
@@ -23,6 +23,11 @@ var integrationTypes = []string{
23
23
"PROMETHEUS" ,
24
24
}
25
25
26
+ var deprecatedIntegrationTypes = []string {
27
+ "NEW_RELIC" ,
28
+ "FLOWDOCK" ,
29
+ }
30
+
26
31
var requiredPerType = map [string ][]string {
27
32
"PAGER_DUTY" : {"service_key" },
28
33
"DATADOG" : {"api_key" , "region" },
@@ -51,11 +56,10 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
51
56
ForceNew : true ,
52
57
},
53
58
"type" : {
54
- Type : schema .TypeString ,
55
- Required : true ,
56
- ForceNew : true ,
57
- ValidateFunc : validation .StringInSlice (integrationTypes , false ),
58
- Deprecated : "This field type has values (NEW_RELIC, FLOWDOCK) that are deprecated and will be removed in 1.9.0 release " ,
59
+ Type : schema .TypeString ,
60
+ Required : true ,
61
+ ForceNew : true ,
62
+ ValidateDiagFunc : validateIntegrationType (),
59
63
},
60
64
"license_key" : {
61
65
Type : schema .TypeString ,
@@ -310,3 +314,36 @@ func splitIntegrationTypeID(id string) (projectID, integrationType string, err e
310
314
311
315
return
312
316
}
317
+
318
+ func validateIntegrationType () schema.SchemaValidateDiagFunc {
319
+ return func (v any , p cty.Path ) diag.Diagnostics {
320
+ value := v .(string )
321
+ var diags diag.Diagnostics
322
+ if ! isElementExist (integrationTypes , value ) {
323
+ diagError := diag.Diagnostic {
324
+ Severity : diag .Error ,
325
+ Summary : "Invalid Third Party Integration type" ,
326
+ Detail : fmt .Sprintf ("Third Party integration type %q is not a valid value. Possible values are: %q." , value , integrationTypes ),
327
+ }
328
+ diags = append (diags , diagError )
329
+ }
330
+ if isElementExist (deprecatedIntegrationTypes , value ) {
331
+ diagWarn := diag.Diagnostic {
332
+ Severity : diag .Warning ,
333
+ Summary : "Warning deprecated Third Party Integration type" ,
334
+ Detail : fmt .Sprintf ("Third Party integration type %q is a deprecated value. This field type values %q are deprecated and will be removed in 1.9.0 release" , value , deprecatedIntegrationTypes ),
335
+ }
336
+ diags = append (diags , diagWarn )
337
+ }
338
+ return diags
339
+ }
340
+ }
341
+
342
+ func isElementExist (s []string , str string ) bool {
343
+ for _ , v := range s {
344
+ if v == str {
345
+ return true
346
+ }
347
+ }
348
+ return false
349
+ }
0 commit comments