Skip to content

Commit 2e6bcd1

Browse files
martinstibbeZuhairahmeddependabot[bot]
authored
INTMDB-556: Regression in 1.8.0: mongodbatlas_third_party_integration marks "type" attribute as deprecated (#1034)
* Update CHANGELOG.md * Chore(deps): Bump golangci/golangci-lint-action from 3.3.1 to 3.4.0 (#1026) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.3.1 to 3.4.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](golangci/golangci-lint-action@v3.3.1...v3.4.0) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add warning for deprecated integration types --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Zuhair Ahmed <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 746cc8f commit 2e6bcd1

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

mongodbatlas/resource_mongodbatlas_third_party_integration.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"net/http"
77
"regexp"
88

9+
"github.com/hashicorp/go-cty/cty"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1212
)
1313

1414
var integrationTypes = []string{
@@ -23,6 +23,11 @@ var integrationTypes = []string{
2323
"PROMETHEUS",
2424
}
2525

26+
var deprecatedIntegrationTypes = []string{
27+
"NEW_RELIC",
28+
"FLOWDOCK",
29+
}
30+
2631
var requiredPerType = map[string][]string{
2732
"PAGER_DUTY": {"service_key"},
2833
"DATADOG": {"api_key", "region"},
@@ -51,11 +56,10 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
5156
ForceNew: true,
5257
},
5358
"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(),
5963
},
6064
"license_key": {
6165
Type: schema.TypeString,
@@ -310,3 +314,36 @@ func splitIntegrationTypeID(id string) (projectID, integrationType string, err e
310314

311315
return
312316
}
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

Comments
 (0)