github.com/IBM-Cloud/terraform@v0.6.4-0.20170726051544-8872b87621df/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 TestResourceAWSElastiCacheReplicationGroupIdValidation(t *testing.T) { 292 cases := []struct { 293 Value string 294 ErrCount int 295 }{ 296 { 297 Value: "tEsting", 298 ErrCount: 0, 299 }, 300 { 301 Value: "t.sting", 302 ErrCount: 1, 303 }, 304 { 305 Value: "t--sting", 306 ErrCount: 1, 307 }, 308 { 309 Value: "1testing", 310 ErrCount: 1, 311 }, 312 { 313 Value: "testing-", 314 ErrCount: 1, 315 }, 316 { 317 Value: randomString(21), 318 ErrCount: 1, 319 }, 320 } 321 322 for _, tc := range cases { 323 _, errors := validateAwsElastiCacheReplicationGroupId(tc.Value, "aws_elasticache_replication_group_replication_group_id") 324 325 if len(errors) != tc.ErrCount { 326 t.Fatalf("Expected the ElastiCache Replication Group Id to trigger a validation error") 327 } 328 } 329 } 330 331 func TestResourceAWSElastiCacheReplicationGroupEngineValidation(t *testing.T) { 332 cases := []struct { 333 Value string 334 ErrCount int 335 }{ 336 { 337 Value: "Redis", 338 ErrCount: 0, 339 }, 340 { 341 Value: "REDIS", 342 ErrCount: 0, 343 }, 344 { 345 Value: "memcached", 346 ErrCount: 1, 347 }, 348 } 349 350 for _, tc := range cases { 351 _, errors := validateAwsElastiCacheReplicationGroupEngine(tc.Value, "aws_elasticache_replication_group_engine") 352 353 if len(errors) != tc.ErrCount { 354 t.Fatalf("Expected the ElastiCache Replication Group Engine to trigger a validation error") 355 } 356 } 357 } 358 359 func testAccCheckAWSElasticacheReplicationGroupExists(n string, v *elasticache.ReplicationGroup) resource.TestCheckFunc { 360 return func(s *terraform.State) error { 361 rs, ok := s.RootModule().Resources[n] 362 if !ok { 363 return fmt.Errorf("Not found: %s", n) 364 } 365 366 if rs.Primary.ID == "" { 367 return fmt.Errorf("No replication group ID is set") 368 } 369 370 conn := testAccProvider.Meta().(*AWSClient).elasticacheconn 371 res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{ 372 ReplicationGroupId: aws.String(rs.Primary.ID), 373 }) 374 if err != nil { 375 return fmt.Errorf("Elasticache error: %v", err) 376 } 377 378 for _, rg := range res.ReplicationGroups { 379 if *rg.ReplicationGroupId == rs.Primary.ID { 380 *v = *rg 381 } 382 } 383 384 return nil 385 } 386 } 387 388 func testAccCheckAWSElasticacheReplicationDestroy(s *terraform.State) error { 389 conn := testAccProvider.Meta().(*AWSClient).elasticacheconn 390 391 for _, rs := range s.RootModule().Resources { 392 if rs.Type != "aws_elasticache_replication_group" { 393 continue 394 } 395 res, err := conn.DescribeReplicationGroups(&elasticache.DescribeReplicationGroupsInput{ 396 ReplicationGroupId: aws.String(rs.Primary.ID), 397 }) 398 if err != nil { 399 // Verify the error is what we want 400 if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "ReplicationGroupNotFoundFault" { 401 continue 402 } 403 return err 404 } 405 if len(res.ReplicationGroups) > 0 { 406 return fmt.Errorf("still exist.") 407 } 408 } 409 return nil 410 } 411 412 func testAccAWSElasticacheReplicationGroupConfig(rName string) string { 413 return fmt.Sprintf(` 414 provider "aws" { 415 region = "us-east-1" 416 } 417 resource "aws_security_group" "bar" { 418 name = "tf-test-security-group-%s" 419 description = "tf-test-security-group-descr" 420 ingress { 421 from_port = -1 422 to_port = -1 423 protocol = "icmp" 424 cidr_blocks = ["0.0.0.0/0"] 425 } 426 } 427 428 resource "aws_elasticache_security_group" "bar" { 429 name = "tf-test-security-group-%s" 430 description = "tf-test-security-group-descr" 431 security_group_names = ["${aws_security_group.bar.name}"] 432 } 433 434 resource "aws_elasticache_replication_group" "bar" { 435 replication_group_id = "tf-%s" 436 replication_group_description = "test description" 437 node_type = "cache.m1.small" 438 number_cache_clusters = 2 439 port = 6379 440 parameter_group_name = "default.redis3.2" 441 security_group_names = ["${aws_elasticache_security_group.bar.name}"] 442 apply_immediately = true 443 auto_minor_version_upgrade = false 444 maintenance_window = "tue:06:30-tue:07:30" 445 snapshot_window = "01:00-02:00" 446 }`, rName, rName, rName) 447 } 448 449 func testAccAWSElasticacheReplicationGroupConfigUpdatedParameterGroup(rName string, rInt int) string { 450 return fmt.Sprintf(` 451 provider "aws" { 452 region = "us-east-1" 453 } 454 resource "aws_security_group" "bar" { 455 name = "tf-test-security-group-%s" 456 description = "tf-test-security-group-descr" 457 ingress { 458 from_port = -1 459 to_port = -1 460 protocol = "icmp" 461 cidr_blocks = ["0.0.0.0/0"] 462 } 463 } 464 465 resource "aws_elasticache_security_group" "bar" { 466 name = "tf-test-security-group-%s" 467 description = "tf-test-security-group-descr" 468 security_group_names = ["${aws_security_group.bar.name}"] 469 } 470 471 resource "aws_elasticache_parameter_group" "bar" { 472 name = "allkeys-lru-%d" 473 family = "redis3.2" 474 475 parameter { 476 name = "maxmemory-policy" 477 value = "allkeys-lru" 478 } 479 } 480 481 resource "aws_elasticache_replication_group" "bar" { 482 replication_group_id = "tf-%s" 483 replication_group_description = "test description" 484 node_type = "cache.m1.small" 485 number_cache_clusters = 2 486 port = 6379 487 parameter_group_name = "${aws_elasticache_parameter_group.bar.name}" 488 security_group_names = ["${aws_elasticache_security_group.bar.name}"] 489 apply_immediately = true 490 }`, rName, rName, rInt, rName) 491 } 492 493 func testAccAWSElasticacheReplicationGroupConfigUpdatedDescription(rName string) string { 494 return fmt.Sprintf(` 495 provider "aws" { 496 region = "us-east-1" 497 } 498 resource "aws_security_group" "bar" { 499 name = "tf-test-security-group-%s" 500 description = "tf-test-security-group-descr" 501 ingress { 502 from_port = -1 503 to_port = -1 504 protocol = "icmp" 505 cidr_blocks = ["0.0.0.0/0"] 506 } 507 } 508 509 resource "aws_elasticache_security_group" "bar" { 510 name = "tf-test-security-group-%s" 511 description = "tf-test-security-group-descr" 512 security_group_names = ["${aws_security_group.bar.name}"] 513 } 514 515 resource "aws_elasticache_replication_group" "bar" { 516 replication_group_id = "tf-%s" 517 replication_group_description = "updated description" 518 node_type = "cache.m1.small" 519 number_cache_clusters = 2 520 port = 6379 521 parameter_group_name = "default.redis3.2" 522 security_group_names = ["${aws_elasticache_security_group.bar.name}"] 523 apply_immediately = true 524 auto_minor_version_upgrade = true 525 }`, rName, rName, rName) 526 } 527 528 func testAccAWSElasticacheReplicationGroupConfigUpdatedMaintenanceWindow(rName string) string { 529 return fmt.Sprintf(` 530 provider "aws" { 531 region = "us-east-1" 532 } 533 resource "aws_security_group" "bar" { 534 name = "tf-test-security-group-%s" 535 description = "tf-test-security-group-descr" 536 ingress { 537 from_port = -1 538 to_port = -1 539 protocol = "icmp" 540 cidr_blocks = ["0.0.0.0/0"] 541 } 542 } 543 544 resource "aws_elasticache_security_group" "bar" { 545 name = "tf-test-security-group-%s" 546 description = "tf-test-security-group-descr" 547 security_group_names = ["${aws_security_group.bar.name}"] 548 } 549 550 resource "aws_elasticache_replication_group" "bar" { 551 replication_group_id = "tf-%s" 552 replication_group_description = "updated description" 553 node_type = "cache.m1.small" 554 number_cache_clusters = 2 555 port = 6379 556 parameter_group_name = "default.redis3.2" 557 security_group_names = ["${aws_elasticache_security_group.bar.name}"] 558 apply_immediately = true 559 auto_minor_version_upgrade = true 560 maintenance_window = "wed:03:00-wed:06:00" 561 snapshot_window = "01:00-02:00" 562 }`, rName, rName, rName) 563 } 564 565 func testAccAWSElasticacheReplicationGroupConfigUpdatedNodeSize(rName string) string { 566 return fmt.Sprintf(` 567 provider "aws" { 568 region = "us-east-1" 569 } 570 resource "aws_security_group" "bar" { 571 name = "tf-test-security-group-%s" 572 description = "tf-test-security-group-descr" 573 ingress { 574 from_port = -1 575 to_port = -1 576 protocol = "icmp" 577 cidr_blocks = ["0.0.0.0/0"] 578 } 579 } 580 581 resource "aws_elasticache_security_group" "bar" { 582 name = "tf-test-security-group-%s" 583 description = "tf-test-security-group-descr" 584 security_group_names = ["${aws_security_group.bar.name}"] 585 } 586 587 resource "aws_elasticache_replication_group" "bar" { 588 replication_group_id = "tf-%s" 589 replication_group_description = "updated description" 590 node_type = "cache.m1.medium" 591 number_cache_clusters = 2 592 port = 6379 593 parameter_group_name = "default.redis3.2" 594 security_group_names = ["${aws_elasticache_security_group.bar.name}"] 595 apply_immediately = true 596 }`, rName, rName, rName) 597 } 598 599 var testAccAWSElasticacheReplicationGroupInVPCConfig = 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" 613 } 614 } 615 616 resource "aws_elasticache_subnet_group" "bar" { 617 name = "tf-test-cache-subnet-%03d" 618 description = "tf-test-cache-subnet-group-descr" 619 subnet_ids = ["${aws_subnet.foo.id}"] 620 } 621 622 resource "aws_security_group" "bar" { 623 name = "tf-test-security-group-%03d" 624 description = "tf-test-security-group-descr" 625 vpc_id = "${aws_vpc.foo.id}" 626 ingress { 627 from_port = -1 628 to_port = -1 629 protocol = "icmp" 630 cidr_blocks = ["0.0.0.0/0"] 631 } 632 } 633 634 resource "aws_elasticache_replication_group" "bar" { 635 replication_group_id = "tf-%s" 636 replication_group_description = "test description" 637 node_type = "cache.m1.small" 638 number_cache_clusters = 1 639 port = 6379 640 subnet_group_name = "${aws_elasticache_subnet_group.bar.name}" 641 security_group_ids = ["${aws_security_group.bar.id}"] 642 parameter_group_name = "default.redis3.2" 643 availability_zones = ["us-west-2a"] 644 auto_minor_version_upgrade = false 645 } 646 647 `, acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) 648 649 var testAccAWSElasticacheReplicationGroupMultiAZInVPCConfig = fmt.Sprintf(` 650 resource "aws_vpc" "foo" { 651 cidr_block = "192.168.0.0/16" 652 tags { 653 Name = "tf-test" 654 } 655 } 656 657 resource "aws_subnet" "foo" { 658 vpc_id = "${aws_vpc.foo.id}" 659 cidr_block = "192.168.0.0/20" 660 availability_zone = "us-west-2a" 661 tags { 662 Name = "tf-test-%03d" 663 } 664 } 665 666 resource "aws_subnet" "bar" { 667 vpc_id = "${aws_vpc.foo.id}" 668 cidr_block = "192.168.16.0/20" 669 availability_zone = "us-west-2b" 670 tags { 671 Name = "tf-test-%03d" 672 } 673 } 674 675 resource "aws_elasticache_subnet_group" "bar" { 676 name = "tf-test-cache-subnet-%03d" 677 description = "tf-test-cache-subnet-group-descr" 678 subnet_ids = [ 679 "${aws_subnet.foo.id}", 680 "${aws_subnet.bar.id}" 681 ] 682 } 683 684 resource "aws_security_group" "bar" { 685 name = "tf-test-security-group-%03d" 686 description = "tf-test-security-group-descr" 687 vpc_id = "${aws_vpc.foo.id}" 688 ingress { 689 from_port = -1 690 to_port = -1 691 protocol = "icmp" 692 cidr_blocks = ["0.0.0.0/0"] 693 } 694 } 695 696 resource "aws_elasticache_replication_group" "bar" { 697 replication_group_id = "tf-%s" 698 replication_group_description = "test description" 699 node_type = "cache.m1.small" 700 number_cache_clusters = 2 701 port = 6379 702 subnet_group_name = "${aws_elasticache_subnet_group.bar.name}" 703 security_group_ids = ["${aws_security_group.bar.id}"] 704 parameter_group_name = "default.redis3.2" 705 availability_zones = ["us-west-2a","us-west-2b"] 706 automatic_failover_enabled = true 707 snapshot_window = "02:00-03:00" 708 snapshot_retention_limit = 7 709 } 710 `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) 711 712 var testAccAWSElasticacheReplicationGroupRedisClusterInVPCConfig = fmt.Sprintf(` 713 resource "aws_vpc" "foo" { 714 cidr_block = "192.168.0.0/16" 715 tags { 716 Name = "tf-test" 717 } 718 } 719 720 resource "aws_subnet" "foo" { 721 vpc_id = "${aws_vpc.foo.id}" 722 cidr_block = "192.168.0.0/20" 723 availability_zone = "us-west-2a" 724 tags { 725 Name = "tf-test-%03d" 726 } 727 } 728 729 resource "aws_subnet" "bar" { 730 vpc_id = "${aws_vpc.foo.id}" 731 cidr_block = "192.168.16.0/20" 732 availability_zone = "us-west-2b" 733 tags { 734 Name = "tf-test-%03d" 735 } 736 } 737 738 resource "aws_elasticache_subnet_group" "bar" { 739 name = "tf-test-cache-subnet-%03d" 740 description = "tf-test-cache-subnet-group-descr" 741 subnet_ids = [ 742 "${aws_subnet.foo.id}", 743 "${aws_subnet.bar.id}" 744 ] 745 } 746 747 resource "aws_security_group" "bar" { 748 name = "tf-test-security-group-%03d" 749 description = "tf-test-security-group-descr" 750 vpc_id = "${aws_vpc.foo.id}" 751 ingress { 752 from_port = -1 753 to_port = -1 754 protocol = "icmp" 755 cidr_blocks = ["0.0.0.0/0"] 756 } 757 } 758 759 resource "aws_elasticache_replication_group" "bar" { 760 replication_group_id = "tf-%s" 761 replication_group_description = "test description" 762 node_type = "cache.t2.micro" 763 number_cache_clusters = "2" 764 port = 6379 765 subnet_group_name = "${aws_elasticache_subnet_group.bar.name}" 766 security_group_ids = ["${aws_security_group.bar.id}"] 767 parameter_group_name = "default.redis3.2.cluster.on" 768 availability_zones = ["us-west-2a","us-west-2b"] 769 automatic_failover_enabled = true 770 snapshot_window = "02:00-03:00" 771 snapshot_retention_limit = 7 772 engine_version = "3.2.4" 773 maintenance_window = "thu:03:00-thu:04:00" 774 } 775 `, acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandInt(), acctest.RandString(10)) 776 777 func testAccAWSElasticacheReplicationGroupNativeRedisClusterErrorConfig(rInt int, rName string) string { 778 return fmt.Sprintf(` 779 resource "aws_vpc" "foo" { 780 cidr_block = "192.168.0.0/16" 781 tags { 782 Name = "tf-test" 783 } 784 } 785 786 resource "aws_subnet" "foo" { 787 vpc_id = "${aws_vpc.foo.id}" 788 cidr_block = "192.168.0.0/20" 789 availability_zone = "us-west-2a" 790 tags { 791 Name = "tf-test-%03d" 792 } 793 } 794 795 resource "aws_subnet" "bar" { 796 vpc_id = "${aws_vpc.foo.id}" 797 cidr_block = "192.168.16.0/20" 798 availability_zone = "us-west-2b" 799 tags { 800 Name = "tf-test-%03d" 801 } 802 } 803 804 resource "aws_elasticache_subnet_group" "bar" { 805 name = "tf-test-cache-subnet-%03d" 806 description = "tf-test-cache-subnet-group-descr" 807 subnet_ids = [ 808 "${aws_subnet.foo.id}", 809 "${aws_subnet.bar.id}" 810 ] 811 } 812 813 resource "aws_security_group" "bar" { 814 name = "tf-test-security-group-%03d" 815 description = "tf-test-security-group-descr" 816 vpc_id = "${aws_vpc.foo.id}" 817 ingress { 818 from_port = -1 819 to_port = -1 820 protocol = "icmp" 821 cidr_blocks = ["0.0.0.0/0"] 822 } 823 } 824 825 resource "aws_elasticache_replication_group" "bar" { 826 replication_group_id = "tf-%s" 827 replication_group_description = "test description" 828 node_type = "cache.t2.micro" 829 port = 6379 830 subnet_group_name = "${aws_elasticache_subnet_group.bar.name}" 831 security_group_ids = ["${aws_security_group.bar.id}"] 832 parameter_group_name = "default.redis3.2.cluster.on" 833 automatic_failover_enabled = true 834 cluster_mode { 835 replicas_per_node_group = 1 836 num_node_groups = 2 837 } 838 number_cache_clusters = 3 839 }`, rInt, rInt, rInt, rInt, rName) 840 } 841 842 func testAccAWSElasticacheReplicationGroupNativeRedisClusterConfig(rInt int, rName string) string { 843 return fmt.Sprintf(` 844 resource "aws_vpc" "foo" { 845 cidr_block = "192.168.0.0/16" 846 tags { 847 Name = "tf-test" 848 } 849 } 850 851 resource "aws_subnet" "foo" { 852 vpc_id = "${aws_vpc.foo.id}" 853 cidr_block = "192.168.0.0/20" 854 availability_zone = "us-west-2a" 855 tags { 856 Name = "tf-test-%03d" 857 } 858 } 859 860 resource "aws_subnet" "bar" { 861 vpc_id = "${aws_vpc.foo.id}" 862 cidr_block = "192.168.16.0/20" 863 availability_zone = "us-west-2b" 864 tags { 865 Name = "tf-test-%03d" 866 } 867 } 868 869 resource "aws_elasticache_subnet_group" "bar" { 870 name = "tf-test-cache-subnet-%03d" 871 description = "tf-test-cache-subnet-group-descr" 872 subnet_ids = [ 873 "${aws_subnet.foo.id}", 874 "${aws_subnet.bar.id}" 875 ] 876 } 877 878 resource "aws_security_group" "bar" { 879 name = "tf-test-security-group-%03d" 880 description = "tf-test-security-group-descr" 881 vpc_id = "${aws_vpc.foo.id}" 882 ingress { 883 from_port = -1 884 to_port = -1 885 protocol = "icmp" 886 cidr_blocks = ["0.0.0.0/0"] 887 } 888 } 889 890 resource "aws_elasticache_replication_group" "bar" { 891 replication_group_id = "tf-%s" 892 replication_group_description = "test description" 893 node_type = "cache.t2.micro" 894 port = 6379 895 subnet_group_name = "${aws_elasticache_subnet_group.bar.name}" 896 security_group_ids = ["${aws_security_group.bar.id}"] 897 parameter_group_name = "default.redis3.2.cluster.on" 898 automatic_failover_enabled = true 899 cluster_mode { 900 replicas_per_node_group = 1 901 num_node_groups = 2 902 } 903 }`, rInt, rInt, rInt, rInt, rName) 904 }