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