@@ -471,7 +471,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met
471
471
})
472
472
}
473
473
if v , ok := d .GetOk ("minimum_load_balancer_capacity" ); ok && len (v .([]any )) > 0 && v .([]any )[0 ] != nil {
474
- minCapacity = expandCapacity (v .([]any ))
474
+ minCapacity = expandMinimumLoadBalancerCapacity (v .([]any ))
475
475
}
476
476
}
477
477
@@ -492,8 +492,9 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, met
492
492
if err := modifyCapacityReservation (ctx , conn , d .Id (), minCapacity ); err != nil {
493
493
return sdkdiag .AppendFromErr (diags , err )
494
494
}
495
- if err := waitForModifyCapacityReservationToComplete (ctx , conn , d .Id (), d .Timeout (schema .TimeoutCreate )); err != nil {
496
- return sdkdiag .AppendErrorf (diags , "waiting for ELBv2 Load Balancer (%s) create: %s" , d .Id (), err )
495
+
496
+ if _ , err := waitCapacityReservationProvisioned (ctx , conn , d .Id (), d .Timeout (schema .TimeoutCreate )); err != nil {
497
+ return sdkdiag .AppendErrorf (diags , "waiting for ELBv2 Load Balancer (%s) capacity reservation provision: %s" , d .Id (), err )
497
498
}
498
499
}
499
500
@@ -592,13 +593,13 @@ func resourceLoadBalancerRead(ctx context.Context, d *schema.ResourceData, meta
592
593
loadBalancerAttributes .flatten (d , attributes )
593
594
594
595
if lb .Type == awstypes .LoadBalancerTypeEnumApplication || lb .Type == awstypes .LoadBalancerTypeEnumNetwork {
595
- capacity , err := findLoadBalancerCapacityByARN (ctx , conn , d .Id ())
596
+ capacity , err := findCapacityReservationByARN (ctx , conn , d .Id ())
596
597
597
598
if err != nil {
598
- return sdkdiag .AppendErrorf (diags , "reading ELBv2 Load Balancer (%s) capacity: %s" , d .Id (), err )
599
+ return sdkdiag .AppendErrorf (diags , "reading ELBv2 Load Balancer (%s) capacity reservation : %s" , d .Id (), err )
599
600
}
600
601
601
- if err := d .Set ("minimum_load_balancer_capacity" , flattenCapacity (capacity .MinimumLoadBalancerCapacity )); err != nil {
602
+ if err := d .Set ("minimum_load_balancer_capacity" , flattenMinimumLoadBalancerCapacity (capacity .MinimumLoadBalancerCapacity )); err != nil {
602
603
return sdkdiag .AppendErrorf (diags , "setting minimum_load_balancer_capacity: %s" , err )
603
604
}
604
605
}
@@ -717,12 +718,12 @@ func resourceLoadBalancerUpdate(ctx context.Context, d *schema.ResourceData, met
717
718
}
718
719
719
720
if d .HasChange ("minimum_load_balancer_capacity" ) {
720
- minCapacity := expandCapacity (d .Get ("minimum_load_balancer_capacity" ).([]any ))
721
- if err := modifyCapacityReservation (ctx , conn , d .Id (), minCapacity ); err != nil {
721
+ if err := modifyCapacityReservation (ctx , conn , d .Id (), expandMinimumLoadBalancerCapacity (d .Get ("minimum_load_balancer_capacity" ).([]any ))); err != nil {
722
722
return sdkdiag .AppendFromErr (diags , err )
723
723
}
724
- if err := waitForModifyCapacityReservationToComplete (ctx , conn , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
725
- return sdkdiag .AppendErrorf (diags , "waiting for ELBv2 Load Balancer (%s) update capacity reservation: %s" , d .Id (), err )
724
+
725
+ if _ , err := waitCapacityReservationProvisioned (ctx , conn , d .Id (), d .Timeout (schema .TimeoutUpdate )); err != nil {
726
+ return sdkdiag .AppendErrorf (diags , "waiting for ELBv2 Load Balancer (%s) capacity reservation provision: %s" , d .Id (), err )
726
727
}
727
728
}
728
729
@@ -766,7 +767,7 @@ func resourceLoadBalancerDelete(ctx context.Context, d *schema.ResourceData, met
766
767
}
767
768
768
769
func modifyLoadBalancerAttributes (ctx context.Context , conn * elasticloadbalancingv2.Client , arn string , attributes []awstypes.LoadBalancerAttribute ) error {
769
- input := & elasticloadbalancingv2.ModifyLoadBalancerAttributesInput {
770
+ input := elasticloadbalancingv2.ModifyLoadBalancerAttributesInput {
770
771
Attributes : attributes ,
771
772
LoadBalancerArn : aws .String (arn ),
772
773
}
@@ -777,7 +778,7 @@ func modifyLoadBalancerAttributes(ctx context.Context, conn *elasticloadbalancin
777
778
return nil
778
779
}
779
780
780
- _ , err := conn .ModifyLoadBalancerAttributes (ctx , input )
781
+ _ , err := conn .ModifyLoadBalancerAttributes (ctx , & input )
781
782
782
783
if err != nil {
783
784
// "Validation error: Load balancer attribute key 'routing.http.desync_mitigation_mode' is not recognized"
@@ -806,17 +807,18 @@ func modifyCapacityReservation(ctx context.Context, conn *elasticloadbalancingv2
806
807
} else if minCapacity .CapacityUnits == nil {
807
808
resetCapacityReservation = true
808
809
}
809
- input := & elasticloadbalancingv2.ModifyCapacityReservationInput {
810
- MinimumLoadBalancerCapacity : minCapacity ,
810
+ input := elasticloadbalancingv2.ModifyCapacityReservationInput {
811
811
LoadBalancerArn : aws .String (arn ),
812
+ MinimumLoadBalancerCapacity : minCapacity ,
812
813
ResetCapacityReservation : aws .Bool (resetCapacityReservation ),
813
814
}
814
815
815
- _ , err := conn .ModifyCapacityReservation (ctx , input )
816
+ _ , err := conn .ModifyCapacityReservation (ctx , & input )
816
817
817
818
if err != nil {
818
819
return fmt .Errorf ("modifying ELBv2 Load Balancer (%s) capacity reservation: %w" , arn , err )
819
820
}
821
+
820
822
return nil
821
823
}
822
824
@@ -1020,11 +1022,11 @@ func findLoadBalancerByARN(ctx context.Context, conn *elasticloadbalancingv2.Cli
1020
1022
}
1021
1023
1022
1024
func findLoadBalancerAttributesByARN (ctx context.Context , conn * elasticloadbalancingv2.Client , arn string ) ([]awstypes.LoadBalancerAttribute , error ) {
1023
- input := & elasticloadbalancingv2.DescribeLoadBalancerAttributesInput {
1025
+ input := elasticloadbalancingv2.DescribeLoadBalancerAttributesInput {
1024
1026
LoadBalancerArn : aws .String (arn ),
1025
1027
}
1026
1028
1027
- output , err := conn .DescribeLoadBalancerAttributes (ctx , input )
1029
+ output , err := conn .DescribeLoadBalancerAttributes (ctx , & input )
1028
1030
1029
1031
if errs.IsA [* awstypes.LoadBalancerNotFoundException ](err ) {
1030
1032
return nil , & retry.NotFoundError {
@@ -1044,12 +1046,12 @@ func findLoadBalancerAttributesByARN(ctx context.Context, conn *elasticloadbalan
1044
1046
return output .Attributes , nil
1045
1047
}
1046
1048
1047
- func findLoadBalancerCapacityByARN (ctx context.Context , conn * elasticloadbalancingv2.Client , arn string ) (* elasticloadbalancingv2.DescribeCapacityReservationOutput , error ) {
1048
- input := & elasticloadbalancingv2.DescribeCapacityReservationInput {
1049
+ func findCapacityReservationByARN (ctx context.Context , conn * elasticloadbalancingv2.Client , arn string ) (* elasticloadbalancingv2.DescribeCapacityReservationOutput , error ) {
1050
+ input := elasticloadbalancingv2.DescribeCapacityReservationInput {
1049
1051
LoadBalancerArn : aws .String (arn ),
1050
1052
}
1051
1053
1052
- output , err := conn .DescribeCapacityReservation (ctx , input )
1054
+ output , err := conn .DescribeCapacityReservation (ctx , & input )
1053
1055
1054
1056
if errs.IsA [* awstypes.LoadBalancerNotFoundException ](err ) {
1055
1057
return nil , & retry.NotFoundError {
@@ -1087,7 +1089,7 @@ func statusLoadBalancer(ctx context.Context, conn *elasticloadbalancingv2.Client
1087
1089
1088
1090
func statusCapacityReservation (ctx context.Context , conn * elasticloadbalancingv2.Client , arn string ) retry.StateRefreshFunc {
1089
1091
return func () (any , string , error ) {
1090
- output , err := findLoadBalancerCapacityByARN (ctx , conn , arn )
1092
+ output , err := findCapacityReservationByARN (ctx , conn , arn )
1091
1093
1092
1094
if tfresource .NotFound (err ) {
1093
1095
return nil , "" , nil
@@ -1194,7 +1196,7 @@ func waitForNLBNetworkInterfacesToDetach(ctx context.Context, conn *ec2.Client,
1194
1196
return err
1195
1197
}
1196
1198
1197
- func waitForModifyCapacityReservationToComplete (ctx context.Context , conn * elasticloadbalancingv2.Client , lbArn string , timeout time.Duration ) error {
1199
+ func waitCapacityReservationProvisioned (ctx context.Context , conn * elasticloadbalancingv2.Client , lbArn string , timeout time.Duration ) ( * elasticloadbalancingv2. DescribeCapacityReservationOutput , error ) {
1198
1200
stateConf := & retry.StateChangeConf {
1199
1201
Pending : enum .Slice (awstypes .CapacityReservationStateEnumPending , awstypes .CapacityReservationStateEnumFailed , awstypes .CapacityReservationStateEnumRebalancing ),
1200
1202
Target : enum .Slice (awstypes .CapacityReservationStateEnumProvisioned ),
@@ -1206,13 +1208,11 @@ func waitForModifyCapacityReservationToComplete(ctx context.Context, conn *elast
1206
1208
1207
1209
outputRaw , err := stateConf .WaitForStateContext (ctx )
1208
1210
1209
- if output , ok := outputRaw .(* awstypes.LoadBalancer ); ok {
1210
- tfresource .SetLastError (err , errors .New (aws .ToString (output .State .Reason )))
1211
-
1212
- return err
1211
+ if output , ok := outputRaw .(* elasticloadbalancingv2.DescribeCapacityReservationOutput ); ok {
1212
+ return output , err
1213
1213
}
1214
1214
1215
- return err
1215
+ return nil , err
1216
1216
}
1217
1217
1218
1218
func loadBalancerNameFromARN (s string ) (string , error ) {
@@ -1603,7 +1603,7 @@ func expandIPAMPools(tfList []any) *awstypes.IpamPools {
1603
1603
return & apiObject
1604
1604
}
1605
1605
1606
- func expandCapacity (tfList []any ) * awstypes.MinimumLoadBalancerCapacity {
1606
+ func expandMinimumLoadBalancerCapacity (tfList []any ) * awstypes.MinimumLoadBalancerCapacity {
1607
1607
if len (tfList ) == 0 {
1608
1608
return nil
1609
1609
}
@@ -1625,25 +1625,25 @@ func expandCapacity(tfList []any) *awstypes.MinimumLoadBalancerCapacity {
1625
1625
return & apiObject
1626
1626
}
1627
1627
1628
- func flattenIPAMPools (ipamPools * awstypes.IpamPools ) []any {
1629
- if ipamPools == nil {
1628
+ func flattenIPAMPools (apiObject * awstypes.IpamPools ) []any {
1629
+ if apiObject == nil {
1630
1630
return nil
1631
1631
}
1632
1632
1633
1633
tfMap := map [string ]any {
1634
- "ipv4_ipam_pool_id" : aws .ToString (ipamPools .Ipv4IpamPoolId ),
1634
+ "ipv4_ipam_pool_id" : aws .ToString (apiObject .Ipv4IpamPoolId ),
1635
1635
}
1636
1636
1637
1637
return []any {tfMap }
1638
1638
}
1639
1639
1640
- func flattenCapacity ( minLoadBalancerCapacity * awstypes.MinimumLoadBalancerCapacity ) []any {
1641
- if minLoadBalancerCapacity == nil {
1640
+ func flattenMinimumLoadBalancerCapacity ( apiObject * awstypes.MinimumLoadBalancerCapacity ) []any {
1641
+ if apiObject == nil {
1642
1642
return nil
1643
1643
}
1644
1644
1645
1645
tfMap := map [string ]any {
1646
- "capacity_units" : aws .ToInt32 (minLoadBalancerCapacity .CapacityUnits ),
1646
+ "capacity_units" : aws .ToInt32 (apiObject .CapacityUnits ),
1647
1647
}
1648
1648
1649
1649
return []any {tfMap }
0 commit comments