diff --git a/aws/data_source_aws_lb.go b/aws/data_source_aws_lb.go index 1e3d2a4f02c..c918fdd3a33 100644 --- a/aws/data_source_aws_lb.go +++ b/aws/data_source_aws_lb.go @@ -14,9 +14,10 @@ func dataSourceAwsLb() *schema.Resource { Read: dataSourceAwsLbRead, Schema: map[string]*schema.Schema{ "arn": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validateArn, }, "arn_suffix": { @@ -44,14 +45,12 @@ func dataSourceAwsLb() *schema.Resource { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Computed: true, - Set: schema.HashString, }, "subnets": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, Computed: true, - Set: schema.HashString, }, "subnet_mapping": { @@ -61,11 +60,15 @@ func dataSourceAwsLb() *schema.Resource { Schema: map[string]*schema.Schema{ "subnet_id": { Type: schema.TypeString, - Required: true, + Computed: true, }, "allocation_id": { Type: schema.TypeString, - Optional: true, + Computed: true, + }, + "private_ipv4_address": { + Type: schema.TypeString, + Computed: true, }, }, }, @@ -138,7 +141,7 @@ func dataSourceAwsLb() *schema.Resource { } func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error { - elbconn := meta.(*AWSClient).elbv2conn + conn := meta.(*AWSClient).elbv2conn lbArn := d.Get("arn").(string) lbName := d.Get("name").(string) @@ -151,7 +154,7 @@ func dataSourceAwsLbRead(d *schema.ResourceData, meta interface{}) error { } log.Printf("[DEBUG] Reading Load Balancer: %s", describeLbOpts) - describeResp, err := elbconn.DescribeLoadBalancers(describeLbOpts) + describeResp, err := conn.DescribeLoadBalancers(describeLbOpts) if err != nil { return fmt.Errorf("Error retrieving LB: %s", err) } diff --git a/aws/data_source_aws_lb_test.go b/aws/data_source_aws_lb_test.go index ca5b8ad2e44..3ebfcc1d473 100644 --- a/aws/data_source_aws_lb_test.go +++ b/aws/data_source_aws_lb_test.go @@ -12,6 +12,7 @@ func TestAccDataSourceAWSLB_basic(t *testing.T) { lbName := fmt.Sprintf("testaccawslb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) dataSourceName := "data.aws_lb.alb_test_with_arn" dataSourceName2 := "data.aws_lb.alb_test_with_name" + resourceName := "aws_lb.alb_test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -20,32 +21,34 @@ func TestAccDataSourceAWSLB_basic(t *testing.T) { { Config: testAccDataSourceAWSLBConfigBasic(lbName), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", lbName), - resource.TestCheckResourceAttr(dataSourceName, "internal", "true"), - resource.TestCheckResourceAttr(dataSourceName, "subnets.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "security_groups.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.TestName", "TestAccAWSALB_basic"), - resource.TestCheckResourceAttr(dataSourceName, "enable_deletion_protection", "false"), - resource.TestCheckResourceAttr(dataSourceName, "idle_timeout", "30"), - resource.TestCheckResourceAttrSet(dataSourceName, "vpc_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "zone_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "dns_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "arn"), - resource.TestCheckResourceAttrSet(dataSourceName, "ip_address_type"), - resource.TestCheckResourceAttr(dataSourceName2, "name", lbName), - resource.TestCheckResourceAttr(dataSourceName2, "internal", "true"), - resource.TestCheckResourceAttr(dataSourceName2, "subnets.#", "2"), - resource.TestCheckResourceAttr(dataSourceName2, "security_groups.#", "1"), - resource.TestCheckResourceAttr(dataSourceName2, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName2, "tags.TestName", "TestAccAWSALB_basic"), - resource.TestCheckResourceAttr(dataSourceName2, "enable_deletion_protection", "false"), - resource.TestCheckResourceAttr(dataSourceName2, "idle_timeout", "30"), - resource.TestCheckResourceAttrSet(dataSourceName2, "vpc_id"), - resource.TestCheckResourceAttrSet(dataSourceName2, "zone_id"), - resource.TestCheckResourceAttrSet(dataSourceName2, "dns_name"), - resource.TestCheckResourceAttrSet(dataSourceName2, "arn"), - resource.TestCheckResourceAttrSet(dataSourceName2, "ip_address_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName, "internal", resourceName, "internal"), + resource.TestCheckResourceAttrPair(dataSourceName, "subnets.#", resourceName, "subnets.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "security_groups.#", resourceName, "security_groups.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), + resource.TestCheckResourceAttrPair(dataSourceName, "tags.TestName", resourceName, "tags.TestName"), + resource.TestCheckResourceAttrPair(dataSourceName, "enable_deletion_protection", resourceName, "enable_deletion_protection"), + resource.TestCheckResourceAttrPair(dataSourceName, "idle_timeout", resourceName, "idle_timeout"), + resource.TestCheckResourceAttrPair(dataSourceName, "vpc_id", resourceName, "vpc_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "zone_id", resourceName, "zone_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "dns_name", resourceName, "dns_name"), + resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName, "ip_address_type", resourceName, "ip_address_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "subnet_mapping.#", resourceName, "subnet_mapping.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName2, "internal", resourceName, "internal"), + resource.TestCheckResourceAttrPair(dataSourceName2, "subnets.#", resourceName, "subnets.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "security_groups.#", resourceName, "security_groups.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "tags.%", resourceName, "tags.%"), + resource.TestCheckResourceAttrPair(dataSourceName2, "tags.TestName", resourceName, "tags.TestName"), + resource.TestCheckResourceAttrPair(dataSourceName2, "enable_deletion_protection", resourceName, "enable_deletion_protection"), + resource.TestCheckResourceAttrPair(dataSourceName2, "idle_timeout", resourceName, "idle_timeout"), + resource.TestCheckResourceAttrPair(dataSourceName2, "vpc_id", resourceName, "vpc_id"), + resource.TestCheckResourceAttrPair(dataSourceName2, "zone_id", resourceName, "zone_id"), + resource.TestCheckResourceAttrPair(dataSourceName2, "dns_name", resourceName, "dns_name"), + resource.TestCheckResourceAttrPair(dataSourceName2, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName2, "ip_address_type", resourceName, "ip_address_type"), + resource.TestCheckResourceAttrPair(dataSourceName2, "subnet_mapping.#", resourceName, "subnet_mapping.#"), ), }, }, @@ -56,6 +59,8 @@ func TestAccDataSourceAWSLB_BackwardsCompatibility(t *testing.T) { lbName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) dataSourceName1 := "data.aws_alb.alb_test_with_arn" dataSourceName2 := "data.aws_alb.alb_test_with_name" + resourceName := "aws_alb.alb_test" + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -63,30 +68,40 @@ func TestAccDataSourceAWSLB_BackwardsCompatibility(t *testing.T) { { Config: testAccDataSourceAWSLBConfigBackardsCompatibility(lbName), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName1, "name", lbName), - resource.TestCheckResourceAttr(dataSourceName1, "internal", "true"), - resource.TestCheckResourceAttr(dataSourceName1, "subnets.#", "2"), - resource.TestCheckResourceAttr(dataSourceName1, "security_groups.#", "1"), - resource.TestCheckResourceAttr(dataSourceName1, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName1, "tags.TestName", "TestAccAWSALB_basic"), - resource.TestCheckResourceAttr(dataSourceName1, "enable_deletion_protection", "false"), - resource.TestCheckResourceAttr(dataSourceName1, "idle_timeout", "30"), - resource.TestCheckResourceAttrSet(dataSourceName1, "vpc_id"), - resource.TestCheckResourceAttrSet(dataSourceName1, "zone_id"), - resource.TestCheckResourceAttrSet(dataSourceName1, "dns_name"), - resource.TestCheckResourceAttrSet(dataSourceName1, "arn"), - resource.TestCheckResourceAttr(dataSourceName2, "name", lbName), - resource.TestCheckResourceAttr(dataSourceName2, "internal", "true"), - resource.TestCheckResourceAttr(dataSourceName2, "subnets.#", "2"), - resource.TestCheckResourceAttr(dataSourceName2, "security_groups.#", "1"), - resource.TestCheckResourceAttr(dataSourceName2, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName2, "tags.TestName", "TestAccAWSALB_basic"), - resource.TestCheckResourceAttr(dataSourceName2, "enable_deletion_protection", "false"), - resource.TestCheckResourceAttr(dataSourceName2, "idle_timeout", "30"), - resource.TestCheckResourceAttrSet(dataSourceName2, "vpc_id"), - resource.TestCheckResourceAttrSet(dataSourceName2, "zone_id"), - resource.TestCheckResourceAttrSet(dataSourceName2, "dns_name"), - resource.TestCheckResourceAttrSet(dataSourceName2, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName1, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName1, "internal", resourceName, "internal"), + resource.TestCheckResourceAttrPair(dataSourceName1, "subnets.#", resourceName, "subnets.#"), + resource.TestCheckResourceAttrPair(dataSourceName1, "security_groups.#", resourceName, "security_groups.#"), + resource.TestCheckResourceAttrPair(dataSourceName1, "tags.%", resourceName, "tags.%"), + resource.TestCheckResourceAttrPair(dataSourceName1, "tags.TestName", resourceName, "tags.TestName"), + resource.TestCheckResourceAttrPair(dataSourceName1, "enable_deletion_protection", resourceName, "enable_deletion_protection"), + resource.TestCheckResourceAttrPair(dataSourceName1, "idle_timeout", resourceName, "idle_timeout"), + resource.TestCheckResourceAttrPair(dataSourceName1, "vpc_id", resourceName, "vpc_id"), + resource.TestCheckResourceAttrPair(dataSourceName1, "zone_id", resourceName, "zone_id"), + resource.TestCheckResourceAttrPair(dataSourceName1, "dns_name", resourceName, "dns_name"), + resource.TestCheckResourceAttrPair(dataSourceName1, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName1, "ip_address_type", resourceName, "ip_address_type"), + resource.TestCheckResourceAttrPair(dataSourceName1, "subnet_mapping.#", resourceName, "subnet_mapping.#"), + resource.TestCheckResourceAttrPair(dataSourceName1, "drop_invalid_header_fields", resourceName, "drop_invalid_header_fields"), + resource.TestCheckResourceAttrPair(dataSourceName1, "enable_http2", resourceName, "enable_http2"), + resource.TestCheckResourceAttrPair(dataSourceName1, "access_logs.#", resourceName, "access_logs.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "name", resourceName, "name"), + resource.TestCheckResourceAttrPair(dataSourceName2, "internal", resourceName, "internal"), + resource.TestCheckResourceAttrPair(dataSourceName2, "subnets.#", resourceName, "subnets.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "security_groups.#", resourceName, "security_groups.#"), + resource.TestCheckResourceAttrPair(dataSourceName2, "tags.%", resourceName, "tags.%"), + resource.TestCheckResourceAttrPair(dataSourceName2, "tags.TestName", resourceName, "tags.TestName"), + resource.TestCheckResourceAttrPair(dataSourceName2, "enable_deletion_protection", resourceName, "enable_deletion_protection"), + resource.TestCheckResourceAttrPair(dataSourceName2, "idle_timeout", resourceName, "idle_timeout"), + resource.TestCheckResourceAttrPair(dataSourceName2, "vpc_id", resourceName, "vpc_id"), + resource.TestCheckResourceAttrPair(dataSourceName2, "zone_id", resourceName, "zone_id"), + resource.TestCheckResourceAttrPair(dataSourceName2, "dns_name", resourceName, "dns_name"), + resource.TestCheckResourceAttrPair(dataSourceName2, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName2, "ip_address_type", resourceName, "ip_address_type"), + resource.TestCheckResourceAttrPair(dataSourceName2, "subnet_mapping.#", resourceName, "subnet_mapping.#"), + resource.TestCheckResourceAttrPair(dataSourceName1, "drop_invalid_header_fields", resourceName, "drop_invalid_header_fields"), + resource.TestCheckResourceAttrPair(dataSourceName1, "enable_http2", resourceName, "enable_http2"), + resource.TestCheckResourceAttrPair(dataSourceName1, "access_logs.#", resourceName, "access_logs.#"), ), }, },