github.com/econnell/terraform@v0.5.4-0.20150722160631-78eb236786a4/builtin/providers/aws/resource_aws_elb_test.go (about)

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