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