Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_elb: Return any errors when updating listeners #4159

Merged
merged 1 commit into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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