Skip to content

Commit 94809a5

Browse files
committed
create addSaasResourceWarning function
1 parent 2d991f1 commit 94809a5

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

aquasec/resource_application_scope.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@ func resourceApplicationScope() *schema.Resource {
1919
},
2020
Schema: map[string]*schema.Schema{
2121
"name": {
22-
Type: schema.TypeString,
23-
Description: "Name of an application scope.",
24-
Required: true,
25-
ForceNew: true,
26-
ValidateFunc: func(val interface{}, key string) ([]string, []error) {
27-
if isSaasEnv() {
28-
return []string{
29-
"You are using aquasec_application_scope with an Aqua SaaS instance. Please migrate to aquasec_application_scope_saas, designed specifically for Aqua SaaS customers and supporting the entire SaaS platform beyond workload protection.",
30-
}, nil
31-
}
32-
return nil, nil
33-
},
22+
Type: schema.TypeString,
23+
Description: "Name of an application scope.",
24+
Required: true,
25+
ForceNew: true,
26+
ValidateFunc: validateSaasResourceWarning("aquasec_application_scope", "aquasec_application_scope_saas"),
3427
},
3528
"description": {
3629
Type: schema.TypeString,

aquasec/utils.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import (
66
os "os"
77
"strings"
88

9-
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10-
119
"github.com/aquasecurity/terraform-provider-aquasec/client"
1210
"github.com/aquasecurity/terraform-provider-aquasec/consts"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1312
)
1413

1514
func convertStringArr(ifaceArr []interface{}) []string {
@@ -244,13 +243,16 @@ func isResourceExist(response string) bool {
244243
}
245244
}
246245

247-
func addSaasResourceWarning(diags diag.Diagnostics, legacyResource string, newResource string) diag.Diagnostics {
248-
if isSaasEnv() {
249-
return append(diags, diag.Diagnostic{
250-
Severity: diag.Warning,
251-
Summary: "Legacy Resource Usage",
252-
Detail: fmt.Sprintf("You are using %s with an Aqua SaaS instance. Please migrate to %s, designed specifically for Aqua SaaS customers and supporting the entire SaaS platform beyond workload protection.", legacyResource, newResource),
253-
})
246+
func validateSaasResourceWarning(legacyResource, newResource string) schema.SchemaValidateFunc {
247+
return func(val interface{}, key string) ([]string, []error) {
248+
if isSaasEnv() {
249+
return []string{
250+
fmt.Sprintf(
251+
"You are using %s with an Aqua SaaS instance. Please migrate to %s, designed specifically for Aqua SaaS customers and supporting the entire SaaS platform beyond workload protection.",
252+
legacyResource, newResource,
253+
),
254+
}, nil
255+
}
256+
return nil, nil
254257
}
255-
return diags
256258
}

0 commit comments

Comments
 (0)