diff --git a/internal/service/elbv2/load_balancer.go b/internal/service/elbv2/load_balancer.go index d5cf371bd7b..849b31031a7 100644 --- a/internal/service/elbv2/load_balancer.go +++ b/internal/service/elbv2/load_balancer.go @@ -499,7 +499,8 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta d.Set("enforce_security_group_inbound_rules_on_private_link_traffic", lb.EnforceSecurityGroupInboundRulesOnPrivateLinkTraffic) d.Set("internal", aws.StringValue(lb.Scheme) == elbv2.LoadBalancerSchemeEnumInternal) d.Set("ip_address_type", lb.IpAddressType) - d.Set("load_balancer_type", lb.Type) + lbType := aws.StringValue(lb.Type) + d.Set("load_balancer_type", lbType) d.Set("name", lb.LoadBalancerName) d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(lb.LoadBalancerName))) d.Set("security_groups", aws.StringValueSlice(lb.SecurityGroups)) @@ -522,8 +523,10 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "setting access_logs: %s", err) } - if err := d.Set("connection_logs", []interface{}{flattenLoadBalancerConnectionLogsAttributes(attributes)}); err != nil { - return sdkdiag.AppendErrorf(diags, "setting connection_logs: %s", err) + if lbType == elbv2.LoadBalancerTypeEnumApplication { + if err := d.Set("connection_logs", []interface{}{flattenLoadBalancerConnectionLogsAttributes(attributes)}); err != nil { + return sdkdiag.AppendErrorf(diags, "setting connection_logs: %s", err) + } } loadBalancerAttributes.flatten(d, attributes) diff --git a/internal/service/elbv2/load_balancer_test.go b/internal/service/elbv2/load_balancer_test.go index 207fcc19e0b..8cab88eca2a 100644 --- a/internal/service/elbv2/load_balancer_test.go +++ b/internal/service/elbv2/load_balancer_test.go @@ -131,7 +131,7 @@ func TestAccELBV2LoadBalancer_NLB_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "access_logs.#", "1"), resource.TestCheckResourceAttr(resourceName, "access_logs.0.enabled", "false"), acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "elasticloadbalancing", regexache.MustCompile(fmt.Sprintf("loadbalancer/net/%s/.+", rName))), - resource.TestCheckResourceAttr(resourceName, "connection_logs.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "connection_logs.#"), resource.TestCheckResourceAttrSet(resourceName, "dns_name"), resource.TestCheckResourceAttr(resourceName, "dns_record_client_routing_policy", "any_availability_zone"), resource.TestCheckResourceAttr(resourceName, "enable_deletion_protection", "false"),