Skip to content

Commit

Permalink
Merge pull request #4159 from terraform-providers/b-aws_elb-add-liste…
Browse files Browse the repository at this point in the history
…ner-err

resource/aws_elb: Return any errors when updating listeners
  • Loading branch information
bflad authored Apr 11, 2018
2 parents a7c27f3 + e7a8ff9 commit 097201a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
5 changes: 4 additions & 1 deletion aws/resource_aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,10 @@ func resourceAwsElbUpdate(d *schema.ResourceData, meta interface{}) error {
ns := n.(*schema.Set)

remove, _ := expandListeners(os.Difference(ns).List())
add, _ := expandListeners(ns.Difference(os).List())
add, err := expandListeners(ns.Difference(os).List())
if err != nil {
return err
}

if len(remove) > 0 {
ports := make([]*int64, 0, len(remove))
Expand Down
83 changes: 61 additions & 22 deletions aws/resource_aws_elb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ func TestAccAWSELB_tags(t *testing.T) {
})
}

func TestAccAWSELB_iam_server_cert(t *testing.T) {
func TestAccAWSELB_Listener_SSLCertificateID_IAMServerCertificate(t *testing.T) {
var conf elb.LoadBalancerDescription
// var td elb.TagDescription
rName := fmt.Sprintf("tf-acctest-%s", acctest.RandString(10))
resourceName := "aws_elb.bar"

testCheck := func(*terraform.State) error {
if len(conf.ListenerDescriptions) != 1 {
return fmt.Errorf(
Expand All @@ -380,20 +382,27 @@ func TestAccAWSELB_iam_server_cert(t *testing.T) {
}
return nil
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_elb.bar",
Providers: testAccProvidersWithTLS,
CheckDestroy: testAccCheckAWSELBDestroy,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProvidersWithTLS,
CheckDestroy: testAccCheckAWSELBDestroy,
Steps: []resource.TestStep{
{
Config: testAccELBIAMServerCertConfig(
fmt.Sprintf("tf-acctest-%s", acctest.RandString(10))),
Config: testAccELBConfig_Listener_IAMServerCertificate(rName, "tcp"),
ExpectError: regexp.MustCompile(`ssl_certificate_id may be set only when protocol is 'https' or 'ssl'`),
},
{
Config: testAccELBConfig_Listener_IAMServerCertificate(rName, "https"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSELBExists("aws_elb.bar", &conf),
testAccCheckAWSELBExists(resourceName, &conf),
testCheck,
),
},
{
Config: testAccELBConfig_Listener_IAMServerCertificate_AddInvalidListener(rName),
ExpectError: regexp.MustCompile(`ssl_certificate_id may be set only when protocol is 'https' or 'ssl'`),
},
},
})
}
Expand Down Expand Up @@ -1624,33 +1633,63 @@ resource "aws_security_group" "bar" {
}
`

func testAccELBIAMServerCertConfig(certName string) string {
func testAccELBConfig_Listener_IAMServerCertificate(certName, lbProtocol string) string {
return fmt.Sprintf(`
%s
data "aws_availability_zones" "available" {}
%[1]s
resource "aws_iam_server_certificate" "test_cert" {
name = "%s"
name = "%[2]s"
certificate_body = "${tls_self_signed_cert.example.cert_pem}"
private_key = "${tls_private_key.example.private_key_pem}"
}
resource "aws_elb" "bar" {
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
availability_zones = ["${data.aws_availability_zones.available.names[0]}"]
listener {
instance_port = 8000
instance_protocol = "https"
lb_port = 80
// Protocol should be case insensitive
lb_protocol = "HttPs"
instance_port = 443
instance_protocol = "%[3]s"
lb_port = 443
lb_protocol = "%[3]s"
ssl_certificate_id = "${aws_iam_server_certificate.test_cert.arn}"
}
}
`, testAccTLSServerCert, certName, lbProtocol)
}

tags {
bar = "baz"
}
func testAccELBConfig_Listener_IAMServerCertificate_AddInvalidListener(certName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
cross_zone_load_balancing = true
%[1]s
resource "aws_iam_server_certificate" "test_cert" {
name = "%[2]s"
certificate_body = "${tls_self_signed_cert.example.cert_pem}"
private_key = "${tls_private_key.example.private_key_pem}"
}
resource "aws_elb" "bar" {
availability_zones = ["${data.aws_availability_zones.available.names[0]}"]
listener {
instance_port = 443
instance_protocol = "https"
lb_port = 443
lb_protocol = "https"
ssl_certificate_id = "${aws_iam_server_certificate.test_cert.arn}"
}
# lb_protocol tcp and ssl_certificate_id is not valid
listener {
instance_port = 8443
instance_protocol = "tcp"
lb_port = 8443
lb_protocol = "tcp"
ssl_certificate_id = "${aws_iam_server_certificate.test_cert.arn}"
}
}
`, testAccTLSServerCert, certName)
}
Expand Down

0 comments on commit 097201a

Please sign in to comment.