github.com/anuaimi/terraform@v0.6.4-0.20150904235404-2bf9aec61da8/builtin/providers/aws/resource_aws_elb_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"reflect"
     7  	"regexp"
     8  	"sort"
     9  	"testing"
    10  
    11  	"github.com/aws/aws-sdk-go/aws"
    12  	"github.com/aws/aws-sdk-go/aws/awserr"
    13  	"github.com/aws/aws-sdk-go/service/elb"
    14  	"github.com/hashicorp/terraform/helper/resource"
    15  	"github.com/hashicorp/terraform/terraform"
    16  )
    17  
    18  func TestAccAWSELB_basic(t *testing.T) {
    19  	var conf elb.LoadBalancerDescription
    20  	ssl_certificate_id := os.Getenv("AWS_SSL_CERTIFICATE_ID")
    21  
    22  	resource.Test(t, resource.TestCase{
    23  		PreCheck:     func() { testAccPreCheck(t) },
    24  		Providers:    testAccProviders,
    25  		CheckDestroy: testAccCheckAWSELBDestroy,
    26  		Steps: []resource.TestStep{
    27  			resource.TestStep{
    28  				Config: testAccAWSELBConfig,
    29  				Check: resource.ComposeTestCheckFunc(
    30  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
    31  					testAccCheckAWSELBAttributes(&conf),
    32  					resource.TestCheckResourceAttr(
    33  						"aws_elb.bar", "name", "foobar-terraform-test"),
    34  					resource.TestCheckResourceAttr(
    35  						"aws_elb.bar", "availability_zones.2487133097", "us-west-2a"),
    36  					resource.TestCheckResourceAttr(
    37  						"aws_elb.bar", "availability_zones.221770259", "us-west-2b"),
    38  					resource.TestCheckResourceAttr(
    39  						"aws_elb.bar", "availability_zones.2050015877", "us-west-2c"),
    40  					resource.TestCheckResourceAttr(
    41  						"aws_elb.bar", "listener.206423021.instance_port", "8000"),
    42  					resource.TestCheckResourceAttr(
    43  						"aws_elb.bar", "listener.206423021.instance_protocol", "http"),
    44  					resource.TestCheckResourceAttr(
    45  						"aws_elb.bar", "listener.206423021.ssl_certificate_id", ssl_certificate_id),
    46  					resource.TestCheckResourceAttr(
    47  						"aws_elb.bar", "listener.206423021.lb_port", "80"),
    48  					resource.TestCheckResourceAttr(
    49  						"aws_elb.bar", "listener.206423021.lb_protocol", "http"),
    50  					resource.TestCheckResourceAttr(
    51  						"aws_elb.bar", "cross_zone_load_balancing", "true"),
    52  				),
    53  			},
    54  		},
    55  	})
    56  }
    57  
    58  func TestAccAWSELB_fullCharacterRange(t *testing.T) {
    59  	var conf elb.LoadBalancerDescription
    60  
    61  	resource.Test(t, resource.TestCase{
    62  		PreCheck:     func() { testAccPreCheck(t) },
    63  		Providers:    testAccProviders,
    64  		CheckDestroy: testAccCheckAWSELBDestroy,
    65  		Steps: []resource.TestStep{
    66  			resource.TestStep{
    67  				Config: testAccAWSELBFullRangeOfCharacters,
    68  				Check: resource.ComposeTestCheckFunc(
    69  					testAccCheckAWSELBExists("aws_elb.foo", &conf),
    70  					resource.TestCheckResourceAttr(
    71  						"aws_elb.foo", "name", "FoobarTerraform-test123"),
    72  				),
    73  			},
    74  		},
    75  	})
    76  }
    77  
    78  func TestAccAWSELB_generatedName(t *testing.T) {
    79  	var conf elb.LoadBalancerDescription
    80  	generatedNameRegexp := regexp.MustCompile("^tf-lb-")
    81  
    82  	resource.Test(t, resource.TestCase{
    83  		PreCheck:     func() { testAccPreCheck(t) },
    84  		Providers:    testAccProviders,
    85  		CheckDestroy: testAccCheckAWSELBDestroy,
    86  		Steps: []resource.TestStep{
    87  			resource.TestStep{
    88  				Config: testAccAWSELBGeneratedName,
    89  				Check: resource.ComposeTestCheckFunc(
    90  					testAccCheckAWSELBExists("aws_elb.foo", &conf),
    91  					resource.TestMatchResourceAttr(
    92  						"aws_elb.foo", "name", generatedNameRegexp),
    93  				),
    94  			},
    95  		},
    96  	})
    97  }
    98  
    99  func TestAccAWSELB_tags(t *testing.T) {
   100  	var conf elb.LoadBalancerDescription
   101  	var td elb.TagDescription
   102  
   103  	resource.Test(t, resource.TestCase{
   104  		PreCheck:     func() { testAccPreCheck(t) },
   105  		Providers:    testAccProviders,
   106  		CheckDestroy: testAccCheckAWSELBDestroy,
   107  		Steps: []resource.TestStep{
   108  			resource.TestStep{
   109  				Config: testAccAWSELBConfig,
   110  				Check: resource.ComposeTestCheckFunc(
   111  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   112  					testAccCheckAWSELBAttributes(&conf),
   113  					resource.TestCheckResourceAttr(
   114  						"aws_elb.bar", "name", "foobar-terraform-test"),
   115  					testAccLoadTags(&conf, &td),
   116  					testAccCheckELBTags(&td.Tags, "bar", "baz"),
   117  				),
   118  			},
   119  
   120  			resource.TestStep{
   121  				Config: testAccAWSELBConfig_TagUpdate,
   122  				Check: resource.ComposeTestCheckFunc(
   123  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   124  					testAccCheckAWSELBAttributes(&conf),
   125  					resource.TestCheckResourceAttr(
   126  						"aws_elb.bar", "name", "foobar-terraform-test"),
   127  					testAccLoadTags(&conf, &td),
   128  					testAccCheckELBTags(&td.Tags, "foo", "bar"),
   129  					testAccCheckELBTags(&td.Tags, "new", "type"),
   130  				),
   131  			},
   132  		},
   133  	})
   134  }
   135  
   136  func testAccLoadTags(conf *elb.LoadBalancerDescription, td *elb.TagDescription) resource.TestCheckFunc {
   137  	return func(s *terraform.State) error {
   138  		conn := testAccProvider.Meta().(*AWSClient).elbconn
   139  
   140  		describe, err := conn.DescribeTags(&elb.DescribeTagsInput{
   141  			LoadBalancerNames: []*string{conf.LoadBalancerName},
   142  		})
   143  
   144  		if err != nil {
   145  			return err
   146  		}
   147  		if len(describe.TagDescriptions) > 0 {
   148  			*td = *describe.TagDescriptions[0]
   149  		}
   150  		return nil
   151  	}
   152  }
   153  
   154  func TestAccAWSELB_InstanceAttaching(t *testing.T) {
   155  	var conf elb.LoadBalancerDescription
   156  
   157  	testCheckInstanceAttached := func(count int) resource.TestCheckFunc {
   158  		return func(*terraform.State) error {
   159  			if len(conf.Instances) != count {
   160  				return fmt.Errorf("instance count does not match")
   161  			}
   162  			return nil
   163  		}
   164  	}
   165  
   166  	resource.Test(t, resource.TestCase{
   167  		PreCheck:     func() { testAccPreCheck(t) },
   168  		Providers:    testAccProviders,
   169  		CheckDestroy: testAccCheckAWSELBDestroy,
   170  		Steps: []resource.TestStep{
   171  			resource.TestStep{
   172  				Config: testAccAWSELBConfig,
   173  				Check: resource.ComposeTestCheckFunc(
   174  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   175  					testAccCheckAWSELBAttributes(&conf),
   176  				),
   177  			},
   178  
   179  			resource.TestStep{
   180  				Config: testAccAWSELBConfigNewInstance,
   181  				Check: resource.ComposeTestCheckFunc(
   182  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   183  					testCheckInstanceAttached(1),
   184  				),
   185  			},
   186  		},
   187  	})
   188  }
   189  
   190  func TestAccAWSELBUpdate_Listener(t *testing.T) {
   191  	var conf elb.LoadBalancerDescription
   192  
   193  	resource.Test(t, resource.TestCase{
   194  		PreCheck:     func() { testAccPreCheck(t) },
   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  					resource.TestCheckResourceAttr(
   204  						"aws_elb.bar", "listener.206423021.instance_port", "8000"),
   205  				),
   206  			},
   207  
   208  			resource.TestStep{
   209  				Config: testAccAWSELBConfigListener_update,
   210  				Check: resource.ComposeTestCheckFunc(
   211  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   212  					resource.TestCheckResourceAttr(
   213  						"aws_elb.bar", "listener.3931999347.instance_port", "8080"),
   214  				),
   215  			},
   216  		},
   217  	})
   218  }
   219  
   220  func TestAccAWSELB_HealthCheck(t *testing.T) {
   221  	var conf elb.LoadBalancerDescription
   222  
   223  	resource.Test(t, resource.TestCase{
   224  		PreCheck:     func() { testAccPreCheck(t) },
   225  		Providers:    testAccProviders,
   226  		CheckDestroy: testAccCheckAWSELBDestroy,
   227  		Steps: []resource.TestStep{
   228  			resource.TestStep{
   229  				Config: testAccAWSELBConfigHealthCheck,
   230  				Check: resource.ComposeTestCheckFunc(
   231  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   232  					testAccCheckAWSELBAttributesHealthCheck(&conf),
   233  					resource.TestCheckResourceAttr(
   234  						"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
   235  					resource.TestCheckResourceAttr(
   236  						"aws_elb.bar", "health_check.3484319807.unhealthy_threshold", "5"),
   237  					resource.TestCheckResourceAttr(
   238  						"aws_elb.bar", "health_check.3484319807.target", "HTTP:8000/"),
   239  					resource.TestCheckResourceAttr(
   240  						"aws_elb.bar", "health_check.3484319807.timeout", "30"),
   241  					resource.TestCheckResourceAttr(
   242  						"aws_elb.bar", "health_check.3484319807.interval", "60"),
   243  				),
   244  			},
   245  		},
   246  	})
   247  }
   248  
   249  func TestAccAWSELBUpdate_HealthCheck(t *testing.T) {
   250  	resource.Test(t, resource.TestCase{
   251  		PreCheck:     func() { testAccPreCheck(t) },
   252  		Providers:    testAccProviders,
   253  		CheckDestroy: testAccCheckAWSELBDestroy,
   254  		Steps: []resource.TestStep{
   255  			resource.TestStep{
   256  				Config: testAccAWSELBConfigHealthCheck,
   257  				Check: resource.ComposeTestCheckFunc(
   258  					resource.TestCheckResourceAttr(
   259  						"aws_elb.bar", "health_check.3484319807.healthy_threshold", "5"),
   260  				),
   261  			},
   262  			resource.TestStep{
   263  				Config: testAccAWSELBConfigHealthCheck_update,
   264  				Check: resource.ComposeTestCheckFunc(
   265  					resource.TestCheckResourceAttr(
   266  						"aws_elb.bar", "health_check.2648756019.healthy_threshold", "10"),
   267  				),
   268  			},
   269  		},
   270  	})
   271  }
   272  
   273  func TestAccAWSELB_Timeout(t *testing.T) {
   274  	var conf elb.LoadBalancerDescription
   275  
   276  	resource.Test(t, resource.TestCase{
   277  		PreCheck:     func() { testAccPreCheck(t) },
   278  		Providers:    testAccProviders,
   279  		CheckDestroy: testAccCheckAWSELBDestroy,
   280  		Steps: []resource.TestStep{
   281  			resource.TestStep{
   282  				Config: testAccAWSELBConfigIdleTimeout,
   283  				Check: resource.ComposeTestCheckFunc(
   284  					testAccCheckAWSELBExists("aws_elb.bar", &conf),
   285  					resource.TestCheckResourceAttr(
   286  						"aws_elb.bar", "idle_timeout", "200",
   287  					),
   288  				),
   289  			},
   290  		},
   291  	})
   292  }
   293  
   294  func TestAccAWSELBUpdate_Timeout(t *testing.T) {
   295  	resource.Test(t, resource.TestCase{
   296  		PreCheck:     func() { testAccPreCheck(t) },
   297  		Providers:    testAccProviders,
   298  		CheckDestroy: testAccCheckAWSELBDestroy,
   299  		Steps: []resource.TestStep{
   300  			resource.TestStep{
   301  				Config: testAccAWSELBConfigIdleTimeout,
   302  				Check: resource.ComposeTestCheckFunc(
   303  					resource.TestCheckResourceAttr(
   304  						"aws_elb.bar", "idle_timeout", "200",
   305  					),
   306  				),
   307  			},
   308  			resource.TestStep{
   309  				Config: testAccAWSELBConfigIdleTimeout_update,
   310  				Check: resource.ComposeTestCheckFunc(
   311  					resource.TestCheckResourceAttr(
   312  						"aws_elb.bar", "idle_timeout", "400",
   313  					),
   314  				),
   315  			},
   316  		},
   317  	})
   318  }
   319  
   320  func TestAccAWSELB_ConnectionDraining(t *testing.T) {
   321  	resource.Test(t, resource.TestCase{
   322  		PreCheck:     func() { testAccPreCheck(t) },
   323  		Providers:    testAccProviders,
   324  		CheckDestroy: testAccCheckAWSELBDestroy,
   325  		Steps: []resource.TestStep{
   326  			resource.TestStep{
   327  				Config: testAccAWSELBConfigConnectionDraining,
   328  				Check: resource.ComposeTestCheckFunc(
   329  					resource.TestCheckResourceAttr(
   330  						"aws_elb.bar", "connection_draining", "true",
   331  					),
   332  					resource.TestCheckResourceAttr(
   333  						"aws_elb.bar", "connection_draining_timeout", "400",
   334  					),
   335  				),
   336  			},
   337  		},
   338  	})
   339  }
   340  
   341  func TestAccAWSELBUpdate_ConnectionDraining(t *testing.T) {
   342  	resource.Test(t, resource.TestCase{
   343  		PreCheck:     func() { testAccPreCheck(t) },
   344  		Providers:    testAccProviders,
   345  		CheckDestroy: testAccCheckAWSELBDestroy,
   346  		Steps: []resource.TestStep{
   347  			resource.TestStep{
   348  				Config: testAccAWSELBConfigConnectionDraining,
   349  				Check: resource.ComposeTestCheckFunc(
   350  					resource.TestCheckResourceAttr(
   351  						"aws_elb.bar", "connection_draining", "true",
   352  					),
   353  					resource.TestCheckResourceAttr(
   354  						"aws_elb.bar", "connection_draining_timeout", "400",
   355  					),
   356  				),
   357  			},
   358  			resource.TestStep{
   359  				Config: testAccAWSELBConfigConnectionDraining_update_timeout,
   360  				Check: resource.ComposeTestCheckFunc(
   361  					resource.TestCheckResourceAttr(
   362  						"aws_elb.bar", "connection_draining", "true",
   363  					),
   364  					resource.TestCheckResourceAttr(
   365  						"aws_elb.bar", "connection_draining_timeout", "600",
   366  					),
   367  				),
   368  			},
   369  			resource.TestStep{
   370  				Config: testAccAWSELBConfigConnectionDraining_update_disable,
   371  				Check: resource.ComposeTestCheckFunc(
   372  					resource.TestCheckResourceAttr(
   373  						"aws_elb.bar", "connection_draining", "false",
   374  					),
   375  				),
   376  			},
   377  		},
   378  	})
   379  }
   380  
   381  func TestAccAWSELB_SecurityGroups(t *testing.T) {
   382  	resource.Test(t, resource.TestCase{
   383  		PreCheck:     func() { testAccPreCheck(t) },
   384  		Providers:    testAccProviders,
   385  		CheckDestroy: testAccCheckAWSELBDestroy,
   386  		Steps: []resource.TestStep{
   387  			resource.TestStep{
   388  				Config: testAccAWSELBConfig,
   389  				Check: resource.ComposeTestCheckFunc(
   390  					resource.TestCheckResourceAttr(
   391  						"aws_elb.bar", "security_groups.#", "0",
   392  					),
   393  				),
   394  			},
   395  			resource.TestStep{
   396  				Config: testAccAWSELBConfigSecurityGroups,
   397  				Check: resource.ComposeTestCheckFunc(
   398  					resource.TestCheckResourceAttr(
   399  						"aws_elb.bar", "security_groups.#", "1",
   400  					),
   401  				),
   402  			},
   403  		},
   404  	})
   405  }
   406  
   407  // Unit test for listeners hash
   408  func TestResourceAwsElbListenerHash(t *testing.T) {
   409  	cases := map[string]struct {
   410  		Left  map[string]interface{}
   411  		Right map[string]interface{}
   412  		Match bool
   413  	}{
   414  		"protocols are case insensitive": {
   415  			map[string]interface{}{
   416  				"instance_port":     80,
   417  				"instance_protocol": "TCP",
   418  				"lb_port":           80,
   419  				"lb_protocol":       "TCP",
   420  			},
   421  			map[string]interface{}{
   422  				"instance_port":     80,
   423  				"instance_protocol": "Tcp",
   424  				"lb_port":           80,
   425  				"lb_protocol":       "tcP",
   426  			},
   427  			true,
   428  		},
   429  	}
   430  
   431  	for tn, tc := range cases {
   432  		leftHash := resourceAwsElbListenerHash(tc.Left)
   433  		rightHash := resourceAwsElbListenerHash(tc.Right)
   434  		if (leftHash == rightHash) != tc.Match {
   435  			t.Fatalf("%s: expected match: %t, but did not get it", tn, tc.Match)
   436  		}
   437  	}
   438  }
   439  
   440  func testAccCheckAWSELBDestroy(s *terraform.State) error {
   441  	conn := testAccProvider.Meta().(*AWSClient).elbconn
   442  
   443  	for _, rs := range s.RootModule().Resources {
   444  		if rs.Type != "aws_elb" {
   445  			continue
   446  		}
   447  
   448  		describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
   449  			LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
   450  		})
   451  
   452  		if err == nil {
   453  			if len(describe.LoadBalancerDescriptions) != 0 &&
   454  				*describe.LoadBalancerDescriptions[0].LoadBalancerName == rs.Primary.ID {
   455  				return fmt.Errorf("ELB still exists")
   456  			}
   457  		}
   458  
   459  		// Verify the error
   460  		providerErr, ok := err.(awserr.Error)
   461  		if !ok {
   462  			return err
   463  		}
   464  
   465  		if providerErr.Code() != "InvalidLoadBalancerName.NotFound" {
   466  			return fmt.Errorf("Unexpected error: %s", err)
   467  		}
   468  	}
   469  
   470  	return nil
   471  }
   472  
   473  func testAccCheckAWSELBAttributes(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
   474  	return func(s *terraform.State) error {
   475  		zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
   476  		azs := make([]string, 0, len(conf.AvailabilityZones))
   477  		for _, x := range conf.AvailabilityZones {
   478  			azs = append(azs, *x)
   479  		}
   480  		sort.StringSlice(azs).Sort()
   481  		if !reflect.DeepEqual(azs, zones) {
   482  			return fmt.Errorf("bad availability_zones")
   483  		}
   484  
   485  		if *conf.LoadBalancerName != "foobar-terraform-test" {
   486  			return fmt.Errorf("bad name")
   487  		}
   488  
   489  		l := elb.Listener{
   490  			InstancePort:     aws.Int64(int64(8000)),
   491  			InstanceProtocol: aws.String("HTTP"),
   492  			LoadBalancerPort: aws.Int64(int64(80)),
   493  			Protocol:         aws.String("HTTP"),
   494  		}
   495  
   496  		if !reflect.DeepEqual(conf.ListenerDescriptions[0].Listener, &l) {
   497  			return fmt.Errorf(
   498  				"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
   499  				conf.ListenerDescriptions[0].Listener,
   500  				l)
   501  		}
   502  
   503  		if *conf.DNSName == "" {
   504  			return fmt.Errorf("empty dns_name")
   505  		}
   506  
   507  		return nil
   508  	}
   509  }
   510  
   511  func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancerDescription) resource.TestCheckFunc {
   512  	return func(s *terraform.State) error {
   513  		zones := []string{"us-west-2a", "us-west-2b", "us-west-2c"}
   514  		azs := make([]string, 0, len(conf.AvailabilityZones))
   515  		for _, x := range conf.AvailabilityZones {
   516  			azs = append(azs, *x)
   517  		}
   518  		sort.StringSlice(azs).Sort()
   519  		if !reflect.DeepEqual(azs, zones) {
   520  			return fmt.Errorf("bad availability_zones")
   521  		}
   522  
   523  		if *conf.LoadBalancerName != "foobar-terraform-test" {
   524  			return fmt.Errorf("bad name")
   525  		}
   526  
   527  		check := &elb.HealthCheck{
   528  			Timeout:            aws.Int64(int64(30)),
   529  			UnhealthyThreshold: aws.Int64(int64(5)),
   530  			HealthyThreshold:   aws.Int64(int64(5)),
   531  			Interval:           aws.Int64(int64(60)),
   532  			Target:             aws.String("HTTP:8000/"),
   533  		}
   534  
   535  		if !reflect.DeepEqual(conf.HealthCheck, check) {
   536  			return fmt.Errorf(
   537  				"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
   538  				conf.HealthCheck,
   539  				check)
   540  		}
   541  
   542  		if *conf.DNSName == "" {
   543  			return fmt.Errorf("empty dns_name")
   544  		}
   545  
   546  		return nil
   547  	}
   548  }
   549  
   550  func testAccCheckAWSELBExists(n string, res *elb.LoadBalancerDescription) resource.TestCheckFunc {
   551  	return func(s *terraform.State) error {
   552  		rs, ok := s.RootModule().Resources[n]
   553  		if !ok {
   554  			return fmt.Errorf("Not found: %s", n)
   555  		}
   556  
   557  		if rs.Primary.ID == "" {
   558  			return fmt.Errorf("No ELB ID is set")
   559  		}
   560  
   561  		conn := testAccProvider.Meta().(*AWSClient).elbconn
   562  
   563  		describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancersInput{
   564  			LoadBalancerNames: []*string{aws.String(rs.Primary.ID)},
   565  		})
   566  
   567  		if err != nil {
   568  			return err
   569  		}
   570  
   571  		if len(describe.LoadBalancerDescriptions) != 1 ||
   572  			*describe.LoadBalancerDescriptions[0].LoadBalancerName != rs.Primary.ID {
   573  			return fmt.Errorf("ELB not found")
   574  		}
   575  
   576  		*res = *describe.LoadBalancerDescriptions[0]
   577  
   578  		return nil
   579  	}
   580  }
   581  
   582  const testAccAWSELBConfig = `
   583  resource "aws_elb" "bar" {
   584    name = "foobar-terraform-test"
   585    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   586  
   587    listener {
   588      instance_port = 8000
   589      instance_protocol = "http"
   590      lb_port = 80
   591      // Protocol should be case insensitive
   592      lb_protocol = "HttP"
   593    }
   594  
   595  	tags {
   596  		bar = "baz"
   597  	}
   598  
   599    cross_zone_load_balancing = true
   600  }
   601  `
   602  
   603  const testAccAWSELBFullRangeOfCharacters = `
   604  resource "aws_elb" "foo" {
   605    name = "FoobarTerraform-test123"
   606    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   607  
   608    listener {
   609      instance_port = 8000
   610      instance_protocol = "http"
   611      lb_port = 80
   612      lb_protocol = "http"
   613    }
   614  }
   615  `
   616  
   617  const testAccAWSELBGeneratedName = `
   618  resource "aws_elb" "foo" {
   619    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   620  
   621    listener {
   622      instance_port = 8000
   623      instance_protocol = "http"
   624      lb_port = 80
   625      lb_protocol = "http"
   626    }
   627  }
   628  `
   629  
   630  const testAccAWSELBConfig_TagUpdate = `
   631  resource "aws_elb" "bar" {
   632    name = "foobar-terraform-test"
   633    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   634  
   635    listener {
   636      instance_port = 8000
   637      instance_protocol = "http"
   638      lb_port = 80
   639      lb_protocol = "http"
   640    }
   641  
   642  	tags {
   643  		foo = "bar"
   644  		new = "type"
   645  	}
   646  
   647    cross_zone_load_balancing = true
   648  }
   649  `
   650  
   651  const testAccAWSELBConfigNewInstance = `
   652  resource "aws_elb" "bar" {
   653    name = "foobar-terraform-test"
   654    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   655  
   656    listener {
   657      instance_port = 8000
   658      instance_protocol = "http"
   659      lb_port = 80
   660      lb_protocol = "http"
   661    }
   662  
   663    instances = ["${aws_instance.foo.id}"]
   664  }
   665  
   666  resource "aws_instance" "foo" {
   667  	# us-west-2
   668  	ami = "ami-043a5034"
   669  	instance_type = "t1.micro"
   670  }
   671  `
   672  
   673  const testAccAWSELBConfigListenerSSLCertificateId = `
   674  resource "aws_elb" "bar" {
   675    name = "foobar-terraform-test"
   676    availability_zones = ["us-west-2a"]
   677  
   678    listener {
   679      instance_port = 8000
   680      instance_protocol = "http"
   681      ssl_certificate_id = "%s"
   682      lb_port = 443
   683      lb_protocol = "https"
   684    }
   685  }
   686  `
   687  
   688  const testAccAWSELBConfigHealthCheck = `
   689  resource "aws_elb" "bar" {
   690    name = "foobar-terraform-test"
   691    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   692  
   693    listener {
   694      instance_port = 8000
   695      instance_protocol = "http"
   696      lb_port = 80
   697      lb_protocol = "http"
   698    }
   699  
   700    health_check {
   701      healthy_threshold = 5
   702      unhealthy_threshold = 5
   703      target = "HTTP:8000/"
   704      interval = 60
   705      timeout = 30
   706    }
   707  }
   708  `
   709  
   710  const testAccAWSELBConfigHealthCheck_update = `
   711  resource "aws_elb" "bar" {
   712    name = "foobar-terraform-test"
   713    availability_zones = ["us-west-2a"]
   714  
   715    listener {
   716      instance_port = 8000
   717      instance_protocol = "http"
   718      lb_port = 80
   719      lb_protocol = "http"
   720    }
   721  
   722    health_check {
   723      healthy_threshold = 10
   724      unhealthy_threshold = 5
   725      target = "HTTP:8000/"
   726      interval = 60
   727      timeout = 30
   728    }
   729  }
   730  `
   731  
   732  const testAccAWSELBConfigListener_update = `
   733  resource "aws_elb" "bar" {
   734    name = "foobar-terraform-test"
   735    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   736  
   737    listener {
   738      instance_port = 8080
   739      instance_protocol = "http"
   740      lb_port = 80
   741      lb_protocol = "http"
   742    }
   743  }
   744  `
   745  
   746  const testAccAWSELBConfigIdleTimeout = `
   747  resource "aws_elb" "bar" {
   748  	name = "foobar-terraform-test"
   749  	availability_zones = ["us-west-2a"]
   750  
   751  	listener {
   752  		instance_port = 8000
   753  		instance_protocol = "http"
   754  		lb_port = 80
   755  		lb_protocol = "http"
   756  	}
   757  
   758  	idle_timeout = 200
   759  }
   760  `
   761  
   762  const testAccAWSELBConfigIdleTimeout_update = `
   763  resource "aws_elb" "bar" {
   764  	name = "foobar-terraform-test"
   765  	availability_zones = ["us-west-2a"]
   766  
   767  	listener {
   768  		instance_port = 8000
   769  		instance_protocol = "http"
   770  		lb_port = 80
   771  		lb_protocol = "http"
   772  	}
   773  
   774  	idle_timeout = 400
   775  }
   776  `
   777  
   778  const testAccAWSELBConfigConnectionDraining = `
   779  resource "aws_elb" "bar" {
   780  	name = "foobar-terraform-test"
   781  	availability_zones = ["us-west-2a"]
   782  
   783  	listener {
   784  		instance_port = 8000
   785  		instance_protocol = "http"
   786  		lb_port = 80
   787  		lb_protocol = "http"
   788  	}
   789  
   790  	connection_draining = true
   791  	connection_draining_timeout = 400
   792  }
   793  `
   794  
   795  const testAccAWSELBConfigConnectionDraining_update_timeout = `
   796  resource "aws_elb" "bar" {
   797  	name = "foobar-terraform-test"
   798  	availability_zones = ["us-west-2a"]
   799  
   800  	listener {
   801  		instance_port = 8000
   802  		instance_protocol = "http"
   803  		lb_port = 80
   804  		lb_protocol = "http"
   805  	}
   806  
   807  	connection_draining = true
   808  	connection_draining_timeout = 600
   809  }
   810  `
   811  
   812  const testAccAWSELBConfigConnectionDraining_update_disable = `
   813  resource "aws_elb" "bar" {
   814  	name = "foobar-terraform-test"
   815  	availability_zones = ["us-west-2a"]
   816  
   817  	listener {
   818  		instance_port = 8000
   819  		instance_protocol = "http"
   820  		lb_port = 80
   821  		lb_protocol = "http"
   822  	}
   823  
   824  	connection_draining = false
   825  }
   826  `
   827  
   828  const testAccAWSELBConfigSecurityGroups = `
   829  resource "aws_elb" "bar" {
   830    name = "foobar-terraform-test"
   831    availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
   832  
   833    listener {
   834      instance_port = 8000
   835      instance_protocol = "http"
   836      lb_port = 80
   837      lb_protocol = "http"
   838    }
   839  
   840    security_groups = ["${aws_security_group.bar.id}"]
   841  }
   842  
   843  resource "aws_security_group" "bar" {
   844    name = "terraform-elb-acceptance-test"
   845    description = "Used in the terraform acceptance tests for the elb resource"
   846  
   847    ingress {
   848      protocol = "tcp"
   849      from_port = 80
   850      to_port = 80
   851      cidr_blocks = ["0.0.0.0/0"]
   852    }
   853  }
   854  `