github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_elb_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "math/rand" 6 "reflect" 7 "regexp" 8 "sort" 9 "testing" 10 "time" 11 12 "github.com/aws/aws-sdk-go/aws" 13 "github.com/aws/aws-sdk-go/aws/awserr" 14 "github.com/aws/aws-sdk-go/service/elb" 15 "github.com/hashicorp/terraform/helper/acctest" 16 "github.com/hashicorp/terraform/helper/resource" 17 "github.com/hashicorp/terraform/terraform" 18 ) 19 20 func TestAccAWSELB_basic(t *testing.T) { 21 var conf elb.LoadBalancerDescription 22 23 resource.Test(t, resource.TestCase{ 24 PreCheck: func() { testAccPreCheck(t) }, 25 IDRefreshName: "aws_elb.bar", 26 Providers: testAccProviders, 27 CheckDestroy: testAccCheckAWSELBDestroy, 28 Steps: []resource.TestStep{ 29 resource.TestStep{ 30 Config: testAccAWSELBConfig, 31 Check: resource.ComposeTestCheckFunc( 32 testAccCheckAWSELBExists("aws_elb.bar", &conf), 33 testAccCheckAWSELBAttributes(&conf), 34 resource.TestCheckResourceAttr( 35 "aws_elb.bar", "availability_zones.#", "3"), 36 resource.TestCheckResourceAttr( 37 "aws_elb.bar", "availability_zones.2487133097", "us-west-2a"), 38 resource.TestCheckResourceAttr( 39 "aws_elb.bar", "availability_zones.221770259", "us-west-2b"), 40 resource.TestCheckResourceAttr( 41 "aws_elb.bar", "availability_zones.2050015877", "us-west-2c"), 42 resource.TestCheckResourceAttr( 43 "aws_elb.bar", "subnets.#", "3"), 44 // NOTE: Subnet IDs are different across AWS accounts and cannot be checked. 45 resource.TestCheckResourceAttr( 46 "aws_elb.bar", "listener.206423021.instance_port", "8000"), 47 resource.TestCheckResourceAttr( 48 "aws_elb.bar", "listener.206423021.instance_protocol", "http"), 49 resource.TestCheckResourceAttr( 50 "aws_elb.bar", "listener.206423021.lb_port", "80"), 51 resource.TestCheckResourceAttr( 52 "aws_elb.bar", "listener.206423021.lb_protocol", "http"), 53 resource.TestCheckResourceAttr( 54 "aws_elb.bar", "cross_zone_load_balancing", "true"), 55 ), 56 }, 57 }, 58 }) 59 } 60 61 func TestAccAWSELB_fullCharacterRange(t *testing.T) { 62 var conf elb.LoadBalancerDescription 63 64 lbName := fmt.Sprintf("Tf-%d", 65 rand.New(rand.NewSource(time.Now().UnixNano())).Int()) 66 67 resource.Test(t, resource.TestCase{ 68 PreCheck: func() { testAccPreCheck(t) }, 69 IDRefreshName: "aws_elb.foo", 70 Providers: testAccProviders, 71 CheckDestroy: testAccCheckAWSELBDestroy, 72 Steps: []resource.TestStep{ 73 resource.TestStep{ 74 Config: fmt.Sprintf(testAccAWSELBFullRangeOfCharacters, lbName), 75 Check: resource.ComposeTestCheckFunc( 76 testAccCheckAWSELBExists("aws_elb.foo", &conf), 77 resource.TestCheckResourceAttr( 78 "aws_elb.foo", "name", lbName), 79 ), 80 }, 81 }, 82 }) 83 } 84 85 func TestAccAWSELB_AccessLogs(t *testing.T) { 86 var conf elb.LoadBalancerDescription 87 88 resource.Test(t, resource.TestCase{ 89 PreCheck: func() { testAccPreCheck(t) }, 90 IDRefreshName: "aws_elb.foo", 91 Providers: testAccProviders, 92 CheckDestroy: testAccCheckAWSELBDestroy, 93 Steps: []resource.TestStep{ 94 resource.TestStep{ 95 Config: testAccAWSELBAccessLogs, 96 Check: resource.ComposeTestCheckFunc( 97 testAccCheckAWSELBExists("aws_elb.foo", &conf), 98 ), 99 }, 100 101 resource.TestStep{ 102 Config: testAccAWSELBAccessLogsOn, 103 Check: resource.ComposeTestCheckFunc( 104 testAccCheckAWSELBExists("aws_elb.foo", &conf), 105 resource.TestCheckResourceAttr( 106 "aws_elb.foo", "access_logs.#", "1"), 107 resource.TestCheckResourceAttr( 108 "aws_elb.foo", "access_logs.0.bucket", "terraform-access-logs-bucket"), 109 resource.TestCheckResourceAttr( 110 "aws_elb.foo", "access_logs.0.interval", "5"), 111 ), 112 }, 113 114 resource.TestStep{ 115 Config: testAccAWSELBAccessLogs, 116 Check: resource.ComposeTestCheckFunc( 117 testAccCheckAWSELBExists("aws_elb.foo", &conf), 118 resource.TestCheckResourceAttr( 119 "aws_elb.foo", "access_logs.#", "0"), 120 ), 121 }, 122 }, 123 }) 124 } 125 126 func TestAccAWSELB_generatedName(t *testing.T) { 127 var conf elb.LoadBalancerDescription 128 generatedNameRegexp := regexp.MustCompile("^tf-lb-") 129 130 resource.Test(t, resource.TestCase{ 131 PreCheck: func() { testAccPreCheck(t) }, 132 IDRefreshName: "aws_elb.foo", 133 Providers: testAccProviders, 134 CheckDestroy: testAccCheckAWSELBDestroy, 135 Steps: []resource.TestStep{ 136 resource.TestStep{ 137 Config: testAccAWSELBGeneratedName, 138 Check: resource.ComposeTestCheckFunc( 139 testAccCheckAWSELBExists("aws_elb.foo", &conf), 140 resource.TestMatchResourceAttr( 141 "aws_elb.foo", "name", generatedNameRegexp), 142 ), 143 }, 144 }, 145 }) 146 } 147 148 func TestAccAWSELB_availabilityZones(t *testing.T) { 149 var conf elb.LoadBalancerDescription 150 151 resource.Test(t, resource.TestCase{ 152 PreCheck: func() { testAccPreCheck(t) }, 153 IDRefreshName: "aws_elb.bar", 154 Providers: testAccProviders, 155 CheckDestroy: testAccCheckAWSELBDestroy, 156 Steps: []resource.TestStep{ 157 resource.TestStep{ 158 Config: testAccAWSELBConfig, 159 Check: resource.ComposeTestCheckFunc( 160 testAccCheckAWSELBExists("aws_elb.bar", &conf), 161 resource.TestCheckResourceAttr( 162 "aws_elb.bar", "availability_zones.#", "3"), 163 resource.TestCheckResourceAttr( 164 "aws_elb.bar", "availability_zones.2487133097", "us-west-2a"), 165 resource.TestCheckResourceAttr( 166 "aws_elb.bar", "availability_zones.221770259", "us-west-2b"), 167 resource.TestCheckResourceAttr( 168 "aws_elb.bar", "availability_zones.2050015877", "us-west-2c"), 169 ), 170 }, 171 172 resource.TestStep{ 173 Config: testAccAWSELBConfig_AvailabilityZonesUpdate, 174 Check: resource.ComposeTestCheckFunc( 175 testAccCheckAWSELBExists("aws_elb.bar", &conf), 176 resource.TestCheckResourceAttr( 177 "aws_elb.bar", "availability_zones.#", "2"), 178 resource.TestCheckResourceAttr( 179 "aws_elb.bar", "availability_zones.2487133097", "us-west-2a"), 180 resource.TestCheckResourceAttr( 181 "aws_elb.bar", "availability_zones.221770259", "us-west-2b"), 182 ), 183 }, 184 }, 185 }) 186 } 187 188 func TestAccAWSELB_tags(t *testing.T) { 189 var conf elb.LoadBalancerDescription 190 var td elb.TagDescription 191 192 resource.Test(t, resource.TestCase{ 193 PreCheck: func() { testAccPreCheck(t) }, 194 IDRefreshName: "aws_elb.bar", 195 Providers: testAccProviders, 196 CheckDestroy: testAccCheckAWSELBDestroy, 197 Steps: []resource.TestStep{ 198 resource.TestStep{ 199 Config: testAccAWSELBConfig, 200 Check: resource.ComposeTestCheckFunc( 201 testAccCheckAWSELBExists("aws_elb.bar", &conf), 202 testAccCheckAWSELBAttributes(&conf), 203 testAccLoadTags(&conf, &td), 204 testAccCheckELBTags(&td.Tags, "bar", "baz"), 205 ), 206 }, 207 208 resource.TestStep{ 209 Config: testAccAWSELBConfig_TagUpdate, 210 Check: resource.ComposeTestCheckFunc( 211 testAccCheckAWSELBExists("aws_elb.bar", &conf), 212 testAccCheckAWSELBAttributes(&conf), 213 testAccLoadTags(&conf, &td), 214 testAccCheckELBTags(&td.Tags, "foo", "bar"), 215 testAccCheckELBTags(&td.Tags, "new", "type"), 216 ), 217 }, 218 }, 219 }) 220 } 221 222 func TestAccAWSELB_iam_server_cert(t *testing.T) { 223 var conf elb.LoadBalancerDescription 224 // var td elb.TagDescription 225 testCheck := func(*terraform.State) error { 226 if len(conf.ListenerDescriptions) != 1 { 227 return fmt.Errorf( 228 "TestAccAWSELB_iam_server_cert expected 1 listener, got %d", 229 len(conf.ListenerDescriptions)) 230 } 231 return nil 232 } 233 resource.Test(t, resource.TestCase{ 234 PreCheck: func() { testAccPreCheck(t) }, 235 IDRefreshName: "aws_elb.bar", 236 Providers: testAccProviders, 237 CheckDestroy: testAccCheckAWSELBDestroy, 238 Steps: []resource.TestStep{ 239 resource.TestStep{ 240 Config: testAccELBIAMServerCertConfig( 241 fmt.Sprintf("tf-acctest-%s", acctest.RandString(10))), 242 Check: resource.ComposeTestCheckFunc( 243 testAccCheckAWSELBExists("aws_elb.bar", &conf), 244 testCheck, 245 ), 246 }, 247 }, 248 }) 249 } 250 251 func TestAccAWSELB_swap_subnets(t *testing.T) { 252 var conf elb.LoadBalancerDescription 253 254 resource.Test(t, resource.TestCase{ 255 PreCheck: func() { testAccPreCheck(t) }, 256 IDRefreshName: "aws_elb.ourapp", 257 Providers: testAccProviders, 258 CheckDestroy: testAccCheckAWSELBDestroy, 259 Steps: []resource.TestStep{ 260 resource.TestStep{ 261 Config: testAccAWSELBConfig_subnets, 262 Check: resource.ComposeTestCheckFunc( 263 testAccCheckAWSELBExists("aws_elb.ourapp", &conf), 264 resource.TestCheckResourceAttr( 265 "aws_elb.ourapp", "subnets.#", "2"), 266 ), 267 }, 268 269 resource.TestStep{ 270 Config: testAccAWSELBConfig_subnet_swap, 271 Check: resource.ComposeTestCheckFunc( 272 testAccCheckAWSELBExists("aws_elb.ourapp", &conf), 273 resource.TestCheckResourceAttr( 274 "aws_elb.ourapp", "subnets.#", "2"), 275 ), 276 }, 277 }, 278 }) 279 } 280 281 func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription) resource.TestCheckFunc { 282 return func(s *terraform.State) error { 283 conn := testAccProvider.Meta().(*AWSClient).elbconn 284 285 describe, err := conn.DescribeTags(&elb.DescribeTagsInput{ 286 LoadBalancerNames: []*string{conf.LoadBalancerName}, 287 }) 288 289 if err != nil { 290 return err 291 } 292 if len(describe.TagDescriptions) > 0 { 293 *td = *describe.TagDescriptions[0] 294 } 295 return nil 296 } 297 } 298 299 func TestAccAWSELB_InstanceAttaching(t *testing.T) { 300 var conf elb.LoadBalancerDescription 301 302 testCheckInstanceAttached := func(count int) resource.TestCheckFunc { 303 return func(*terraform.State) error { 304 if len(conf.Instances) != count { 305 return fmt.Errorf("instance count does not match") 306 } 307 return nil 308 } 309 } 310 311 resource.Test(t, resource.TestCase{ 312 PreCheck: func() { testAccPreCheck(t) }, 313 IDRefreshName: "aws_elb.bar", 314 Providers: testAccProviders, 315 CheckDestroy: testAccCheckAWSELBDestroy, 316 Steps: []resource.TestStep{ 317 resource.TestStep{ 318 Config: testAccAWSELBConfig, 319 Check: resource.ComposeTestCheckFunc( 320 testAccCheckAWSELBExists("aws_elb.bar", &conf), 321 testAccCheckAWSELBAttributes(&conf), 322 ), 323 }, 324 325 resource.TestStep{ 326 Config: testAccAWSELBConfigNewInstance, 327 Check: resource.ComposeTestCheckFunc( 328 testAccCheckAWSELBExists("aws_elb.bar", &conf), 329 testCheckInstanceAttached(1), 330 ), 331 }, 332 }, 333 }) 334 } 335 336 func TestAccAWSELBUpdate_Listener(t *testing.T) { 337 var conf elb.LoadBalancerDescription 338 339 resource.Test(t, resource.TestCase{ 340 PreCheck: func() { testAccPreCheck(t) }, 341 IDRefreshName: "aws_elb.bar", 342 Providers: testAccProviders, 343 CheckDestroy: testAccCheckAWSELBDestroy, 344 Steps: []resource.TestStep{ 345 resource.TestStep{ 346 Config: testAccAWSELBConfig, 347 Check: resource.ComposeTestCheckFunc( 348 testAccCheckAWSELBExists("aws_elb.bar", &conf), 349 testAccCheckAWSELBAttributes(&conf), 350 resource.TestCheckResourceAttr( 351 "aws_elb.bar", "listener.206423021.instance_port", "8000"), 352 ), 353 }, 354 355 resource.TestStep{ 356 Config: testAccAWSELBConfigListener_update, 357 Check: resource.ComposeTestCheckFunc( 358 testAccCheckAWSELBExists("aws_elb.bar", &conf), 359 resource.TestCheckResourceAttr( 360 "aws_elb.bar", "listener.3931999347.instance_port", "8080"), 361 ), 362 }, 363 }, 364 }) 365 } 366 367 func TestAccAWSELB_HealthCheck(t *testing.T) { 368 var conf elb.LoadBalancerDescription 369 370 resource.Test(t, resource.TestCase{ 371 PreCheck: func() { testAccPreCheck(t) }, 372 IDRefreshName: "aws_elb.bar", 373 Providers: testAccProviders, 374 CheckDestroy: testAccCheckAWSELBDestroy, 375 Steps: []resource.TestStep{ 376 resource.TestStep{ 377 Config: testAccAWSELBConfigHealthCheck, 378 Check: resource.ComposeTestCheckFunc( 379 testAccCheckAWSELBExists("aws_elb.bar", &conf), 380 testAccCheckAWSELBAttributesHealthCheck(&conf), 381 resource.TestCheckResourceAttr( 382 "aws_elb.bar", "health_check.0.healthy_threshold", "5"), 383 resource.TestCheckResourceAttr( 384 "aws_elb.bar", "health_check.0.unhealthy_threshold", "5"), 385 resource.TestCheckResourceAttr( 386 "aws_elb.bar", "health_check.0.target", "HTTP:8000/"), 387 resource.TestCheckResourceAttr( 388 "aws_elb.bar", "health_check.0.timeout", "30"), 389 resource.TestCheckResourceAttr( 390 "aws_elb.bar", "health_check.0.interval", "60"), 391 ), 392 }, 393 }, 394 }) 395 } 396 397 func TestAccAWSELBUpdate_HealthCheck(t *testing.T) { 398 resource.Test(t, resource.TestCase{ 399 PreCheck: func() { testAccPreCheck(t) }, 400 IDRefreshName: "aws_elb.bar", 401 Providers: testAccProviders, 402 CheckDestroy: testAccCheckAWSELBDestroy, 403 Steps: []resource.TestStep{ 404 resource.TestStep{ 405 Config: testAccAWSELBConfigHealthCheck, 406 Check: resource.ComposeTestCheckFunc( 407 resource.TestCheckResourceAttr( 408 "aws_elb.bar", "health_check.0.healthy_threshold", "5"), 409 ), 410 }, 411 resource.TestStep{ 412 Config: testAccAWSELBConfigHealthCheck_update, 413 Check: resource.ComposeTestCheckFunc( 414 resource.TestCheckResourceAttr( 415 "aws_elb.bar", "health_check.0.healthy_threshold", "10"), 416 ), 417 }, 418 }, 419 }) 420 } 421 422 func TestAccAWSELB_Timeout(t *testing.T) { 423 var conf elb.LoadBalancerDescription 424 425 resource.Test(t, resource.TestCase{ 426 PreCheck: func() { testAccPreCheck(t) }, 427 IDRefreshName: "aws_elb.bar", 428 Providers: testAccProviders, 429 CheckDestroy: testAccCheckAWSELBDestroy, 430 Steps: []resource.TestStep{ 431 resource.TestStep{ 432 Config: testAccAWSELBConfigIdleTimeout, 433 Check: resource.ComposeTestCheckFunc( 434 testAccCheckAWSELBExists("aws_elb.bar", &conf), 435 resource.TestCheckResourceAttr( 436 "aws_elb.bar", "idle_timeout", "200", 437 ), 438 ), 439 }, 440 }, 441 }) 442 } 443 444 func TestAccAWSELBUpdate_Timeout(t *testing.T) { 445 resource.Test(t, resource.TestCase{ 446 PreCheck: func() { testAccPreCheck(t) }, 447 IDRefreshName: "aws_elb.bar", 448 Providers: testAccProviders, 449 CheckDestroy: testAccCheckAWSELBDestroy, 450 Steps: []resource.TestStep{ 451 resource.TestStep{ 452 Config: testAccAWSELBConfigIdleTimeout, 453 Check: resource.ComposeTestCheckFunc( 454 resource.TestCheckResourceAttr( 455 "aws_elb.bar", "idle_timeout", "200", 456 ), 457 ), 458 }, 459 resource.TestStep{ 460 Config: testAccAWSELBConfigIdleTimeout_update, 461 Check: resource.ComposeTestCheckFunc( 462 resource.TestCheckResourceAttr( 463 "aws_elb.bar", "idle_timeout", "400", 464 ), 465 ), 466 }, 467 }, 468 }) 469 } 470 471 func TestAccAWSELB_ConnectionDraining(t *testing.T) { 472 resource.Test(t, resource.TestCase{ 473 PreCheck: func() { testAccPreCheck(t) }, 474 IDRefreshName: "aws_elb.bar", 475 Providers: testAccProviders, 476 CheckDestroy: testAccCheckAWSELBDestroy, 477 Steps: []resource.TestStep{ 478 resource.TestStep{ 479 Config: testAccAWSELBConfigConnectionDraining, 480 Check: resource.ComposeTestCheckFunc( 481 resource.TestCheckResourceAttr( 482 "aws_elb.bar", "connection_draining", "true", 483 ), 484 resource.TestCheckResourceAttr( 485 "aws_elb.bar", "connection_draining_timeout", "400", 486 ), 487 ), 488 }, 489 }, 490 }) 491 } 492 493 func TestAccAWSELBUpdate_ConnectionDraining(t *testing.T) { 494 resource.Test(t, resource.TestCase{ 495 PreCheck: func() { testAccPreCheck(t) }, 496 IDRefreshName: "aws_elb.bar", 497 Providers: testAccProviders, 498 CheckDestroy: testAccCheckAWSELBDestroy, 499 Steps: []resource.TestStep{ 500 resource.TestStep{ 501 Config: testAccAWSELBConfigConnectionDraining, 502 Check: resource.ComposeTestCheckFunc( 503 resource.TestCheckResourceAttr( 504 "aws_elb.bar", "connection_draining", "true", 505 ), 506 resource.TestCheckResourceAttr( 507 "aws_elb.bar", "connection_draining_timeout", "400", 508 ), 509 ), 510 }, 511 resource.TestStep{ 512 Config: testAccAWSELBConfigConnectionDraining_update_timeout, 513 Check: resource.ComposeTestCheckFunc( 514 resource.TestCheckResourceAttr( 515 "aws_elb.bar", "connection_draining", "true", 516 ), 517 resource.TestCheckResourceAttr( 518 "aws_elb.bar", "connection_draining_timeout", "600", 519 ), 520 ), 521 }, 522 resource.TestStep{ 523 Config: testAccAWSELBConfigConnectionDraining_update_disable, 524 Check: resource.ComposeTestCheckFunc( 525 resource.TestCheckResourceAttr( 526 "aws_elb.bar", "connection_draining", "false", 527 ), 528 ), 529 }, 530 }, 531 }) 532 } 533 534 func TestAccAWSELB_SecurityGroups(t *testing.T) { 535 resource.Test(t, resource.TestCase{ 536 PreCheck: func() { testAccPreCheck(t) }, 537 IDRefreshName: "aws_elb.bar", 538 Providers: testAccProviders, 539 CheckDestroy: testAccCheckAWSELBDestroy, 540 Steps: []resource.TestStep{ 541 resource.TestStep{ 542 Config: testAccAWSELBConfig, 543 Check: resource.ComposeTestCheckFunc( 544 // ELBs get a default security group 545 resource.TestCheckResourceAttr( 546 "aws_elb.bar", "security_groups.#", "1", 547 ), 548 ), 549 }, 550 resource.TestStep{ 551 Config: testAccAWSELBConfigSecurityGroups, 552 Check: resource.ComposeTestCheckFunc( 553 // Count should still be one as we swap in a custom security group 554 resource.TestCheckResourceAttr( 555 "aws_elb.bar", "security_groups.#", "1", 556 ), 557 ), 558 }, 559 }, 560 }) 561 } 562 563 // Unit test for listeners hash 564 func TestResourceAwsElbListenerHash(t *testing.T) { 565 cases := map[string]struct { 566 Left map[string]interface{} 567 Right map[string]interface{} 568 Match bool 569 }{ 570 "protocols are case insensitive": { 571 map[string]interface{}{ 572 "instance_port": 80, 573 "instance_protocol": "TCP", 574 "lb_port": 80, 575 "lb_protocol": "TCP", 576 }, 577 map[string]interface{}{ 578 "instance_port": 80, 579 "instance_protocol": "Tcp", 580 "lb_port": 80, 581 "lb_protocol": "tcP", 582 }, 583 true, 584 }, 585 } 586 587 for tn, tc := range cases { 588 leftHash := resourceAwsElbListenerHash(tc.Left) 589 rightHash := resourceAwsElbListenerHash(tc.Right) 590 if leftHash == rightHash != tc.Match { 591 t.Fatalf("%s: expected match: %t, but did not get it", tn, tc.Match) 592 } 593 } 594 } 595 596 func TestResourceAWSELB_validateElbNameCannotBeginWithHyphen(t *testing.T) { 597 var elbName = "-Testing123" 598 _, errors := validateElbName(elbName, "SampleKey") 599 600 if len(errors) != 1 { 601 t.Fatalf("Expected the ELB Name to trigger a validation error") 602 } 603 } 604 605 func TestResourceAWSELB_validateElbNameCannotBeLongerThen32Characters(t *testing.T) { 606 var elbName = "Testing123dddddddddddddddddddvvvv" 607 _, errors := validateElbName(elbName, "SampleKey") 608 609 if len(errors) != 1 { 610 t.Fatalf("Expected the ELB Name to trigger a validation error") 611 } 612 } 613 614 func TestResourceAWSELB_validateElbNameCannotHaveSpecialCharacters(t *testing.T) { 615 var elbName = "Testing123%%" 616 _, errors := validateElbName(elbName, "SampleKey") 617 618 if len(errors) != 1 { 619 t.Fatalf("Expected the ELB Name to trigger a validation error") 620 } 621 } 622 623 func TestResourceAWSELB_validateElbNameCannotEndWithHyphen(t *testing.T) { 624 var elbName = "Testing123-" 625 _, errors := validateElbName(elbName, "SampleKey") 626 627 if len(errors) != 1 { 628 t.Fatalf("Expected the ELB Name to trigger a validation error") 629 } 630 } 631 632 func TestResourceAWSELB_validateAccessLogsInterval(t *testing.T) { 633 type testCases struct { 634 Value int 635 ErrCount int 636 } 637 638 invalidCases := []testCases{ 639 { 640 Value: 0, 641 ErrCount: 1, 642 }, 643 { 644 Value: 10, 645 ErrCount: 1, 646 }, 647 { 648 Value: -1, 649 ErrCount: 1, 650 }, 651 } 652 653 for _, tc := range invalidCases { 654 _, errors := validateAccessLogsInterval(tc.Value, "interval") 655 if len(errors) != tc.ErrCount { 656 t.Fatalf("Expected %q to trigger a validation error.", tc.Value) 657 } 658 } 659 660 } 661 662 func TestResourceAWSELB_validateListenerProtocol(t *testing.T) { 663 type testCases struct { 664 Value string 665 ErrCount int 666 } 667 668 invalidCases := []testCases{ 669 { 670 Value: "", 671 ErrCount: 1, 672 }, 673 { 674 Value: "incorrect", 675 ErrCount: 1, 676 }, 677 { 678 Value: "HTTP:", 679 ErrCount: 1, 680 }, 681 } 682 683 for _, tc := range invalidCases { 684 _, errors := validateListenerProtocol(tc.Value, "protocol") 685 if len(errors) != tc.ErrCount { 686 t.Fatalf("Expected %q to trigger a validation error.", tc.Value) 687 } 688 } 689 690 validCases := []testCases{ 691 { 692 Value: "TCP", 693 ErrCount: 0, 694 }, 695 { 696 Value: "ssl", 697 ErrCount: 0, 698 }, 699 { 700 Value: "HTTP", 701 ErrCount: 0, 702 }, 703 } 704 705 for _, tc := range validCases { 706 _, errors := validateListenerProtocol(tc.Value, "protocol") 707 if len(errors) != tc.ErrCount { 708 t.Fatalf("Expected %q not to trigger a validation error.", tc.Value) 709 } 710 } 711 } 712 713 func TestResourceAWSELB_validateHealthCheckTarget(t *testing.T) { 714 type testCase struct { 715 Value string 716 ErrCount int 717 } 718 719 randomRunes := func(n int) string { 720 rand.Seed(time.Now().UTC().UnixNano()) 721 722 // A complete set of modern Katakana characters. 723 runes := []rune("アイウエオ" + 724 "カキクケコガギグゲゴサシスセソザジズゼゾ" + 725 "タチツテトダヂヅデドナニヌネノハヒフヘホ" + 726 "バビブベボパピプペポマミムメモヤユヨラリ" + 727 "ルレロワヰヱヲン") 728 729 s := make([]rune, n) 730 for i := range s { 731 s[i] = runes[rand.Intn(len(runes))] 732 } 733 return string(s) 734 } 735 736 validCases := []testCase{ 737 { 738 Value: "TCP:1234", 739 ErrCount: 0, 740 }, 741 { 742 Value: "http:80/test", 743 ErrCount: 0, 744 }, 745 { 746 Value: fmt.Sprintf("HTTP:8080/%s", randomRunes(5)), 747 ErrCount: 0, 748 }, 749 { 750 Value: "SSL:8080", 751 ErrCount: 0, 752 }, 753 } 754 755 for _, tc := range validCases { 756 _, errors := validateHeathCheckTarget(tc.Value, "target") 757 if len(errors) != tc.ErrCount { 758 t.Fatalf("Expected %q not to trigger a validation error.", tc.Value) 759 } 760 } 761 762 invalidCases := []testCase{ 763 { 764 Value: "", 765 ErrCount: 1, 766 }, 767 { 768 Value: "TCP:", 769 ErrCount: 1, 770 }, 771 { 772 Value: "TCP:1234/", 773 ErrCount: 1, 774 }, 775 { 776 Value: "SSL:8080/", 777 ErrCount: 1, 778 }, 779 { 780 Value: "HTTP:8080", 781 ErrCount: 1, 782 }, 783 { 784 Value: "incorrect-value", 785 ErrCount: 1, 786 }, 787 { 788 Value: "TCP:123456", 789 ErrCount: 1, 790 }, 791 { 792 Value: "incorrect:80/", 793 ErrCount: 1, 794 }, 795 { 796 Value: fmt.Sprintf("HTTP:8080/%s%s", randomString(512), randomRunes(512)), 797 ErrCount: 1, 798 }, 799 } 800 801 for _, tc := range invalidCases { 802 _, errors := validateHeathCheckTarget(tc.Value, "target") 803 if len(errors) != tc.ErrCount { 804 t.Fatalf("Expected %q to trigger a validation error.", tc.Value) 805 } 806 } 807 } 808 809 func testAccCheckAWSELBDestroy(s *terraform.State) error { 810 conn := testAccProvider.Meta().(*AWSClient).elbconn 811 812 for _, rs := range s.RootModule().Resources { 813 if rs.Type != "aws_elb" { 814 continue 815 } 816 817 describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{ 818 LoadBalancerNames: []*string{aws.String(rs.Primary.ID)}, 819 }) 820 821 if err == nil { 822 if len(describe.LoadBalancerDescriptions) != 0 && 823 *describe.LoadBalancerDescriptions[0].LoadBalancerName == rs.Primary.ID { 824 return fmt.Errorf("ELB still exists") 825 } 826 } 827 828 // Verify the error 829 providerErr, ok := err.(awserr.Error) 830 if !ok { 831 return err 832 } 833 834 if providerErr.Code() != "LoadBalancerNotFound" { 835 return fmt.Errorf("Unexpected error: %s", err) 836 } 837 } 838 839 return nil 840 } 841 842 func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { 843 return func(s *terraform.State) error { 844 zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"} 845 azs := make([]string, 0, len(conf.AvailabilityZones)) 846 for _, x := range conf.AvailabilityZones { 847 azs = append(azs, *x) 848 } 849 sort.StringSlice(azs).Sort() 850 if !reflect.DeepEqual(azs, zones) { 851 return fmt.Errorf("bad availability_zones") 852 } 853 854 l := elb.Listener{ 855 InstancePort: aws.Int64(int64(8000)), 856 InstanceProtocol: aws.String("HTTP"), 857 LoadBalancerPort: aws.Int64(int64(80)), 858 Protocol: aws.String("HTTP"), 859 } 860 861 if !reflect.DeepEqual(conf.ListenerDescriptions[0].Listener, &l) { 862 return fmt.Errorf( 863 "Got:\n\n%#v\n\nExpected:\n\n%#v\n", 864 conf.ListenerDescriptions[0].Listener, 865 l) 866 } 867 868 if *conf.DNSName == "" { 869 return fmt.Errorf("empty dns_name") 870 } 871 872 return nil 873 } 874 } 875 876 func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc { 877 return func(s *terraform.State) error { 878 zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"} 879 azs := make([]string, 0, len(conf.AvailabilityZones)) 880 for _, x := range conf.AvailabilityZones { 881 azs = append(azs, *x) 882 } 883 sort.StringSlice(azs).Sort() 884 if !reflect.DeepEqual(azs, zones) { 885 return fmt.Errorf("bad availability_zones") 886 } 887 888 check := &elb.HealthCheck{ 889 Timeout: aws.Int64(int64(30)), 890 UnhealthyThreshold: aws.Int64(int64(5)), 891 HealthyThreshold: aws.Int64(int64(5)), 892 Interval: aws.Int64(int64(60)), 893 Target: aws.String("HTTP:8000/"), 894 } 895 896 if !reflect.DeepEqual(conf.HealthCheck, check) { 897 return fmt.Errorf( 898 "Got:\n\n%#v\n\nExpected:\n\n%#v\n", 899 conf.HealthCheck, 900 check) 901 } 902 903 if *conf.DNSName == "" { 904 return fmt.Errorf("empty dns_name") 905 } 906 907 return nil 908 } 909 } 910 911 func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resource.TestCheckFunc { 912 return func(s *terraform.State) error { 913 rs, ok := s.RootModule().Resources[n] 914 if !ok { 915 return fmt.Errorf("Not found: %s", n) 916 } 917 918 if rs.Primary.ID == "" { 919 return fmt.Errorf("No ELB ID is set") 920 } 921 922 conn := testAccProvider.Meta().(*AWSClient).elbconn 923 924 describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{ 925 LoadBalancerNames: []*string{aws.String(rs.Primary.ID)}, 926 }) 927 928 if err != nil { 929 return err 930 } 931 932 if len(describe.LoadBalancerDescriptions) != 1 || 933 *describe.LoadBalancerDescriptions[0].LoadBalancerName != rs.Primary.ID { 934 return fmt.Errorf("ELB not found") 935 } 936 937 *res = *describe.LoadBalancerDescriptions[0] 938 939 // Confirm source_security_group_id for ELBs in a VPC 940 // See https://github.com/hashicorp/terraform/pull/3780 941 if res.VPCId != nil { 942 sgid := rs.Primary.Attributes["source_security_group_id"] 943 if sgid == "" { 944 return fmt.Errorf("Expected to find source_security_group_id for ELB, but was empty") 945 } 946 } 947 948 return nil 949 } 950 } 951 952 const testAccAWSELBConfig = ` 953 resource "aws_elb" "bar" { 954 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 955 956 listener { 957 instance_port = 8000 958 instance_protocol = "http" 959 lb_port = 80 960 // Protocol should be case insensitive 961 lb_protocol = "HttP" 962 } 963 964 tags { 965 bar = "baz" 966 } 967 968 cross_zone_load_balancing = true 969 } 970 ` 971 972 const testAccAWSELBFullRangeOfCharacters = ` 973 resource "aws_elb" "foo" { 974 name = "%s" 975 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 976 977 listener { 978 instance_port = 8000 979 instance_protocol = "http" 980 lb_port = 80 981 lb_protocol = "http" 982 } 983 } 984 ` 985 986 const testAccAWSELBAccessLogs = ` 987 resource "aws_elb" "foo" { 988 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 989 990 listener { 991 instance_port = 8000 992 instance_protocol = "http" 993 lb_port = 80 994 lb_protocol = "http" 995 } 996 } 997 ` 998 const testAccAWSELBAccessLogsOn = ` 999 # an S3 bucket configured for Access logs 1000 # The 797873946194 is the AWS ID for us-west-2, so this test 1001 # must be ran in us-west-2 1002 resource "aws_s3_bucket" "acceslogs_bucket" { 1003 bucket = "terraform-access-logs-bucket" 1004 acl = "private" 1005 force_destroy = true 1006 policy = <<EOF 1007 { 1008 "Id": "Policy1446577137248", 1009 "Statement": [ 1010 { 1011 "Action": "s3:PutObject", 1012 "Effect": "Allow", 1013 "Principal": { 1014 "AWS": "arn:aws:iam::797873946194:root" 1015 }, 1016 "Resource": "arn:aws:s3:::terraform-access-logs-bucket/*", 1017 "Sid": "Stmt1446575236270" 1018 } 1019 ], 1020 "Version": "2012-10-17" 1021 } 1022 EOF 1023 } 1024 1025 resource "aws_elb" "foo" { 1026 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1027 1028 listener { 1029 instance_port = 8000 1030 instance_protocol = "http" 1031 lb_port = 80 1032 lb_protocol = "http" 1033 } 1034 1035 access_logs { 1036 interval = 5 1037 bucket = "${aws_s3_bucket.acceslogs_bucket.bucket}" 1038 } 1039 } 1040 ` 1041 1042 const testAccAWSELBGeneratedName = ` 1043 resource "aws_elb" "foo" { 1044 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1045 1046 listener { 1047 instance_port = 8000 1048 instance_protocol = "http" 1049 lb_port = 80 1050 lb_protocol = "http" 1051 } 1052 } 1053 ` 1054 1055 const testAccAWSELBConfig_AvailabilityZonesUpdate = ` 1056 resource "aws_elb" "bar" { 1057 availability_zones = ["us-west-2a", "us-west-2b"] 1058 1059 listener { 1060 instance_port = 8000 1061 instance_protocol = "http" 1062 lb_port = 80 1063 lb_protocol = "http" 1064 } 1065 } 1066 ` 1067 1068 const testAccAWSELBConfig_TagUpdate = ` 1069 resource "aws_elb" "bar" { 1070 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1071 1072 listener { 1073 instance_port = 8000 1074 instance_protocol = "http" 1075 lb_port = 80 1076 lb_protocol = "http" 1077 } 1078 1079 tags { 1080 foo = "bar" 1081 new = "type" 1082 } 1083 1084 cross_zone_load_balancing = true 1085 } 1086 ` 1087 1088 const testAccAWSELBConfigNewInstance = ` 1089 resource "aws_elb" "bar" { 1090 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1091 1092 listener { 1093 instance_port = 8000 1094 instance_protocol = "http" 1095 lb_port = 80 1096 lb_protocol = "http" 1097 } 1098 1099 instances = ["${aws_instance.foo.id}"] 1100 } 1101 1102 resource "aws_instance" "foo" { 1103 # us-west-2 1104 ami = "ami-043a5034" 1105 instance_type = "t1.micro" 1106 } 1107 ` 1108 1109 const testAccAWSELBConfigListenerSSLCertificateId = ` 1110 resource "aws_elb" "bar" { 1111 availability_zones = ["us-west-2a"] 1112 1113 listener { 1114 instance_port = 8000 1115 instance_protocol = "http" 1116 ssl_certificate_id = "%s" 1117 lb_port = 443 1118 lb_protocol = "https" 1119 } 1120 } 1121 ` 1122 1123 const testAccAWSELBConfigHealthCheck = ` 1124 resource "aws_elb" "bar" { 1125 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1126 1127 listener { 1128 instance_port = 8000 1129 instance_protocol = "http" 1130 lb_port = 80 1131 lb_protocol = "http" 1132 } 1133 1134 health_check { 1135 healthy_threshold = 5 1136 unhealthy_threshold = 5 1137 target = "HTTP:8000/" 1138 interval = 60 1139 timeout = 30 1140 } 1141 } 1142 ` 1143 1144 const testAccAWSELBConfigHealthCheck_update = ` 1145 resource "aws_elb" "bar" { 1146 availability_zones = ["us-west-2a"] 1147 1148 listener { 1149 instance_port = 8000 1150 instance_protocol = "http" 1151 lb_port = 80 1152 lb_protocol = "http" 1153 } 1154 1155 health_check { 1156 healthy_threshold = 10 1157 unhealthy_threshold = 5 1158 target = "HTTP:8000/" 1159 interval = 60 1160 timeout = 30 1161 } 1162 } 1163 ` 1164 1165 const testAccAWSELBConfigListener_update = ` 1166 resource "aws_elb" "bar" { 1167 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1168 1169 listener { 1170 instance_port = 8080 1171 instance_protocol = "http" 1172 lb_port = 80 1173 lb_protocol = "http" 1174 } 1175 } 1176 ` 1177 1178 const testAccAWSELBConfigIdleTimeout = ` 1179 resource "aws_elb" "bar" { 1180 availability_zones = ["us-west-2a"] 1181 1182 listener { 1183 instance_port = 8000 1184 instance_protocol = "http" 1185 lb_port = 80 1186 lb_protocol = "http" 1187 } 1188 1189 idle_timeout = 200 1190 } 1191 ` 1192 1193 const testAccAWSELBConfigIdleTimeout_update = ` 1194 resource "aws_elb" "bar" { 1195 availability_zones = ["us-west-2a"] 1196 1197 listener { 1198 instance_port = 8000 1199 instance_protocol = "http" 1200 lb_port = 80 1201 lb_protocol = "http" 1202 } 1203 1204 idle_timeout = 400 1205 } 1206 ` 1207 1208 const testAccAWSELBConfigConnectionDraining = ` 1209 resource "aws_elb" "bar" { 1210 availability_zones = ["us-west-2a"] 1211 1212 listener { 1213 instance_port = 8000 1214 instance_protocol = "http" 1215 lb_port = 80 1216 lb_protocol = "http" 1217 } 1218 1219 connection_draining = true 1220 connection_draining_timeout = 400 1221 } 1222 ` 1223 1224 const testAccAWSELBConfigConnectionDraining_update_timeout = ` 1225 resource "aws_elb" "bar" { 1226 availability_zones = ["us-west-2a"] 1227 1228 listener { 1229 instance_port = 8000 1230 instance_protocol = "http" 1231 lb_port = 80 1232 lb_protocol = "http" 1233 } 1234 1235 connection_draining = true 1236 connection_draining_timeout = 600 1237 } 1238 ` 1239 1240 const testAccAWSELBConfigConnectionDraining_update_disable = ` 1241 resource "aws_elb" "bar" { 1242 availability_zones = ["us-west-2a"] 1243 1244 listener { 1245 instance_port = 8000 1246 instance_protocol = "http" 1247 lb_port = 80 1248 lb_protocol = "http" 1249 } 1250 1251 connection_draining = false 1252 } 1253 ` 1254 1255 const testAccAWSELBConfigSecurityGroups = ` 1256 resource "aws_elb" "bar" { 1257 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1258 1259 listener { 1260 instance_port = 8000 1261 instance_protocol = "http" 1262 lb_port = 80 1263 lb_protocol = "http" 1264 } 1265 1266 security_groups = ["${aws_security_group.bar.id}"] 1267 } 1268 1269 resource "aws_security_group" "bar" { 1270 ingress { 1271 protocol = "tcp" 1272 from_port = 80 1273 to_port = 80 1274 cidr_blocks = ["0.0.0.0/0"] 1275 } 1276 1277 tags { 1278 Name = "tf_elb_sg_test" 1279 } 1280 } 1281 ` 1282 1283 // This IAM Server config is lifted from 1284 // builtin/providers/aws/resource_aws_iam_server_certificate_test.go 1285 func testAccELBIAMServerCertConfig(certName string) string { 1286 return fmt.Sprintf(` 1287 resource "aws_iam_server_certificate" "test_cert" { 1288 name = "%s" 1289 certificate_body = <<EOF 1290 -----BEGIN CERTIFICATE----- 1291 MIIDBjCCAe4CCQCGWwBmOiHQdTANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJB 1292 VTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0 1293 cyBQdHkgTHRkMB4XDTE2MDYyMTE2MzM0MVoXDTE3MDYyMTE2MzM0MVowRTELMAkG 1294 A1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0 1295 IFdpZGdpdHMgUHR5IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB 1296 AL+LFlsCJG5txZp4yuu+lQnuUrgBXRG+irQqcTXlV91Bp5hpmRIyhnGCtWxxDBUL 1297 xrh4WN3VV/0jDzKT976oLgOy3hj56Cdqf+JlZ1qgMN5bHB3mm3aVWnrnsLbBsfwZ 1298 SEbk3Kht/cE1nK2toNVW+rznS3m+eoV3Zn/DUNwGlZr42hGNs6ETn2jURY78ETqR 1299 mW47xvjf86eIo7vULHJaY6xyarPqkL8DZazOmvY06hUGvGwGBny7gugfXqDG+I8n 1300 cPBsGJGSAmHmVV8o0RCB9UjY+TvSMQRpEDoVlvyrGuglsD8to/4+7UcsuDGlRYN6 1301 jmIOC37mOi/jwRfWL1YUa4MCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAPDxTH0oQ 1302 JjKXoJgkmQxurB81RfnK/NrswJVzWbOv6ejcbhwh+/ZgJTMc15BrYcxU6vUW1V/i 1303 Z7APU0qJ0icECACML+a2fRI7YdLCTiPIOmY66HY8MZHAn3dGjU5TeiUflC0n0zkP 1304 mxKJe43kcYLNDItbfvUDo/GoxTXrC3EFVZyU0RhFzoVJdODlTHXMVFCzcbQEBrBJ 1305 xKdShCEc8nFMneZcGFeEU488ntZoWzzms8/QpYrKa5S0Sd7umEU2Kwu4HTkvUFg/ 1306 CqDUFjhydXxYRsxXBBrEiLOE5BdtJR1sH/QHxIJe23C9iHI2nS1NbLziNEApLwC4 1307 GnSud83VUo9G9w== 1308 -----END CERTIFICATE----- 1309 EOF 1310 1311 private_key = <<EOF 1312 -----BEGIN RSA PRIVATE KEY----- 1313 MIIEowIBAAKCAQEAv4sWWwIkbm3FmnjK676VCe5SuAFdEb6KtCpxNeVX3UGnmGmZ 1314 EjKGcYK1bHEMFQvGuHhY3dVX/SMPMpP3vqguA7LeGPnoJ2p/4mVnWqAw3lscHeab 1315 dpVaeuewtsGx/BlIRuTcqG39wTWcra2g1Vb6vOdLeb56hXdmf8NQ3AaVmvjaEY2z 1316 oROfaNRFjvwROpGZbjvG+N/zp4iju9QsclpjrHJqs+qQvwNlrM6a9jTqFQa8bAYG 1317 fLuC6B9eoMb4jydw8GwYkZICYeZVXyjREIH1SNj5O9IxBGkQOhWW/Ksa6CWwPy2j 1318 /j7tRyy4MaVFg3qOYg4LfuY6L+PBF9YvVhRrgwIDAQABAoIBAFqJ4h1Om+3e0WK8 1319 6h4YzdYN4ue7LUTv7hxPW4gASlH5cMDoWURywX3yLNN/dBiWom4b5NWmvJqY8dwU 1320 eSyTznxNFhJ0PjozaxOWnw4FXlQceOPhV2bsHgKudadNU1Y4lSN9lpe+tg2Xy+GE 1321 ituM66RTKCf502w3DioiJpx6OEkxuhrnsQAWNcGB0MnTukm2f+629V+04R5MT5V1 1322 nY+5Phx2BpHgYzWBKh6Px1puu7xFv5SMQda1ndlPIKb4cNp0yYn+1lHNjbOE7QL/ 1323 oEpWgrauS5Zk/APK33v/p3wVYHrKocIFHlPiCW0uIJJLsOZDY8pQXpTlc+/xGLLy 1324 WBu4boECgYEA6xO+1UNh6ndJ3xGuNippH+ucTi/uq1+0tG1bd63v+75tn5l4LyY2 1325 CWHRaWVlVn+WnDslkQTJzFD68X+9M7Cc4oP6WnhTyPamG7HlGv5JxfFHTC9GOKmz 1326 sSc624BDmqYJ7Xzyhe5kc3iHzqG/L72ZF1aijZdrodQMSY1634UX6aECgYEA0Jdr 1327 cBPSN+mgmEY6ogN5h7sO5uNV3TQQtW2IslfWZn6JhSRF4Rf7IReng48CMy9ZhFBy 1328 Q7H2I1pDGjEC9gQHhgVfm+FyMSVqXfCHEW/97pvvu9ougHA0MhPep1twzTGrqg+K 1329 f3PLW8hVkGyCrTfWgbDlPsHgsocA/wTaQOheaqMCgYBat5z+WemQfQZh8kXDm2xE 1330 KD2Cota9BcsLkeQpdFNXWC6f167cqydRSZFx1fJchhJOKjkeFLX3hgzBY6VVLEPu 1331 2jWj8imLNTv3Fhiu6RD5NVppWRkFRuAUbmo1SPNN2+Oa5YwGCXB0a0Alip/oQYex 1332 zPogIB4mLlmrjNCtL4SB4QKBgCEHKMrZSJrz0irqS9RlanPUaZqjenAJE3A2xMNA 1333 Z0FZXdsIEEyA6JGn1i1dkoKaR7lMp5sSbZ/RZfiatBZSMwLEjQv4mYUwoHP5Ztma 1334 +wEyDbaX6G8L1Sfsv3+OWgETkVPfHBXsNtH0mZ/BnrtgsQVeBh52wmZiPAUlNo26 1335 fWCzAoGBAJOjqovLelLWzyQGqPFx/MwuI56UFXd1CmFlCIvF2WxCFmk3tlExoCN1 1336 HqSpt92vsgYgV7+lAb4U7Uy/v012gwiU1LK+vyAE9geo3pTjG73BNzG4H547xtbY 1337 dg+Sd4Wjm89UQoUUoiIcstY7FPbqfBtYKfh4RYHAHV2BwDFqzZCM 1338 -----END RSA PRIVATE KEY----- 1339 EOF 1340 } 1341 1342 resource "aws_elb" "bar" { 1343 availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"] 1344 1345 listener { 1346 instance_port = 8000 1347 instance_protocol = "https" 1348 lb_port = 80 1349 // Protocol should be case insensitive 1350 lb_protocol = "HttPs" 1351 ssl_certificate_id = "${aws_iam_server_certificate.test_cert.arn}" 1352 } 1353 1354 tags { 1355 bar = "baz" 1356 } 1357 1358 cross_zone_load_balancing = true 1359 } 1360 `, certName) 1361 } 1362 1363 const testAccAWSELBConfig_subnets = ` 1364 provider "aws" { 1365 region = "us-west-2" 1366 } 1367 1368 resource "aws_vpc" "azelb" { 1369 cidr_block = "10.1.0.0/16" 1370 enable_dns_hostnames = true 1371 1372 tags { 1373 Name = "subnet-vpc" 1374 } 1375 } 1376 1377 resource "aws_subnet" "public_a_one" { 1378 vpc_id = "${aws_vpc.azelb.id}" 1379 1380 cidr_block = "10.1.1.0/24" 1381 availability_zone = "us-west-2a" 1382 } 1383 1384 resource "aws_subnet" "public_b_one" { 1385 vpc_id = "${aws_vpc.azelb.id}" 1386 1387 cidr_block = "10.1.7.0/24" 1388 availability_zone = "us-west-2b" 1389 } 1390 1391 resource "aws_subnet" "public_a_two" { 1392 vpc_id = "${aws_vpc.azelb.id}" 1393 1394 cidr_block = "10.1.2.0/24" 1395 availability_zone = "us-west-2a" 1396 } 1397 1398 resource "aws_elb" "ourapp" { 1399 name = "terraform-asg-deployment-example" 1400 1401 subnets = [ 1402 "${aws_subnet.public_a_one.id}", 1403 "${aws_subnet.public_b_one.id}", 1404 ] 1405 1406 listener { 1407 instance_port = 80 1408 instance_protocol = "http" 1409 lb_port = 80 1410 lb_protocol = "http" 1411 } 1412 1413 depends_on = ["aws_internet_gateway.gw"] 1414 } 1415 1416 resource "aws_internet_gateway" "gw" { 1417 vpc_id = "${aws_vpc.azelb.id}" 1418 1419 tags { 1420 Name = "main" 1421 } 1422 } 1423 ` 1424 1425 const testAccAWSELBConfig_subnet_swap = ` 1426 provider "aws" { 1427 region = "us-west-2" 1428 } 1429 1430 resource "aws_vpc" "azelb" { 1431 cidr_block = "10.1.0.0/16" 1432 enable_dns_hostnames = true 1433 1434 tags { 1435 Name = "subnet-vpc" 1436 } 1437 } 1438 1439 resource "aws_subnet" "public_a_one" { 1440 vpc_id = "${aws_vpc.azelb.id}" 1441 1442 cidr_block = "10.1.1.0/24" 1443 availability_zone = "us-west-2a" 1444 } 1445 1446 resource "aws_subnet" "public_b_one" { 1447 vpc_id = "${aws_vpc.azelb.id}" 1448 1449 cidr_block = "10.1.7.0/24" 1450 availability_zone = "us-west-2b" 1451 } 1452 1453 resource "aws_subnet" "public_a_two" { 1454 vpc_id = "${aws_vpc.azelb.id}" 1455 1456 cidr_block = "10.1.2.0/24" 1457 availability_zone = "us-west-2a" 1458 } 1459 1460 resource "aws_elb" "ourapp" { 1461 name = "terraform-asg-deployment-example" 1462 1463 subnets = [ 1464 "${aws_subnet.public_a_two.id}", 1465 "${aws_subnet.public_b_one.id}", 1466 ] 1467 1468 listener { 1469 instance_port = 80 1470 instance_protocol = "http" 1471 lb_port = 80 1472 lb_protocol = "http" 1473 } 1474 1475 depends_on = ["aws_internet_gateway.gw"] 1476 } 1477 1478 resource "aws_internet_gateway" "gw" { 1479 vpc_id = "${aws_vpc.azelb.id}" 1480 1481 tags { 1482 Name = "main" 1483 } 1484 } 1485 `