github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/aws/awserr"
     9  	"github.com/aws/aws-sdk-go/service/elasticache"
    10  	"github.com/hashicorp/terraform/helper/acctest"
    11  	"github.com/hashicorp/terraform/helper/resource"
    12  	"github.com/hashicorp/terraform/terraform"
    13  )
    14  
    15  func TestAccAWSElasticacheReplicationGroup_basic(t *testing.T) {
    16  	var rg elasticache.ReplicationGroup
    17  
    18  	resource.Test(t, resource.TestCase{
    19  		PreCheck:     func() { testAccPreCheck(t) },
    20  		Providers:    testAccProviders,
    21  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    22  		Steps: []resource.TestStep{
    23  			resource.TestStep{
    24  				Config: testAccAWSElasticacheReplicationGroupConfig(acctest.RandString(10)),
    25  				Check: resource.ComposeTestCheckFunc(
    26  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    27  					resource.TestCheckResourceAttr(
    28  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    29  					resource.TestCheckResourceAttr(
    30  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
    31  				),
    32  			},
    33  		},
    34  	})
    35  }
    36  
    37  func TestAccAWSElasticacheReplicationGroup_updateDescription(t *testing.T) {
    38  	var rg elasticache.ReplicationGroup
    39  	rName := acctest.RandString(10)
    40  	resource.Test(t, resource.TestCase{
    41  		PreCheck:     func() { testAccPreCheck(t) },
    42  		Providers:    testAccProviders,
    43  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    44  		Steps: []resource.TestStep{
    45  			resource.TestStep{
    46  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
    47  				Check: resource.ComposeTestCheckFunc(
    48  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    49  					resource.TestCheckResourceAttr(
    50  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    51  					resource.TestCheckResourceAttr(
    52  						"aws_elasticache_replication_group.bar", "replication_group_description", "test description"),
    53  					resource.TestCheckResourceAttr(
    54  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
    55  				),
    56  			},
    57  
    58  			resource.TestStep{
    59  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName),
    60  				Check: resource.ComposeTestCheckFunc(
    61  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    62  					resource.TestCheckResourceAttr(
    63  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    64  					resource.TestCheckResourceAttr(
    65  						"aws_elasticache_replication_group.bar", "replication_group_description", "updated description"),
    66  					resource.TestCheckResourceAttr(
    67  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "true"),
    68  				),
    69  			},
    70  		},
    71  	})
    72  }
    73  
    74  func TestAccAWSElasticacheReplicationGroup_updateNodeSize(t *testing.T) {
    75  	var rg elasticache.ReplicationGroup
    76  	rName := acctest.RandString(10)
    77  	resource.Test(t, resource.TestCase{
    78  		PreCheck:     func() { testAccPreCheck(t) },
    79  		Providers:    testAccProviders,
    80  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    81  		Steps: []resource.TestStep{
    82  			resource.TestStep{
    83  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
    84  				Check: resource.ComposeTestCheckFunc(
    85  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    86  					resource.TestCheckResourceAttr(
    87  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    88  					resource.TestCheckResourceAttr(
    89  						"aws_elasticache_replication_group.bar", "node_type", "cache.m1.small"),
    90  				),
    91  			},
    92  
    93  			resource.TestStep{
    94  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedNodeSize(rName),
    95  				Check: resource.ComposeTestCheckFunc(
    96  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    97  					resource.TestCheckResourceAttr(
    98  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    99  					resource.TestCheckResourceAttr(
   100  						"aws_elasticache_replication_group.bar", "node_type", "cache.m1.medium"),
   101  				),
   102  			},
   103  		},
   104  	})
   105  }
   106  
   107  //This is a test to prove that we panic we get in https://github.com/hashicorp/terraform/issues/9097
   108  func TestAccAWSElasticacheReplicationGroup_updateParameterGroup(t *testing.T) {
   109  	var rg elasticache.ReplicationGroup
   110  	rName := acctest.RandString(10)
   111  	resource.Test(t, resource.TestCase{
   112  		PreCheck:     func() { testAccPreCheck(t) },
   113  		Providers:    testAccProviders,
   114  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   115  		Steps: []resource.TestStep{
   116  			resource.TestStep{
   117  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
   118  				Check: resource.ComposeTestCheckFunc(
   119  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   120  					resource.TestCheckResourceAttr(
   121  						"aws_elasticache_replication_group.bar", "parameter_group_name", "default.redis3.2"),
   122  				),
   123  			},
   124  
   125  			resource.TestStep{
   126  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName),
   127  				Check: resource.ComposeTestCheckFunc(
   128  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   129  					resource.TestCheckResourceAttr(
   130  						"aws_elasticache_replication_group.bar", "parameter_group_name", "allkeys-lru"),
   131  				),
   132  			},
   133  		},
   134  	})
   135  }
   136  
   137  func TestAccAWSElasticacheReplicationGroup_vpc(t *testing.T) {
   138  	var rg elasticache.ReplicationGroup
   139  	resource.Test(t, resource.TestCase{
   140  		PreCheck:     func() { testAccPreCheck(t) },
   141  		Providers:    testAccProviders,
   142  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   143  		Steps: []resource.TestStep{
   144  			resource.TestStep{
   145  				Config: testAccAWSElasticacheReplicationGroupInVPCConfig,
   146  				Check: resource.ComposeTestCheckFunc(
   147  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   148  					resource.TestCheckResourceAttr(
   149  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "1"),
   150  					resource.TestCheckResourceAttr(
   151  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
   152  				),
   153  			},
   154  		},
   155  	})
   156  }
   157  
   158  func TestAccAWSElasticacheReplicationGroup_multiAzInVpc(t *testing.T) {
   159  	var rg elasticache.ReplicationGroup
   160  	resource.Test(t, resource.TestCase{
   161  		PreCheck:     func() { testAccPreCheck(t) },
   162  		Providers:    testAccProviders,
   163  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   164  		Steps: []resource.TestStep{
   165  			resource.TestStep{
   166  				Config: testAccAWSElasticacheReplicationGroupMultiAZInVPCConfig,
   167  				Check: resource.ComposeTestCheckFunc(
   168  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   169  					resource.TestCheckResourceAttr(
   170  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   171  					resource.TestCheckResourceAttr(
   172  						"aws_elasticache_replication_group.bar", "automatic_failover_enabled", "true"),
   173  					resource.TestCheckResourceAttr(
   174  						"aws_elasticache_replication_group.bar", "snapshot_window", "02:00-03:00"),
   175  					resource.TestCheckResourceAttr(
   176  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "7"),
   177  					resource.TestCheckResourceAttrSet(
   178  						"aws_elasticache_replication_group.bar", "primary_endpoint_address"),
   179  				),
   180  			},
   181  		},
   182  	})
   183  }
   184  
   185  func TestAccAWSElasticacheReplicationGroup_redisClusterInVpc2(t *testing.T) {
   186  	var rg elasticache.ReplicationGroup
   187  	resource.Test(t, resource.TestCase{
   188  		PreCheck:     func() { testAccPreCheck(t) },
   189  		Providers:    testAccProviders,
   190  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   191  		Steps: []resource.TestStep{
   192  			resource.TestStep{
   193  				Config: testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig,
   194  				Check: resource.ComposeTestCheckFunc(
   195  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   196  					resource.TestCheckResourceAttr(
   197  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   198  					resource.TestCheckResourceAttr(
   199  						"aws_elasticache_replication_group.bar", "automatic_failover_enabled", "true"),
   200  					resource.TestCheckResourceAttr(
   201  						"aws_elasticache_replication_group.bar", "snapshot_window", "02:00-03:00"),
   202  					resource.TestCheckResourceAttr(
   203  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "7"),
   204  					resource.TestCheckResourceAttrSet(
   205  						"aws_elasticache_replication_group.bar", "configuration_endpoint_address"),
   206  				),
   207  			},
   208  		},
   209  	})
   210  }
   211  
   212  func TestResourceAWSElastiCacheReplicationGroupIdValidation(t *testing.T) {
   213  	cases := []struct {
   214  		Value    string
   215  		ErrCount int
   216  	}{
   217  		{
   218  			Value:    "tEsting",
   219  			ErrCount: 0,
   220  		},
   221  		{
   222  			Value:    "t.sting",
   223  			ErrCount: 1,
   224  		},
   225  		{
   226  			Value:    "t--sting",
   227  			ErrCount: 1,
   228  		},
   229  		{
   230  			Value:    "1testing",
   231  			ErrCount: 1,
   232  		},
   233  		{
   234  			Value:    "testing-",
   235  			ErrCount: 1,
   236  		},
   237  		{
   238  			Value:    randomString(17),
   239  			ErrCount: 1,
   240  		},
   241  	}
   242  
   243  	for _, tc := range cases {
   244  		_, errors := validateAwsElastiCacheReplicationGroupId(tc.Value, "aws_elasticache_replication_group_replication_group_id")
   245  
   246  		if len(errors) != tc.ErrCount {
   247  			t.Fatalf("Expected the ElastiCache Replication Group Id to trigger a validation error")
   248  		}
   249  	}
   250  }
   251  
   252  func TestResourceAWSElastiCacheReplicationGroupEngineValidation(t *testing.T) {
   253  	cases := []struct {
   254  		Value    string
   255  		ErrCount int
   256  	}{
   257  		{
   258  			Value:    "Redis",
   259  			ErrCount: 0,
   260  		},
   261  		{
   262  			Value:    "REDIS",
   263  			ErrCount: 0,
   264  		},
   265  		{
   266  			Value:    "memcached",
   267  			ErrCount: 1,
   268  		},
   269  	}
   270  
   271  	for _, tc := range cases {
   272  		_, errors := validateAwsElastiCacheReplicationGroupEngine(tc.Value, "aws_elasticache_replication_group_engine")
   273  
   274  		if len(errors) != tc.ErrCount {
   275  			t.Fatalf("Expected the ElastiCache Replication Group Engine to trigger a validation error")
   276  		}
   277  	}
   278  }
   279  
   280  func testAccCheckAWSElasticacheReplicationGroupExists(n string, v *elasticache.ReplicationGroup) resource.TestCheckFunc {
   281  	return func(s *terraform.State) error {
   282  		rs, ok := s.RootModule().Resources[n]
   283  		if !ok {
   284  			return fmt.Errorf("Not found: %s", n)
   285  		}
   286  
   287  		if rs.Primary.ID == "" {
   288  			return fmt.Errorf("No replication group ID is set")
   289  		}
   290  
   291  		conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
   292  		res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{
   293  			ReplicationGroupId: aws.String(rs.Primary.ID),
   294  		})
   295  		if err != nil {
   296  			return fmt.Errorf("Elasticache error: %v", err)
   297  		}
   298  
   299  		for _, rg := range res.ReplicationGroups {
   300  			if *rg.ReplicationGroupId == rs.Primary.ID {
   301  				*v = *rg
   302  			}
   303  		}
   304  
   305  		return nil
   306  	}
   307  }
   308  
   309  func testAccCheckAWSElasticacheReplicationDestroy(s *terraform.State) error {
   310  	conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
   311  
   312  	for _, rs := range s.RootModule().Resources {
   313  		if rs.Type != "aws_elasticache_replication_group" {
   314  			continue
   315  		}
   316  		res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{
   317  			ReplicationGroupId: aws.String(rs.Primary.ID),
   318  		})
   319  		if err != nil {
   320  			// Verify the error is what we want
   321  			if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ReplicationGroupNotFoundFault" {
   322  				continue
   323  			}
   324  			return err
   325  		}
   326  		if len(res.ReplicationGroups) > 0 {
   327  			return fmt.Errorf("still exist.")
   328  		}
   329  	}
   330  	return nil
   331  }
   332  
   333  func testAccAWSElasticacheReplicationGroupConfig(rName string) string {
   334  	return fmt.Sprintf(`
   335  provider "aws" {
   336    region = "us-east-1"
   337  }
   338  resource "aws_security_group" "bar" {
   339      name = "tf-test-security-group-%s"
   340      description = "tf-test-security-group-descr"
   341      ingress {
   342          from_port = -1
   343          to_port = -1
   344          protocol = "icmp"
   345          cidr_blocks = ["0.0.0.0/0"]
   346      }
   347  }
   348  
   349  resource "aws_elasticache_security_group" "bar" {
   350      name = "tf-test-security-group-%s"
   351      description = "tf-test-security-group-descr"
   352      security_group_names = ["${aws_security_group.bar.name}"]
   353  }
   354  
   355  resource "aws_elasticache_replication_group" "bar" {
   356      replication_group_id = "tf-%s"
   357      replication_group_description = "test description"
   358      node_type = "cache.m1.small"
   359      number_cache_clusters = 2
   360      port = 6379
   361      parameter_group_name = "default.redis3.2"
   362      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   363      apply_immediately = true
   364      auto_minor_version_upgrade = false
   365  }`, rName, rName, rName)
   366  }
   367  
   368  func testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName string) string {
   369  	return fmt.Sprintf(`
   370  provider "aws" {
   371    region = "us-east-1"
   372  }
   373  resource "aws_security_group" "bar" {
   374      name = "tf-test-security-group-%s"
   375      description = "tf-test-security-group-descr"
   376      ingress {
   377          from_port = -1
   378          to_port = -1
   379          protocol = "icmp"
   380          cidr_blocks = ["0.0.0.0/0"]
   381      }
   382  }
   383  
   384  resource "aws_elasticache_security_group" "bar" {
   385      name = "tf-test-security-group-%s"
   386      description = "tf-test-security-group-descr"
   387      security_group_names = ["${aws_security_group.bar.name}"]
   388  }
   389  
   390  resource "aws_elasticache_parameter_group" "bar" {
   391      name = "allkeys-lru"
   392      family = "redis3.2"
   393  
   394      parameter {
   395          name = "maxmemory-policy"
   396          value = "allkeys-lru"
   397      }
   398  }
   399  
   400  resource "aws_elasticache_replication_group" "bar" {
   401      replication_group_id = "tf-%s"
   402      replication_group_description = "test description"
   403      node_type = "cache.m1.small"
   404      number_cache_clusters = 2
   405      port = 6379
   406      parameter_group_name = "${aws_elasticache_parameter_group.bar.name}"
   407      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   408      apply_immediately = true
   409  }`, rName, rName, rName)
   410  }
   411  
   412  func testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName string) string {
   413  	return fmt.Sprintf(`
   414  provider "aws" {
   415  	region = "us-east-1"
   416  }
   417  resource "aws_security_group" "bar" {
   418      name = "tf-test-security-group-%s"
   419      description = "tf-test-security-group-descr"
   420      ingress {
   421          from_port = -1
   422          to_port = -1
   423          protocol = "icmp"
   424          cidr_blocks = ["0.0.0.0/0"]
   425      }
   426  }
   427  
   428  resource "aws_elasticache_security_group" "bar" {
   429      name = "tf-test-security-group-%s"
   430      description = "tf-test-security-group-descr"
   431      security_group_names = ["${aws_security_group.bar.name}"]
   432  }
   433  
   434  resource "aws_elasticache_replication_group" "bar" {
   435      replication_group_id = "tf-%s"
   436      replication_group_description = "updated description"
   437      node_type = "cache.m1.small"
   438      number_cache_clusters = 2
   439      port = 6379
   440      parameter_group_name = "default.redis3.2"
   441      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   442      apply_immediately = true
   443      auto_minor_version_upgrade = true
   444  }`, rName, rName, rName)
   445  }
   446  
   447  func testAccAWSElasticacheReplicationGroupConfigUpdatedNodeSize(rName string) string {
   448  	return fmt.Sprintf(`
   449  provider "aws" {
   450  	region = "us-east-1"
   451  }
   452  resource "aws_security_group" "bar" {
   453      name = "tf-test-security-group-%s"
   454      description = "tf-test-security-group-descr"
   455      ingress {
   456          from_port = -1
   457          to_port = -1
   458          protocol = "icmp"
   459          cidr_blocks = ["0.0.0.0/0"]
   460      }
   461  }
   462  
   463  resource "aws_elasticache_security_group" "bar" {
   464      name = "tf-test-security-group-%s"
   465      description = "tf-test-security-group-descr"
   466      security_group_names = ["${aws_security_group.bar.name}"]
   467  }
   468  
   469  resource "aws_elasticache_replication_group" "bar" {
   470      replication_group_id = "tf-%s"
   471      replication_group_description = "updated description"
   472      node_type = "cache.m1.medium"
   473      number_cache_clusters = 2
   474      port = 6379
   475      parameter_group_name = "default.redis3.2"
   476      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   477      apply_immediately = true
   478  }`, rName, rName, rName)
   479  }
   480  
   481  var testAccAWSElasticacheReplicationGroupInVPCConfig = fmt.Sprintf(`
   482  resource "aws_vpc" "foo" {
   483      cidr_block = "192.168.0.0/16"
   484      tags {
   485              Name = "tf-test"
   486      }
   487  }
   488  
   489  resource "aws_subnet" "foo" {
   490      vpc_id = "${aws_vpc.foo.id}"
   491      cidr_block = "192.168.0.0/20"
   492      availability_zone = "us-west-2a"
   493      tags {
   494              Name = "tf-test"
   495      }
   496  }
   497  
   498  resource "aws_elasticache_subnet_group" "bar" {
   499      name = "tf-test-cache-subnet-%03d"
   500      description = "tf-test-cache-subnet-group-descr"
   501      subnet_ids = ["${aws_subnet.foo.id}"]
   502  }
   503  
   504  resource "aws_security_group" "bar" {
   505      name = "tf-test-security-group-%03d"
   506      description = "tf-test-security-group-descr"
   507      vpc_id = "${aws_vpc.foo.id}"
   508      ingress {
   509          from_port = -1
   510          to_port = -1
   511          protocol = "icmp"
   512          cidr_blocks = ["0.0.0.0/0"]
   513      }
   514  }
   515  
   516  resource "aws_elasticache_replication_group" "bar" {
   517      replication_group_id = "tf-%s"
   518      replication_group_description = "test description"
   519      node_type = "cache.m1.small"
   520      number_cache_clusters = 1
   521      port = 6379
   522      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   523      security_group_ids = ["${aws_security_group.bar.id}"]
   524      parameter_group_name = "default.redis3.2"
   525      availability_zones = ["us-west-2a"]
   526      auto_minor_version_upgrade = false
   527  }
   528  
   529  `, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
   530  
   531  var testAccAWSElasticacheReplicationGroupMultiAZInVPCConfig = fmt.Sprintf(`
   532  resource "aws_vpc" "foo" {
   533      cidr_block = "192.168.0.0/16"
   534      tags {
   535              Name = "tf-test"
   536      }
   537  }
   538  
   539  resource "aws_subnet" "foo" {
   540      vpc_id = "${aws_vpc.foo.id}"
   541      cidr_block = "192.168.0.0/20"
   542      availability_zone = "us-west-2a"
   543      tags {
   544              Name = "tf-test-%03d"
   545      }
   546  }
   547  
   548  resource "aws_subnet" "bar" {
   549      vpc_id = "${aws_vpc.foo.id}"
   550      cidr_block = "192.168.16.0/20"
   551      availability_zone = "us-west-2b"
   552      tags {
   553              Name = "tf-test-%03d"
   554      }
   555  }
   556  
   557  resource "aws_elasticache_subnet_group" "bar" {
   558      name = "tf-test-cache-subnet-%03d"
   559      description = "tf-test-cache-subnet-group-descr"
   560      subnet_ids = [
   561          "${aws_subnet.foo.id}",
   562          "${aws_subnet.bar.id}"
   563      ]
   564  }
   565  
   566  resource "aws_security_group" "bar" {
   567      name = "tf-test-security-group-%03d"
   568      description = "tf-test-security-group-descr"
   569      vpc_id = "${aws_vpc.foo.id}"
   570      ingress {
   571          from_port = -1
   572          to_port = -1
   573          protocol = "icmp"
   574          cidr_blocks = ["0.0.0.0/0"]
   575      }
   576  }
   577  
   578  resource "aws_elasticache_replication_group" "bar" {
   579      replication_group_id = "tf-%s"
   580      replication_group_description = "test description"
   581      node_type = "cache.m1.small"
   582      number_cache_clusters = 2
   583      port = 6379
   584      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   585      security_group_ids = ["${aws_security_group.bar.id}"]
   586      parameter_group_name = "default.redis3.2"
   587      availability_zones = ["us-west-2a","us-west-2b"]
   588      automatic_failover_enabled = true
   589      snapshot_window = "02:00-03:00"
   590      snapshot_retention_limit = 7
   591  }
   592  `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
   593  
   594  var testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig = fmt.Sprintf(`
   595  resource "aws_vpc" "foo" {
   596      cidr_block = "192.168.0.0/16"
   597      tags {
   598              Name = "tf-test"
   599      }
   600  }
   601  
   602  resource "aws_subnet" "foo" {
   603      vpc_id = "${aws_vpc.foo.id}"
   604      cidr_block = "192.168.0.0/20"
   605      availability_zone = "us-west-2a"
   606      tags {
   607              Name = "tf-test-%03d"
   608      }
   609  }
   610  
   611  resource "aws_subnet" "bar" {
   612      vpc_id = "${aws_vpc.foo.id}"
   613      cidr_block = "192.168.16.0/20"
   614      availability_zone = "us-west-2b"
   615      tags {
   616              Name = "tf-test-%03d"
   617      }
   618  }
   619  
   620  resource "aws_elasticache_subnet_group" "bar" {
   621      name = "tf-test-cache-subnet-%03d"
   622      description = "tf-test-cache-subnet-group-descr"
   623      subnet_ids = [
   624          "${aws_subnet.foo.id}",
   625          "${aws_subnet.bar.id}"
   626      ]
   627  }
   628  
   629  resource "aws_security_group" "bar" {
   630      name = "tf-test-security-group-%03d"
   631      description = "tf-test-security-group-descr"
   632      vpc_id = "${aws_vpc.foo.id}"
   633      ingress {
   634          from_port = -1
   635          to_port = -1
   636          protocol = "icmp"
   637          cidr_blocks = ["0.0.0.0/0"]
   638      }
   639  }
   640  
   641  resource "aws_elasticache_replication_group" "bar" {
   642      replication_group_id = "tf-%s"
   643      replication_group_description = "test description"
   644      node_type = "cache.t2.micro"
   645      number_cache_clusters = "2"
   646      port = 6379
   647      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   648      security_group_ids = ["${aws_security_group.bar.id}"]
   649      parameter_group_name = "default.redis3.2.cluster.on"
   650      availability_zones = ["us-west-2a","us-west-2b"]
   651      automatic_failover_enabled = true
   652      snapshot_window = "02:00-03:00"
   653      snapshot_retention_limit = 7
   654      engine_version = "3.2.4"
   655      maintenance_window = "thu:03:00-thu:04:00"
   656  }
   657  `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))