Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/elasticache_replication_group: Modify validation, make replication_group_id to lowercase #2432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aws/resource_aws_elasticache_replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validateAwsElastiCacheReplicationGroupId,
StateFunc: func(val interface{}) string {
return strings.ToLower(val.(string))
},
}

resourceSchema["automatic_failover_enabled"] = &schema.Schema{
Expand Down Expand Up @@ -518,7 +521,7 @@ func validateAwsElastiCacheReplicationGroupId(v interface{}, k string) (ws []str
errors = append(errors, fmt.Errorf(
"only alphanumeric characters and hyphens allowed in %q", k))
}
if !regexp.MustCompile(`^[a-z]`).MatchString(value) {
if !regexp.MustCompile(`^[a-zA-Z]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"first character of %q must be a letter", k))
}
Expand Down
32 changes: 32 additions & 0 deletions aws/resource_aws_elasticache_replication_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ func TestAccAWSElasticacheReplicationGroup_basic(t *testing.T) {
})
}

func TestAccAWSElasticacheReplicationGroup_Uppercase(t *testing.T) {
var rg elasticache.ReplicationGroup
rStr := acctest.RandString(5)
rgName := fmt.Sprintf("TF-ELASTIRG-%s", rStr)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSElasticacheReplicationGroupConfig_Uppercase(rgName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
resource.TestCheckResourceAttr(
"aws_elasticache_replication_group.bar", "replication_group_id", fmt.Sprintf("tf-elastirg-%s", rStr)),
),
},
},
})
}

func TestAccAWSElasticacheReplicationGroup_updateDescription(t *testing.T) {
var rg elasticache.ReplicationGroup
rName := acctest.RandString(10)
Expand Down Expand Up @@ -476,6 +497,17 @@ resource "aws_elasticache_replication_group" "bar" {
}`, rName, rName, rName)
}

func testAccAWSElasticacheReplicationGroupConfig_Uppercase(rgName string) string {
return fmt.Sprintf(`
resource "aws_elasticache_replication_group" "bar" {
replication_group_id = "%s"
replication_group_description = "test description"
node_type = "cache.t2.micro"
number_cache_clusters = 1
port = 6379
}`, rgName)
}

func testAccAWSElasticacheReplicationGroupConfigEnableSnapshotting(rName string) string {
return fmt.Sprintf(`
provider "aws" {
Expand Down