diff --git a/.changelog/31020.txt b/.changelog/31020.txt new file mode 100644 index 000000000000..da3dc1367a8d --- /dev/null +++ b/.changelog/31020.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_redshift_scheduled_action: Add plan time validation for `name` argument +``` \ No newline at end of file diff --git a/internal/service/redshift/scheduled_action.go b/internal/service/redshift/scheduled_action.go index faf14f948a0e..b42158184b11 100644 --- a/internal/service/redshift/scheduled_action.go +++ b/internal/service/redshift/scheduled_action.go @@ -3,6 +3,7 @@ package redshift import ( "context" "log" + "regexp" "time" "github.com/aws/aws-sdk-go/aws" @@ -48,9 +49,10 @@ func ResourceScheduledAction() *schema.Resource { Required: true, }, "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-z0-9-]{1,63}$`), ""), }, "schedule": { Type: schema.TypeString, diff --git a/internal/service/redshift/scheduled_action_test.go b/internal/service/redshift/scheduled_action_test.go index 05cb5fad036d..b11f48040acb 100644 --- a/internal/service/redshift/scheduled_action_test.go +++ b/internal/service/redshift/scheduled_action_test.go @@ -3,12 +3,14 @@ package redshift_test import ( "context" "fmt" + "regexp" "testing" "time" "github.com/aws/aws-sdk-go/service/redshift" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -479,3 +481,37 @@ resource "aws_redshift_scheduled_action" "test" { } `, rName, schedule, classic, clusterType, nodeType, numberOfNodes)) } + +func TestAccRedshiftScheduledAction_validScheduleName(t *testing.T) { + t.Parallel() + + var f = validation.StringMatch(regexp.MustCompile(`^[a-z0-9-]{1,63}$`), "") + + validIds := []string{ + "tf-test-schedule-action-1", + acctest.ResourcePrefix, + sdkacctest.RandomWithPrefix(acctest.ResourcePrefix), + } + + for _, s := range validIds { + _, errors := f(s, "") + if len(errors) > 0 { + t.Fatalf("%q should be a valid replication instance id: %v", s, errors) + } + } + + invalidIds := []string{ + "tf_test_schedule-action_1", + "tfTestScheduleACtion", + "tf.test.schedule.action.1", + "tf test schedule action 1", + "tf-test-schedule-action-1!", + } + + for _, s := range invalidIds { + _, errors := f(s, "") + if len(errors) == 0 { + t.Fatalf("%q should not be a valid replication instance id: %v", s, errors) + } + } +}