github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/aws/resource_aws_elasticache_replication_group_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"testing"
     7  
     8  	"github.com/aws/aws-sdk-go/aws"
     9  	"github.com/aws/aws-sdk-go/aws/awserr"
    10  	"github.com/aws/aws-sdk-go/service/elasticache"
    11  	"github.com/hashicorp/terraform/helper/acctest"
    12  	"github.com/hashicorp/terraform/helper/resource"
    13  	"github.com/hashicorp/terraform/terraform"
    14  )
    15  
    16  func TestAccAWSElasticacheReplicationGroup_basic(t *testing.T) {
    17  	var rg elasticache.ReplicationGroup
    18  
    19  	resource.Test(t, resource.TestCase{
    20  		PreCheck:     func() { testAccPreCheck(t) },
    21  		Providers:    testAccProviders,
    22  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    23  		Steps: []resource.TestStep{
    24  			{
    25  				Config: testAccAWSElasticacheReplicationGroupConfig(acctest.RandString(10)),
    26  				Check: resource.ComposeTestCheckFunc(
    27  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    28  					resource.TestCheckResourceAttr(
    29  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    30  					resource.TestCheckResourceAttr(
    31  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
    32  				),
    33  			},
    34  		},
    35  	})
    36  }
    37  
    38  func TestAccAWSElasticacheReplicationGroup_updateDescription(t *testing.T) {
    39  	var rg elasticache.ReplicationGroup
    40  	rName := acctest.RandString(10)
    41  	resource.Test(t, resource.TestCase{
    42  		PreCheck:     func() { testAccPreCheck(t) },
    43  		Providers:    testAccProviders,
    44  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    45  		Steps: []resource.TestStep{
    46  			{
    47  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
    48  				Check: resource.ComposeTestCheckFunc(
    49  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    50  					resource.TestCheckResourceAttr(
    51  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    52  					resource.TestCheckResourceAttr(
    53  						"aws_elasticache_replication_group.bar", "replication_group_description", "test description"),
    54  					resource.TestCheckResourceAttr(
    55  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
    56  				),
    57  			},
    58  
    59  			{
    60  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName),
    61  				Check: resource.ComposeTestCheckFunc(
    62  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    63  					resource.TestCheckResourceAttr(
    64  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
    65  					resource.TestCheckResourceAttr(
    66  						"aws_elasticache_replication_group.bar", "replication_group_description", "updated description"),
    67  					resource.TestCheckResourceAttr(
    68  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "true"),
    69  				),
    70  			},
    71  		},
    72  	})
    73  }
    74  
    75  func TestAccAWSElasticacheReplicationGroup_updateMaintenanceWindow(t *testing.T) {
    76  	var rg elasticache.ReplicationGroup
    77  	rName := acctest.RandString(10)
    78  	resource.Test(t, resource.TestCase{
    79  		PreCheck:     func() { testAccPreCheck(t) },
    80  		Providers:    testAccProviders,
    81  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
    82  		Steps: []resource.TestStep{
    83  			{
    84  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
    85  				Check: resource.ComposeTestCheckFunc(
    86  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    87  					resource.TestCheckResourceAttr(
    88  						"aws_elasticache_replication_group.bar", "maintenance_window", "tue:06:30-tue:07:30"),
    89  				),
    90  			},
    91  			{
    92  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedMaintenanceWindow(rName),
    93  				Check: resource.ComposeTestCheckFunc(
    94  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
    95  					resource.TestCheckResourceAttr(
    96  						"aws_elasticache_replication_group.bar", "maintenance_window", "wed:03:00-wed:06:00"),
    97  				),
    98  			},
    99  		},
   100  	})
   101  }
   102  
   103  func TestAccAWSElasticacheReplicationGroup_updateNodeSize(t *testing.T) {
   104  	var rg elasticache.ReplicationGroup
   105  	rName := acctest.RandString(10)
   106  	resource.Test(t, resource.TestCase{
   107  		PreCheck:     func() { testAccPreCheck(t) },
   108  		Providers:    testAccProviders,
   109  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   110  		Steps: []resource.TestStep{
   111  			{
   112  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
   113  				Check: resource.ComposeTestCheckFunc(
   114  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   115  					resource.TestCheckResourceAttr(
   116  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   117  					resource.TestCheckResourceAttr(
   118  						"aws_elasticache_replication_group.bar", "node_type", "cache.m1.small"),
   119  				),
   120  			},
   121  
   122  			{
   123  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedNodeSize(rName),
   124  				Check: resource.ComposeTestCheckFunc(
   125  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   126  					resource.TestCheckResourceAttr(
   127  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   128  					resource.TestCheckResourceAttr(
   129  						"aws_elasticache_replication_group.bar", "node_type", "cache.m1.medium"),
   130  				),
   131  			},
   132  		},
   133  	})
   134  }
   135  
   136  //This is a test to prove that we panic we get in https://github.com/hashicorp/terraform/issues/9097
   137  func TestAccAWSElasticacheReplicationGroup_updateParameterGroup(t *testing.T) {
   138  	var rg elasticache.ReplicationGroup
   139  	rName := acctest.RandString(10)
   140  	rInt := acctest.RandInt()
   141  	resource.Test(t, resource.TestCase{
   142  		PreCheck:     func() { testAccPreCheck(t) },
   143  		Providers:    testAccProviders,
   144  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   145  		Steps: []resource.TestStep{
   146  			{
   147  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
   148  				Check: resource.ComposeTestCheckFunc(
   149  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   150  					resource.TestCheckResourceAttr(
   151  						"aws_elasticache_replication_group.bar", "parameter_group_name", "default.redis3.2"),
   152  				),
   153  			},
   154  
   155  			{
   156  				Config: testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName, rInt),
   157  				Check: resource.ComposeTestCheckFunc(
   158  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   159  					resource.TestCheckResourceAttr(
   160  						"aws_elasticache_replication_group.bar", "parameter_group_name", fmt.Sprintf("allkeys-lru-%d", rInt)),
   161  				),
   162  			},
   163  		},
   164  	})
   165  }
   166  
   167  func TestAccAWSElasticacheReplicationGroup_vpc(t *testing.T) {
   168  	var rg elasticache.ReplicationGroup
   169  	resource.Test(t, resource.TestCase{
   170  		PreCheck:     func() { testAccPreCheck(t) },
   171  		Providers:    testAccProviders,
   172  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   173  		Steps: []resource.TestStep{
   174  			{
   175  				Config: testAccAWSElasticacheReplicationGroupInVPCConfig,
   176  				Check: resource.ComposeTestCheckFunc(
   177  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   178  					resource.TestCheckResourceAttr(
   179  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "1"),
   180  					resource.TestCheckResourceAttr(
   181  						"aws_elasticache_replication_group.bar", "auto_minor_version_upgrade", "false"),
   182  				),
   183  			},
   184  		},
   185  	})
   186  }
   187  
   188  func TestAccAWSElasticacheReplicationGroup_multiAzInVpc(t *testing.T) {
   189  	var rg elasticache.ReplicationGroup
   190  	resource.Test(t, resource.TestCase{
   191  		PreCheck:     func() { testAccPreCheck(t) },
   192  		Providers:    testAccProviders,
   193  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   194  		Steps: []resource.TestStep{
   195  			{
   196  				Config: testAccAWSElasticacheReplicationGroupMultiAZInVPCConfig,
   197  				Check: resource.ComposeTestCheckFunc(
   198  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   199  					resource.TestCheckResourceAttr(
   200  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   201  					resource.TestCheckResourceAttr(
   202  						"aws_elasticache_replication_group.bar", "automatic_failover_enabled", "true"),
   203  					resource.TestCheckResourceAttr(
   204  						"aws_elasticache_replication_group.bar", "snapshot_window", "02:00-03:00"),
   205  					resource.TestCheckResourceAttr(
   206  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "7"),
   207  					resource.TestCheckResourceAttrSet(
   208  						"aws_elasticache_replication_group.bar", "primary_endpoint_address"),
   209  				),
   210  			},
   211  		},
   212  	})
   213  }
   214  
   215  func TestAccAWSElasticacheReplicationGroup_redisClusterInVpc2(t *testing.T) {
   216  	var rg elasticache.ReplicationGroup
   217  	resource.Test(t, resource.TestCase{
   218  		PreCheck:     func() { testAccPreCheck(t) },
   219  		Providers:    testAccProviders,
   220  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   221  		Steps: []resource.TestStep{
   222  			{
   223  				Config: testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig,
   224  				Check: resource.ComposeTestCheckFunc(
   225  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   226  					resource.TestCheckResourceAttr(
   227  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "2"),
   228  					resource.TestCheckResourceAttr(
   229  						"aws_elasticache_replication_group.bar", "automatic_failover_enabled", "true"),
   230  					resource.TestCheckResourceAttr(
   231  						"aws_elasticache_replication_group.bar", "snapshot_window", "02:00-03:00"),
   232  					resource.TestCheckResourceAttr(
   233  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "7"),
   234  					resource.TestCheckResourceAttrSet(
   235  						"aws_elasticache_replication_group.bar", "configuration_endpoint_address"),
   236  				),
   237  			},
   238  		},
   239  	})
   240  }
   241  
   242  func TestAccAWSElasticacheReplicationGroup_nativeRedisCluster(t *testing.T) {
   243  	var rg elasticache.ReplicationGroup
   244  	rInt := acctest.RandInt()
   245  	rName := acctest.RandString(10)
   246  
   247  	resource.Test(t, resource.TestCase{
   248  		PreCheck:     func() { testAccPreCheck(t) },
   249  		Providers:    testAccProviders,
   250  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   251  		Steps: []resource.TestStep{
   252  			{
   253  				Config: testAccAWSElasticacheReplicationGroupNativeRedisClusterConfig(rInt, rName),
   254  				Check: resource.ComposeTestCheckFunc(
   255  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   256  					resource.TestCheckResourceAttr(
   257  						"aws_elasticache_replication_group.bar", "number_cache_clusters", "4"),
   258  					resource.TestCheckResourceAttr(
   259  						"aws_elasticache_replication_group.bar", "cluster_mode.#", "1"),
   260  					resource.TestCheckResourceAttr(
   261  						"aws_elasticache_replication_group.bar", "cluster_mode.4170186206.num_node_groups", "2"),
   262  					resource.TestCheckResourceAttr(
   263  						"aws_elasticache_replication_group.bar", "cluster_mode.4170186206.replicas_per_node_group", "1"),
   264  					resource.TestCheckResourceAttr(
   265  						"aws_elasticache_replication_group.bar", "port", "6379"),
   266  					resource.TestCheckResourceAttrSet(
   267  						"aws_elasticache_replication_group.bar", "configuration_endpoint_address"),
   268  				),
   269  			},
   270  		},
   271  	})
   272  }
   273  
   274  func TestAccAWSElasticacheReplicationGroup_clusteringAndCacheNodesCausesError(t *testing.T) {
   275  	rInt := acctest.RandInt()
   276  	rName := acctest.RandString(10)
   277  
   278  	resource.Test(t, resource.TestCase{
   279  		PreCheck:     func() { testAccPreCheck(t) },
   280  		Providers:    testAccProviders,
   281  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   282  		Steps: []resource.TestStep{
   283  			{
   284  				Config:      testAccAWSElasticacheReplicationGroupNativeRedisClusterErrorConfig(rInt, rName),
   285  				ExpectError: regexp.MustCompile("Either `number_cache_clusters` or `cluster_mode` must be set"),
   286  			},
   287  		},
   288  	})
   289  }
   290  
   291  func TestAccAWSElasticacheReplicationGroup_enableSnapshotting(t *testing.T) {
   292  	var rg elasticache.ReplicationGroup
   293  	rName := acctest.RandString(10)
   294  
   295  	resource.Test(t, resource.TestCase{
   296  		PreCheck:     func() { testAccPreCheck(t) },
   297  		Providers:    testAccProviders,
   298  		CheckDestroy: testAccCheckAWSElasticacheReplicationDestroy,
   299  		Steps: []resource.TestStep{
   300  			{
   301  				Config: testAccAWSElasticacheReplicationGroupConfig(rName),
   302  				Check: resource.ComposeTestCheckFunc(
   303  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   304  					resource.TestCheckResourceAttr(
   305  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "0"),
   306  				),
   307  			},
   308  
   309  			{
   310  				Config: testAccAWSElasticacheReplicationGroupConfigEnableSnapshotting(rName),
   311  				Check: resource.ComposeTestCheckFunc(
   312  					testAccCheckAWSElasticacheReplicationGroupExists("aws_elasticache_replication_group.bar", &rg),
   313  					resource.TestCheckResourceAttr(
   314  						"aws_elasticache_replication_group.bar", "snapshot_retention_limit", "2"),
   315  				),
   316  			},
   317  		},
   318  	})
   319  }
   320  
   321  func TestResourceAWSElastiCacheReplicationGroupIdValidation(t *testing.T) {
   322  	cases := []struct {
   323  		Value    string
   324  		ErrCount int
   325  	}{
   326  		{
   327  			Value:    "tEsting",
   328  			ErrCount: 0,
   329  		},
   330  		{
   331  			Value:    "t.sting",
   332  			ErrCount: 1,
   333  		},
   334  		{
   335  			Value:    "t--sting",
   336  			ErrCount: 1,
   337  		},
   338  		{
   339  			Value:    "1testing",
   340  			ErrCount: 1,
   341  		},
   342  		{
   343  			Value:    "testing-",
   344  			ErrCount: 1,
   345  		},
   346  		{
   347  			Value:    randomString(21),
   348  			ErrCount: 1,
   349  		},
   350  	}
   351  
   352  	for _, tc := range cases {
   353  		_, errors := validateAwsElastiCacheReplicationGroupId(tc.Value, "aws_elasticache_replication_group_replication_group_id")
   354  
   355  		if len(errors) != tc.ErrCount {
   356  			t.Fatalf("Expected the ElastiCache Replication Group Id to trigger a validation error")
   357  		}
   358  	}
   359  }
   360  
   361  func TestResourceAWSElastiCacheReplicationGroupEngineValidation(t *testing.T) {
   362  	cases := []struct {
   363  		Value    string
   364  		ErrCount int
   365  	}{
   366  		{
   367  			Value:    "Redis",
   368  			ErrCount: 0,
   369  		},
   370  		{
   371  			Value:    "REDIS",
   372  			ErrCount: 0,
   373  		},
   374  		{
   375  			Value:    "memcached",
   376  			ErrCount: 1,
   377  		},
   378  	}
   379  
   380  	for _, tc := range cases {
   381  		_, errors := validateAwsElastiCacheReplicationGroupEngine(tc.Value, "aws_elasticache_replication_group_engine")
   382  
   383  		if len(errors) != tc.ErrCount {
   384  			t.Fatalf("Expected the ElastiCache Replication Group Engine to trigger a validation error")
   385  		}
   386  	}
   387  }
   388  
   389  func testAccCheckAWSElasticacheReplicationGroupExists(n string, v *elasticache.ReplicationGroup) resource.TestCheckFunc {
   390  	return func(s *terraform.State) error {
   391  		rs, ok := s.RootModule().Resources[n]
   392  		if !ok {
   393  			return fmt.Errorf("Not found: %s", n)
   394  		}
   395  
   396  		if rs.Primary.ID == "" {
   397  			return fmt.Errorf("No replication group ID is set")
   398  		}
   399  
   400  		conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
   401  		res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{
   402  			ReplicationGroupId: aws.String(rs.Primary.ID),
   403  		})
   404  		if err != nil {
   405  			return fmt.Errorf("Elasticache error: %v", err)
   406  		}
   407  
   408  		for _, rg := range res.ReplicationGroups {
   409  			if *rg.ReplicationGroupId == rs.Primary.ID {
   410  				*v = *rg
   411  			}
   412  		}
   413  
   414  		return nil
   415  	}
   416  }
   417  
   418  func testAccCheckAWSElasticacheReplicationDestroy(s *terraform.State) error {
   419  	conn := testAccProvider.Meta().(*AWSClient).elasticacheconn
   420  
   421  	for _, rs := range s.RootModule().Resources {
   422  		if rs.Type != "aws_elasticache_replication_group" {
   423  			continue
   424  		}
   425  		res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{
   426  			ReplicationGroupId: aws.String(rs.Primary.ID),
   427  		})
   428  		if err != nil {
   429  			// Verify the error is what we want
   430  			if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ReplicationGroupNotFoundFault" {
   431  				continue
   432  			}
   433  			return err
   434  		}
   435  		if len(res.ReplicationGroups) > 0 {
   436  			return fmt.Errorf("still exist.")
   437  		}
   438  	}
   439  	return nil
   440  }
   441  
   442  func testAccAWSElasticacheReplicationGroupConfig(rName string) string {
   443  	return fmt.Sprintf(`
   444  provider "aws" {
   445    region = "us-east-1"
   446  }
   447  resource "aws_security_group" "bar" {
   448      name = "tf-test-security-group-%s"
   449      description = "tf-test-security-group-descr"
   450      ingress {
   451          from_port = -1
   452          to_port = -1
   453          protocol = "icmp"
   454          cidr_blocks = ["0.0.0.0/0"]
   455      }
   456  }
   457  
   458  resource "aws_elasticache_security_group" "bar" {
   459      name = "tf-test-security-group-%s"
   460      description = "tf-test-security-group-descr"
   461      security_group_names = ["${aws_security_group.bar.name}"]
   462  }
   463  
   464  resource "aws_elasticache_replication_group" "bar" {
   465      replication_group_id = "tf-%s"
   466      replication_group_description = "test description"
   467      node_type = "cache.m1.small"
   468      number_cache_clusters = 2
   469      port = 6379
   470      parameter_group_name = "default.redis3.2"
   471      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   472      apply_immediately = true
   473      auto_minor_version_upgrade = false
   474      maintenance_window = "tue:06:30-tue:07:30"
   475      snapshot_window = "01:00-02:00"
   476  }`, rName, rName, rName)
   477  }
   478  
   479  func testAccAWSElasticacheReplicationGroupConfigEnableSnapshotting(rName string) string {
   480  	return fmt.Sprintf(`
   481  provider "aws" {
   482    region = "us-east-1"
   483  }
   484  resource "aws_security_group" "bar" {
   485      name = "tf-test-security-group-%s"
   486      description = "tf-test-security-group-descr"
   487      ingress {
   488          from_port = -1
   489          to_port = -1
   490          protocol = "icmp"
   491          cidr_blocks = ["0.0.0.0/0"]
   492      }
   493  }
   494  
   495  resource "aws_elasticache_security_group" "bar" {
   496      name = "tf-test-security-group-%s"
   497      description = "tf-test-security-group-descr"
   498      security_group_names = ["${aws_security_group.bar.name}"]
   499  }
   500  
   501  resource "aws_elasticache_replication_group" "bar" {
   502      replication_group_id = "tf-%s"
   503      replication_group_description = "test description"
   504      node_type = "cache.m1.small"
   505      number_cache_clusters = 2
   506      port = 6379
   507      parameter_group_name = "default.redis3.2"
   508      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   509      apply_immediately = true
   510      auto_minor_version_upgrade = false
   511      maintenance_window = "tue:06:30-tue:07:30"
   512      snapshot_window = "01:00-02:00"
   513      snapshot_retention_limit = 2
   514  }`, rName, rName, rName)
   515  }
   516  
   517  func testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName string, rInt int) string {
   518  	return fmt.Sprintf(`
   519  provider "aws" {
   520    region = "us-east-1"
   521  }
   522  resource "aws_security_group" "bar" {
   523      name = "tf-test-security-group-%s"
   524      description = "tf-test-security-group-descr"
   525      ingress {
   526          from_port = -1
   527          to_port = -1
   528          protocol = "icmp"
   529          cidr_blocks = ["0.0.0.0/0"]
   530      }
   531  }
   532  
   533  resource "aws_elasticache_security_group" "bar" {
   534      name = "tf-test-security-group-%s"
   535      description = "tf-test-security-group-descr"
   536      security_group_names = ["${aws_security_group.bar.name}"]
   537  }
   538  
   539  resource "aws_elasticache_parameter_group" "bar" {
   540      name = "allkeys-lru-%d"
   541      family = "redis3.2"
   542  
   543      parameter {
   544          name = "maxmemory-policy"
   545          value = "allkeys-lru"
   546      }
   547  }
   548  
   549  resource "aws_elasticache_replication_group" "bar" {
   550      replication_group_id = "tf-%s"
   551      replication_group_description = "test description"
   552      node_type = "cache.m1.small"
   553      number_cache_clusters = 2
   554      port = 6379
   555      parameter_group_name = "${aws_elasticache_parameter_group.bar.name}"
   556      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   557      apply_immediately = true
   558  }`, rName, rName, rInt, rName)
   559  }
   560  
   561  func testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName string) string {
   562  	return fmt.Sprintf(`
   563  provider "aws" {
   564  	region = "us-east-1"
   565  }
   566  resource "aws_security_group" "bar" {
   567      name = "tf-test-security-group-%s"
   568      description = "tf-test-security-group-descr"
   569      ingress {
   570          from_port = -1
   571          to_port = -1
   572          protocol = "icmp"
   573          cidr_blocks = ["0.0.0.0/0"]
   574      }
   575  }
   576  
   577  resource "aws_elasticache_security_group" "bar" {
   578      name = "tf-test-security-group-%s"
   579      description = "tf-test-security-group-descr"
   580      security_group_names = ["${aws_security_group.bar.name}"]
   581  }
   582  
   583  resource "aws_elasticache_replication_group" "bar" {
   584      replication_group_id = "tf-%s"
   585      replication_group_description = "updated description"
   586      node_type = "cache.m1.small"
   587      number_cache_clusters = 2
   588      port = 6379
   589      parameter_group_name = "default.redis3.2"
   590      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   591      apply_immediately = true
   592      auto_minor_version_upgrade = true
   593  }`, rName, rName, rName)
   594  }
   595  
   596  func testAccAWSElasticacheReplicationGroupConfigUpdatedMaintenanceWindow(rName string) string {
   597  	return fmt.Sprintf(`
   598  provider "aws" {
   599  	region = "us-east-1"
   600  }
   601  resource "aws_security_group" "bar" {
   602      name = "tf-test-security-group-%s"
   603      description = "tf-test-security-group-descr"
   604      ingress {
   605          from_port = -1
   606          to_port = -1
   607          protocol = "icmp"
   608          cidr_blocks = ["0.0.0.0/0"]
   609      }
   610  }
   611  
   612  resource "aws_elasticache_security_group" "bar" {
   613      name = "tf-test-security-group-%s"
   614      description = "tf-test-security-group-descr"
   615      security_group_names = ["${aws_security_group.bar.name}"]
   616  }
   617  
   618  resource "aws_elasticache_replication_group" "bar" {
   619      replication_group_id = "tf-%s"
   620      replication_group_description = "updated description"
   621      node_type = "cache.m1.small"
   622      number_cache_clusters = 2
   623      port = 6379
   624      parameter_group_name = "default.redis3.2"
   625      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   626      apply_immediately = true
   627      auto_minor_version_upgrade = true
   628      maintenance_window = "wed:03:00-wed:06:00"
   629      snapshot_window = "01:00-02:00"
   630  }`, rName, rName, rName)
   631  }
   632  
   633  func testAccAWSElasticacheReplicationGroupConfigUpdatedNodeSize(rName string) string {
   634  	return fmt.Sprintf(`
   635  provider "aws" {
   636  	region = "us-east-1"
   637  }
   638  resource "aws_security_group" "bar" {
   639      name = "tf-test-security-group-%s"
   640      description = "tf-test-security-group-descr"
   641      ingress {
   642          from_port = -1
   643          to_port = -1
   644          protocol = "icmp"
   645          cidr_blocks = ["0.0.0.0/0"]
   646      }
   647  }
   648  
   649  resource "aws_elasticache_security_group" "bar" {
   650      name = "tf-test-security-group-%s"
   651      description = "tf-test-security-group-descr"
   652      security_group_names = ["${aws_security_group.bar.name}"]
   653  }
   654  
   655  resource "aws_elasticache_replication_group" "bar" {
   656      replication_group_id = "tf-%s"
   657      replication_group_description = "updated description"
   658      node_type = "cache.m1.medium"
   659      number_cache_clusters = 2
   660      port = 6379
   661      parameter_group_name = "default.redis3.2"
   662      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
   663      apply_immediately = true
   664  }`, rName, rName, rName)
   665  }
   666  
   667  var testAccAWSElasticacheReplicationGroupInVPCConfig = fmt.Sprintf(`
   668  resource "aws_vpc" "foo" {
   669      cidr_block = "192.168.0.0/16"
   670      tags {
   671              Name = "tf-test"
   672      }
   673  }
   674  
   675  resource "aws_subnet" "foo" {
   676      vpc_id = "${aws_vpc.foo.id}"
   677      cidr_block = "192.168.0.0/20"
   678      availability_zone = "us-west-2a"
   679      tags {
   680              Name = "tf-test"
   681      }
   682  }
   683  
   684  resource "aws_elasticache_subnet_group" "bar" {
   685      name = "tf-test-cache-subnet-%03d"
   686      description = "tf-test-cache-subnet-group-descr"
   687      subnet_ids = ["${aws_subnet.foo.id}"]
   688  }
   689  
   690  resource "aws_security_group" "bar" {
   691      name = "tf-test-security-group-%03d"
   692      description = "tf-test-security-group-descr"
   693      vpc_id = "${aws_vpc.foo.id}"
   694      ingress {
   695          from_port = -1
   696          to_port = -1
   697          protocol = "icmp"
   698          cidr_blocks = ["0.0.0.0/0"]
   699      }
   700  }
   701  
   702  resource "aws_elasticache_replication_group" "bar" {
   703      replication_group_id = "tf-%s"
   704      replication_group_description = "test description"
   705      node_type = "cache.m1.small"
   706      number_cache_clusters = 1
   707      port = 6379
   708      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   709      security_group_ids = ["${aws_security_group.bar.id}"]
   710      parameter_group_name = "default.redis3.2"
   711      availability_zones = ["us-west-2a"]
   712      auto_minor_version_upgrade = false
   713  }
   714  
   715  `, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
   716  
   717  var testAccAWSElasticacheReplicationGroupMultiAZInVPCConfig = fmt.Sprintf(`
   718  resource "aws_vpc" "foo" {
   719      cidr_block = "192.168.0.0/16"
   720      tags {
   721              Name = "tf-test"
   722      }
   723  }
   724  
   725  resource "aws_subnet" "foo" {
   726      vpc_id = "${aws_vpc.foo.id}"
   727      cidr_block = "192.168.0.0/20"
   728      availability_zone = "us-west-2a"
   729      tags {
   730              Name = "tf-test-%03d"
   731      }
   732  }
   733  
   734  resource "aws_subnet" "bar" {
   735      vpc_id = "${aws_vpc.foo.id}"
   736      cidr_block = "192.168.16.0/20"
   737      availability_zone = "us-west-2b"
   738      tags {
   739              Name = "tf-test-%03d"
   740      }
   741  }
   742  
   743  resource "aws_elasticache_subnet_group" "bar" {
   744      name = "tf-test-cache-subnet-%03d"
   745      description = "tf-test-cache-subnet-group-descr"
   746      subnet_ids = [
   747          "${aws_subnet.foo.id}",
   748          "${aws_subnet.bar.id}"
   749      ]
   750  }
   751  
   752  resource "aws_security_group" "bar" {
   753      name = "tf-test-security-group-%03d"
   754      description = "tf-test-security-group-descr"
   755      vpc_id = "${aws_vpc.foo.id}"
   756      ingress {
   757          from_port = -1
   758          to_port = -1
   759          protocol = "icmp"
   760          cidr_blocks = ["0.0.0.0/0"]
   761      }
   762  }
   763  
   764  resource "aws_elasticache_replication_group" "bar" {
   765      replication_group_id = "tf-%s"
   766      replication_group_description = "test description"
   767      node_type = "cache.m1.small"
   768      number_cache_clusters = 2
   769      port = 6379
   770      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   771      security_group_ids = ["${aws_security_group.bar.id}"]
   772      parameter_group_name = "default.redis3.2"
   773      availability_zones = ["us-west-2a","us-west-2b"]
   774      automatic_failover_enabled = true
   775      snapshot_window = "02:00-03:00"
   776      snapshot_retention_limit = 7
   777  }
   778  `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
   779  
   780  var testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig = fmt.Sprintf(`
   781  resource "aws_vpc" "foo" {
   782      cidr_block = "192.168.0.0/16"
   783      tags {
   784              Name = "tf-test"
   785      }
   786  }
   787  
   788  resource "aws_subnet" "foo" {
   789      vpc_id = "${aws_vpc.foo.id}"
   790      cidr_block = "192.168.0.0/20"
   791      availability_zone = "us-west-2a"
   792      tags {
   793              Name = "tf-test-%03d"
   794      }
   795  }
   796  
   797  resource "aws_subnet" "bar" {
   798      vpc_id = "${aws_vpc.foo.id}"
   799      cidr_block = "192.168.16.0/20"
   800      availability_zone = "us-west-2b"
   801      tags {
   802              Name = "tf-test-%03d"
   803      }
   804  }
   805  
   806  resource "aws_elasticache_subnet_group" "bar" {
   807      name = "tf-test-cache-subnet-%03d"
   808      description = "tf-test-cache-subnet-group-descr"
   809      subnet_ids = [
   810          "${aws_subnet.foo.id}",
   811          "${aws_subnet.bar.id}"
   812      ]
   813  }
   814  
   815  resource "aws_security_group" "bar" {
   816      name = "tf-test-security-group-%03d"
   817      description = "tf-test-security-group-descr"
   818      vpc_id = "${aws_vpc.foo.id}"
   819      ingress {
   820          from_port = -1
   821          to_port = -1
   822          protocol = "icmp"
   823          cidr_blocks = ["0.0.0.0/0"]
   824      }
   825  }
   826  
   827  resource "aws_elasticache_replication_group" "bar" {
   828      replication_group_id = "tf-%s"
   829      replication_group_description = "test description"
   830      node_type = "cache.t2.micro"
   831      number_cache_clusters = "2"
   832      port = 6379
   833      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   834      security_group_ids = ["${aws_security_group.bar.id}"]
   835      parameter_group_name = "default.redis3.2.cluster.on"
   836      availability_zones = ["us-west-2a","us-west-2b"]
   837      automatic_failover_enabled = true
   838      snapshot_window = "02:00-03:00"
   839      snapshot_retention_limit = 7
   840      engine_version = "3.2.4"
   841      maintenance_window = "thu:03:00-thu:04:00"
   842  }
   843  `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10))
   844  
   845  func testAccAWSElasticacheReplicationGroupNativeRedisClusterErrorConfig(rInt int, rName string) string {
   846  	return fmt.Sprintf(`
   847  resource "aws_vpc" "foo" {
   848      cidr_block = "192.168.0.0/16"
   849      tags {
   850          Name = "tf-test"
   851      }
   852  }
   853  
   854  resource "aws_subnet" "foo" {
   855      vpc_id = "${aws_vpc.foo.id}"
   856      cidr_block = "192.168.0.0/20"
   857      availability_zone = "us-west-2a"
   858      tags {
   859          Name = "tf-test-%03d"
   860      }
   861  }
   862  
   863  resource "aws_subnet" "bar" {
   864      vpc_id = "${aws_vpc.foo.id}"
   865      cidr_block = "192.168.16.0/20"
   866      availability_zone = "us-west-2b"
   867      tags {
   868          Name = "tf-test-%03d"
   869      }
   870  }
   871  
   872  resource "aws_elasticache_subnet_group" "bar" {
   873      name = "tf-test-cache-subnet-%03d"
   874      description = "tf-test-cache-subnet-group-descr"
   875      subnet_ids = [
   876          "${aws_subnet.foo.id}",
   877          "${aws_subnet.bar.id}"
   878      ]
   879  }
   880  
   881  resource "aws_security_group" "bar" {
   882      name = "tf-test-security-group-%03d"
   883      description = "tf-test-security-group-descr"
   884      vpc_id = "${aws_vpc.foo.id}"
   885      ingress {
   886          from_port = -1
   887          to_port = -1
   888          protocol = "icmp"
   889          cidr_blocks = ["0.0.0.0/0"]
   890      }
   891  }
   892  
   893  resource "aws_elasticache_replication_group" "bar" {
   894      replication_group_id = "tf-%s"
   895      replication_group_description = "test description"
   896      node_type = "cache.t2.micro"
   897      port = 6379
   898      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   899      security_group_ids = ["${aws_security_group.bar.id}"]
   900      parameter_group_name = "default.redis3.2.cluster.on"
   901      automatic_failover_enabled = true
   902      cluster_mode {
   903        replicas_per_node_group = 1
   904        num_node_groups = 2
   905      }
   906      number_cache_clusters = 3
   907  }`, rInt, rInt, rInt, rInt, rName)
   908  }
   909  
   910  func testAccAWSElasticacheReplicationGroupNativeRedisClusterConfig(rInt int, rName string) string {
   911  	return fmt.Sprintf(`
   912  resource "aws_vpc" "foo" {
   913      cidr_block = "192.168.0.0/16"
   914      tags {
   915          Name = "tf-test"
   916      }
   917  }
   918  
   919  resource "aws_subnet" "foo" {
   920      vpc_id = "${aws_vpc.foo.id}"
   921      cidr_block = "192.168.0.0/20"
   922      availability_zone = "us-west-2a"
   923      tags {
   924          Name = "tf-test-%03d"
   925      }
   926  }
   927  
   928  resource "aws_subnet" "bar" {
   929      vpc_id = "${aws_vpc.foo.id}"
   930      cidr_block = "192.168.16.0/20"
   931      availability_zone = "us-west-2b"
   932      tags {
   933          Name = "tf-test-%03d"
   934      }
   935  }
   936  
   937  resource "aws_elasticache_subnet_group" "bar" {
   938      name = "tf-test-cache-subnet-%03d"
   939      description = "tf-test-cache-subnet-group-descr"
   940      subnet_ids = [
   941          "${aws_subnet.foo.id}",
   942          "${aws_subnet.bar.id}"
   943      ]
   944  }
   945  
   946  resource "aws_security_group" "bar" {
   947      name = "tf-test-security-group-%03d"
   948      description = "tf-test-security-group-descr"
   949      vpc_id = "${aws_vpc.foo.id}"
   950      ingress {
   951          from_port = -1
   952          to_port = -1
   953          protocol = "icmp"
   954          cidr_blocks = ["0.0.0.0/0"]
   955      }
   956  }
   957  
   958  resource "aws_elasticache_replication_group" "bar" {
   959      replication_group_id = "tf-%s"
   960      replication_group_description = "test description"
   961      node_type = "cache.t2.micro"
   962      port = 6379
   963      subnet_group_name = "${aws_elasticache_subnet_group.bar.name}"
   964      security_group_ids = ["${aws_security_group.bar.id}"]
   965      parameter_group_name = "default.redis3.2.cluster.on"
   966      automatic_failover_enabled = true
   967      cluster_mode {
   968        replicas_per_node_group = 1
   969        num_node_groups = 2
   970      }
   971  }`, rInt, rInt, rInt, rInt, rName)
   972  }