Skip to content

Commit

Permalink
Merge pull request #38212 from mattburgess/elb-awssdkv2-migration
Browse files Browse the repository at this point in the history
Elb awssdkv2 migration
  • Loading branch information
ewbankkit committed Jul 10, 2024
2 parents 28e7f1b + 52b6e6f commit 957c491
Show file tree
Hide file tree
Showing 56 changed files with 1,668 additions and 1,901 deletions.
3 changes: 3 additions & 0 deletions .changelog/38212.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_iam_server_certificate: Add configurable `delete` timeout
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/eks v1.46.0
github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1
github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1
github.com/aws/aws-sdk-go-v2/service/emr v1.42.0
github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1 h1:yJMmaQ3jTpCrsXl0lxQU
github.com/aws/aws-sdk-go-v2/service/elasticache v1.40.1/go.mod h1:HfavnpYheVa3TXRxHNZYIM/BMI8hmSbtiSbYxqdri/4=
github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0 h1:HKN6OvyM2N4mCME+1MgkBemV1Mle3VSuag4Q5+jaPM0=
github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.0/go.mod h1:H8YbT18eu4O03RiBqdDderRdpnHe2Pv439zdO5mmbfU=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1 h1:/x4d5NeeoKJAhyZ5zHnBOaxOSotobVb9mXeprdl363I=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.1/go.mod h1:Dm9KFhagyV3Ecne6tpYIXWh51N/Q288vpm+0u3P/gbo=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1 h1:XuwjSEGfLxo6UJtpJVy/E80GpE1gNclDBv5k1nTQcCs=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.1/go.mod h1:74D8OQ00uEvvpuG5e4VX+/2v3MC2pltRtzNyXJnEjrI=
github.com/aws/aws-sdk-go-v2/service/emr v1.42.0 h1:n3e3/X7ixZrQja0ot3l6M19nw8EarUo1yR0rH4e8aec=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,16 @@ func IntValueToString(v int) *string {
return aws.String(strconv.Itoa(v))
}

// Int64ToStringValue converts an int64 pointer to a Go string value.
// Int32ToStringValue converts an int32 pointer to a Go string value.
func Int32ToStringValue(v *int32) string {
return strconv.FormatInt(int64(aws.Int32Value(v)), 10)
}

// Int32ValueToStringValue converts an int32 value to a Go string value.
func Int32ValueToStringValue(v int32) string {
return strconv.FormatInt(int64(v), 10)
}

// Int64ToStringValue converts an int64 pointer to a Go string value.
func Int64ToStringValue(v *int64) string {
return strconv.FormatInt(aws.Int64Value(v), 10)
Expand All @@ -450,15 +455,27 @@ func StringToIntValue(v *string) int {
// StringToInt32Value converts a string pointer to a Go int32 value.
// Invalid integer strings are converted to 0.
func StringToInt32Value(v *string) int32 {
i, _ := strconv.ParseInt(aws.StringValue(v), 0, 32)
return int32(i)
return StringValueToInt32Value(aws.StringValue(v))
}

// StringValueToBase64String converts a string to a Go base64 string pointer.
func StringValueToBase64String(v string) *string {
return aws.String(itypes.Base64EncodeOnce([]byte(v)))
}

// StringValueToInt64 converts a string to a Go int32 pointer.
// Invalid integer strings are converted to 0.
func StringValueToInt32(v string) *int32 {
return aws.Int32(StringValueToInt32Value(v))
}

// StringValueToInt32Value converts a string to a Go int32 value.
// Invalid integer strings are converted to 0.
func StringValueToInt32Value(v string) int32 {
i, _ := strconv.ParseInt(v, 0, 32)
return int32(i)
}

// StringValueToInt64 converts a string to a Go int64 pointer.
// Invalid integer strings are converted to 0.
func StringValueToInt64(v string) *int64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func listOfMap(tags tftags.KeyValueTags) []any {

{{- if .TagKeyType }}
// TagKeys returns {{ .ServicePackage }} service tag keys.
func TagKeys(tags tftags.KeyValueTags) []*{{ .AWSService }}.{{ .TagKeyType }} {
result := make([]*{{ .AWSService }}.{{ .TagKeyType }}, 0, len(tags))
func TagKeys(tags tftags.KeyValueTags) []awstypes.{{ .TagKeyType }} {
result := make([]awstypes.{{ .TagKeyType }}, 0, len(tags))

for k := range tags.Map() {
tagKey := &{{ .AWSService }}.{{ .TagKeyType }}{
tagKey := awstypes.{{ .TagKeyType }}{
{{ .TagTypeKeyElem }}: aws.String(k),
}

Expand Down
4 changes: 4 additions & 0 deletions internal/service/autoscaling/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ func (lifecycleHookLifecycleTransition) Values() []lifecycleHookLifecycleTransit
lifecycleHookLifecycleTransitionInstanceTerminating,
}
}

const (
elbInstanceStateInService = "InService"
)
19 changes: 9 additions & 10 deletions internal/service/autoscaling/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
awstypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
"github.com/hashicorp/go-cty/cty"
Expand All @@ -33,7 +33,6 @@ import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2/types/nullable"
tfelb "github.com/hashicorp/terraform-provider-aws/internal/service/elb"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -1211,7 +1210,7 @@ func resourceGroupCreate(ctx context.Context, d *schema.ResourceData, meta inter
return nil
}

if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBConn(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil {
if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBClient(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Auto Scaling Group (%s) capacity satisfied: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -1708,7 +1707,7 @@ func resourceGroupUpdate(ctx context.Context, d *schema.ResourceData, meta inter
return nil
}

if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBConn(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil {
if err := waitGroupCapacitySatisfied(ctx, conn, meta.(*conns.AWSClient).ELBClient(ctx), meta.(*conns.AWSClient).ELBV2Conn(ctx), d.Id(), f, startTime, d.Get("ignore_failed_scaling_activities").(bool), timeout); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Auto Scaling Group (%s) capacity satisfied: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -1965,16 +1964,16 @@ func drainWarmPool(ctx context.Context, conn *autoscaling.Client, name string, t
return nil
}

func findELBInstanceStates(ctx context.Context, conn *elb.ELB, g *awstypes.AutoScalingGroup) (map[string]map[string]string, error) {
func findELBInstanceStates(ctx context.Context, conn *elasticloadbalancing.Client, g *awstypes.AutoScalingGroup) (map[string]map[string]string, error) {
instanceStates := make(map[string]map[string]string)

for _, v := range g.LoadBalancerNames {
lbName := v
input := &elb.DescribeInstanceHealthInput{
input := &elasticloadbalancing.DescribeInstanceHealthInput{
LoadBalancerName: aws.String(lbName),
}

output, err := conn.DescribeInstanceHealthWithContext(ctx, input)
output, err := conn.DescribeInstanceHealth(ctx, input)

if err != nil {
return nil, fmt.Errorf("reading load balancer (%s) instance health: %w", lbName, err)
Expand Down Expand Up @@ -2284,7 +2283,7 @@ func findWarmPoolByName(ctx context.Context, conn *autoscaling.Client, name stri
return findWarmPool(ctx, conn, input)
}

func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn *elb.ELB, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool) retry.StateRefreshFunc {
func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn *elasticloadbalancing.Client, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
if !ignoreFailedScalingActivities {
// Check for fatal error in activity logs.
Expand Down Expand Up @@ -2359,7 +2358,7 @@ func statusGroupCapacity(ctx context.Context, conn *autoscaling.Client, elbconn
inAll := true

for _, v := range lbInstanceStates {
if state, ok := v[instanceID]; ok && state != tfelb.InstanceStateInService {
if state, ok := v[instanceID]; ok && state != elbInstanceStateInService {
inAll = false
break
}
Expand Down Expand Up @@ -2539,7 +2538,7 @@ func statusWarmPoolInstanceCount(ctx context.Context, conn *autoscaling.Client,
}
}

func waitGroupCapacitySatisfied(ctx context.Context, conn *autoscaling.Client, elbconn *elb.ELB, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool, timeout time.Duration) error {
func waitGroupCapacitySatisfied(ctx context.Context, conn *autoscaling.Client, elbconn *elasticloadbalancing.Client, elbv2conn *elbv2.ELBV2, name string, cb func(int, int) error, startTime time.Time, ignoreFailedScalingActivities bool, timeout time.Duration) error {
stateConf := &retry.StateChangeConf{
Target: []string{"ok"},
Refresh: statusGroupCapacity(ctx, conn, elbconn, elbv2conn, name, cb, startTime, ignoreFailedScalingActivities),
Expand Down
Loading

0 comments on commit 957c491

Please sign in to comment.