Skip to content

Commit cb45328

Browse files
Relax expiry duration validation
1 parent 64f808a commit cb45328

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

ns1/resource_apikey.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package ns1
33
import (
44
"fmt"
55
"log"
6+
"regexp"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
810

911
ns1 "gopkg.in/ns1/ns1-go.v2/rest"
1012
"gopkg.in/ns1/ns1-go.v2/rest/model/account"
@@ -40,14 +42,11 @@ func apikeyResource() *schema.Resource {
4042
Type: schema.TypeString,
4143
Optional: true,
4244
ForceNew: true,
43-
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
44-
v := val.(string)
45-
if v != "" && v != "10d" && v != "30d" && v != "90d" {
46-
errs = append(errs, fmt.Errorf("%q must be one of: '10d', '30d', '90d', got: %s", key, v))
47-
}
48-
return
49-
},
50-
Description: "Duration for automatic secret rotation. Valid values: '10d', '30d', '90d'. When set, API key secrets will automatically rotate. Changing this value will force recreation of the API key.",
45+
ValidateFunc: validation.StringMatch(
46+
regexp.MustCompile(`^\d+d$`),
47+
"must be a duration in format '<number>d' (e.g., '10d', '30d', '90d')",
48+
),
49+
Description: "Duration for automatic secret expiration (e.g., '10d', '30d', '90d'). Accepts any duration in '<number>d' format. When set, API key secrets will automatically expire after the specified period. Changing this value will force recreation of the API key.",
5150
},
5251
"secrets": {
5352
Type: schema.TypeList,

0 commit comments

Comments
 (0)