@@ -44,6 +44,40 @@ func TestAccAWSALB_basic(t *testing.T) {
4444 })
4545}
4646
47+ // TestAccAWSALB_noSecurityGroup regression tests the issue in #8264,
48+ // where if an ALB is created without a security group, a default one
49+ // is assigned.
50+ func TestAccAWSALB_noSecurityGroup (t * testing.T ) {
51+ var conf elbv2.LoadBalancer
52+ albName := fmt .Sprintf ("testaccawsalb-nosg-%s" , acctest .RandStringFromCharSet (10 , acctest .CharSetAlphaNum ))
53+
54+ resource .Test (t , resource.TestCase {
55+ PreCheck : func () { testAccPreCheck (t ) },
56+ IDRefreshName : "aws_alb.alb_test" ,
57+ Providers : testAccProviders ,
58+ CheckDestroy : testAccCheckAWSALBDestroy ,
59+ Steps : []resource.TestStep {
60+ {
61+ Config : testAccAWSALBConfig_nosg (albName ),
62+ Check : resource .ComposeAggregateTestCheckFunc (
63+ testAccCheckAWSALBExists ("aws_alb.alb_test" , & conf ),
64+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "name" , albName ),
65+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "internal" , "false" ),
66+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "subnets.#" , "2" ),
67+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "security_groups.#" , "1" ),
68+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "tags.%" , "1" ),
69+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "tags.TestName" , "TestAccAWSALB_basic" ),
70+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "enable_deletion_protection" , "false" ),
71+ resource .TestCheckResourceAttr ("aws_alb.alb_test" , "idle_timeout" , "30" ),
72+ resource .TestCheckResourceAttrSet ("aws_alb.alb_test" , "vpc_id" ),
73+ resource .TestCheckResourceAttrSet ("aws_alb.alb_test" , "zone_id" ),
74+ resource .TestCheckResourceAttrSet ("aws_alb.alb_test" , "dns_name" ),
75+ ),
76+ },
77+ },
78+ })
79+ }
80+
4781func TestAccAWSALB_accesslogs (t * testing.T ) {
4882 var conf elbv2.LoadBalancer
4983 bucketName := fmt .Sprintf ("testaccawsalbaccesslogs-%s" , acctest .RandStringFromCharSet (6 , acctest .CharSetAlphaNum ))
@@ -334,3 +368,45 @@ resource "aws_security_group" "alb_test" {
334368 }
335369}` , albName , bucketName )
336370}
371+
372+ func testAccAWSALBConfig_nosg (albName string ) string {
373+ return fmt .Sprintf (`resource "aws_alb" "alb_test" {
374+ name = "%s"
375+ internal = false
376+ subnets = ["${aws_subnet.alb_test.*.id}"]
377+
378+ idle_timeout = 30
379+ enable_deletion_protection = false
380+
381+ tags {
382+ TestName = "TestAccAWSALB_basic"
383+ }
384+ }
385+
386+ variable "subnets" {
387+ default = ["10.0.1.0/24", "10.0.2.0/24"]
388+ type = "list"
389+ }
390+
391+ data "aws_availability_zones" "available" {}
392+
393+ resource "aws_vpc" "alb_test" {
394+ cidr_block = "10.0.0.0/16"
395+
396+ tags {
397+ TestName = "TestAccAWSALB_basic"
398+ }
399+ }
400+
401+ resource "aws_subnet" "alb_test" {
402+ count = 2
403+ vpc_id = "${aws_vpc.alb_test.id}"
404+ cidr_block = "${element(var.subnets, count.index)}"
405+ map_public_ip_on_launch = true
406+ availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}"
407+
408+ tags {
409+ TestName = "TestAccAWSALB_basic"
410+ }
411+ }` , albName )
412+ }
0 commit comments