Skip to content

Commit

Permalink
Merge pull request #31020 from dscain/b-redshift-scheduleaction-name-fix
Browse files Browse the repository at this point in the history
Fix aws_redshift_scheduled_action naming allowing non [0-9a-z-]{1,63}
  • Loading branch information
ewbankkit authored May 4, 2023
2 parents c9dda84 + 9608611 commit 8fdcc50
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/31020.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_redshift_scheduled_action: Add plan time validation for `name` argument
```
8 changes: 5 additions & 3 deletions internal/service/redshift/scheduled_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redshift
import (
"context"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions internal/service/redshift/scheduled_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 8fdcc50

Please sign in to comment.