Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TechDebt: Migrate apprunner service to aws-sdk-go-v2 #34292

Merged
merged 72 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
6da8b0a
go get github.com/aws/aws-sdk-go-v2/service/apprunner
brittandeyoung Nov 7, 2023
0512115
names: Update apprunner to use aws-sdk-go-v2
brittandeyoung Nov 7, 2023
bc95884
conns: generate new apprunner aws-sdk-go-v2 client
brittandeyoung Nov 7, 2023
e77f62d
apprunner: Amend generate, update tags gen to sdk-v2
brittandeyoung Nov 7, 2023
0f6687c
apprunner: re-generate tags_gen with sdk-v2
brittandeyoung Nov 7, 2023
97539d4
apprunner: Amend auto_scaling_configuration_version, migrate to aws-…
brittandeyoung Nov 7, 2023
88cbfce
apprunner: Amend auto_scaling_configuration_version_test, migrate to …
brittandeyoung Nov 7, 2023
7d3f05f
apprunner: Amend connection, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
7ad4389
apprunner: Amend connection_test, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
b7e3596
apprunner: Amend custom_domain_association, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
1db1305
apprunner: Amend custom_domain_association_test, migrate to aws-sdk-g…
brittandeyoung Nov 7, 2023
27f8f3c
apprunner: Amend find, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
ed88d0b
apprunner: Amend observability_configuration, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
a54966d
apprunner: Amend observability_configuration_version_test, migrate to…
brittandeyoung Nov 7, 2023
f981c6d
apprunner: Amend service, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
030f895
apprunner: Amend service_package_gen, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
88074a6
apprunner: Amend service_test, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
f68da77
apprunner: Amend status, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
ebd1ab1
apprunner: Amend sweep, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
f0857dc
apprunner: Amend vpc_connector, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
a2d8abe
apprunner: Amend vpc_connector_test, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
c7f8475
apprunner: Amend vpc_ingress_connection, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
68bb073
apprunner: Amend vpc_ingress_connection_test, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
390101e
apprunner: Amend wait, migrate to aws-sdk-go-v2
brittandeyoung Nov 7, 2023
d86229d
apprunner: Amend find, golangci-lint
brittandeyoung Nov 7, 2023
aad4c92
apprunner: Amend auto_scaling_configuration_version, use correct int …
brittandeyoung Nov 7, 2023
731a36e
Merge branch 'main' into HEAD
ewbankkit Nov 19, 2023
2bafaaf
Add 'names.AppRunnerEndpointID'.
ewbankkit Nov 19, 2023
b5e2a72
Use github.com/aws/aws-sdk-go-v2/service/apprunner@v1.24.1
ewbankkit Nov 19, 2023
db1b290
r/aws_apprunner_auto_scaling_configuration_version: Tidy up.
ewbankkit Nov 19, 2023
bda6790
Acceptance test output:
ewbankkit Nov 19, 2023
c6a24b1
Add 'tfslices.ToPointers'.
ewbankkit Nov 20, 2023
ca511d2
r/aws_apprunner_connection: Tidy up.
ewbankkit Nov 20, 2023
2d79203
r/aws_apprunner_connection: Tidy up acceptance tests.
ewbankkit Nov 20, 2023
46aef3a
Acceptance test output:
ewbankkit Nov 20, 2023
c41fc26
r/aws_apprunner_custom_domain_association: Tidy up.
ewbankkit Nov 20, 2023
ae0940f
r/aws_apprunner_custom_domain_association: Tidy up acceptance tests.
ewbankkit Nov 20, 2023
a0e296a
Acceptance test output:
ewbankkit Nov 20, 2023
aa093e2
Correct source file name.
ewbankkit Nov 20, 2023
a351bc4
r/aws_apprunner_observability_configuration: Tidy up.
ewbankkit Nov 20, 2023
2fadefb
r/aws_apprunner_observability_configuration: Tidy up acceptance tests.
ewbankkit Nov 20, 2023
b86e5d7
Fix typo.
ewbankkit Nov 20, 2023
4b78c01
Acceptance test output:
ewbankkit Nov 20, 2023
3174f5e
r/aws_apprunner_vpc_ingress_connection: Tidy up.
ewbankkit Nov 20, 2023
76cde79
r/aws_apprunner_vpc_ingress_connection: Tidy up acceptance tests.
ewbankkit Nov 20, 2023
50193cc
Acceptance test output:
ewbankkit Nov 20, 2023
7165109
r/aws_apprunner_vpc_connector: Tidy up.
ewbankkit Nov 20, 2023
7a67b90
Acceptance test output:
ewbankkit Nov 20, 2023
4d589a6
r/aws_apprunner_service: Tidy up.
ewbankkit Nov 21, 2023
864067a
r/aws_apprunner_service: Tidy up acceptance tests.
ewbankkit Nov 21, 2023
6021f48
Acceptance test output:
ewbankkit Nov 21, 2023
f5dd6c4
apprunner: Tidy up sweepers.
ewbankkit Nov 21, 2023
44580c4
Merge branch 'main' into HEAD
ewbankkit Nov 21, 2023
663e910
r/aws_apprunner_service: Add `network_configuration.ip_address_type` …
ewbankkit Nov 21, 2023
baf3f0c
Acceptance test output:
ewbankkit Nov 21, 2023
3697706
r/aws_apprunner_service: Add `source_configuration.code_repository.so…
ewbankkit Nov 21, 2023
7f55082
r/aws_apprunner_service: Allow `health_check_configuration` to be upd…
ewbankkit Nov 21, 2023
8de1ddb
Acceptance test output:
ewbankkit Nov 21, 2023
2cf7c6f
r/aws_apprunner_service: Use 'ListServices' to find 'service_url' for…
ewbankkit Nov 21, 2023
1d6c57b
r/aws_apprunner_service: Find 'service_url' via custom domains for pr…
ewbankkit Nov 21, 2023
370a584
Acceptance test output:
ewbankkit Nov 21, 2023
6b93aa9
Add CHANGELOG entry.
ewbankkit Nov 21, 2023
b304c73
r/aws_apprunner_service: Change `observability_configuration` to Forc…
ewbankkit Nov 21, 2023
76b7cbc
Revert "r/aws_apprunner_service: Change `observability_configuration`…
ewbankkit Nov 21, 2023
eb33475
r/aws_apprunner_auto_scaling_configuration_version: Add `is_default` …
ewbankkit Nov 22, 2023
1f1c8ea
r/aws_apprunner_auto_scaling_configuration_version: 'is_default' is r…
ewbankkit Nov 22, 2023
bc742e5
Acceptance test output:
ewbankkit Nov 22, 2023
95a6877
r/aws_apprunner_default_auto_scaling_configuration_version: New resou…
ewbankkit Nov 22, 2023
15e1f5d
r/aws_apprunner_default_auto_scaling_configuration_version: Documenta…
ewbankkit Nov 22, 2023
9ba102b
r/aws_apprunner_default_auto_scaling_configuration_version: Acceptanc…
ewbankkit Nov 22, 2023
16b2109
Acceptance test output:
ewbankkit Nov 22, 2023
d38d837
Fix terrafmt error with acceptance test configuration.
ewbankkit Nov 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changelog/34292.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```release-note:enhancement
resource/aws_apprunner_service: Add `network_configuration.ip_address_type` argument
```

```release-note:enhancement
resource/aws_apprunner_service: Add `source_configuration.code_repository.source_directory` argument to support monorepos
```

```release-note:enhancement
resource/aws_apprunner_service: Allow `health_check_configuration` to be updated in-place
```

```release-note:bug
resource/aws_apprunner_service: Correctly set `service_url` for private services
```

```release-note:enhancement
resource/aws_apprunner_auto_scaling_configuration_version: Add `has_associated_service` and `is_default` attributes
```

```release-note:new-resource
aws_apprunner_default_auto_scaling_configuration_version
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/acm v1.21.3
github.com/aws/aws-sdk-go-v2/service/appconfig v1.25.3
github.com/aws/aws-sdk-go-v2/service/appflow v1.38.3
github.com/aws/aws-sdk-go-v2/service/apprunner v1.24.4
github.com/aws/aws-sdk-go-v2/service/athena v1.35.1
github.com/aws/aws-sdk-go-v2/service/auditmanager v1.29.3
github.com/aws/aws-sdk-go-v2/service/bedrock v1.3.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/aws/aws-sdk-go-v2/service/appconfig v1.25.3 h1:68bxzI7wWa1nJT+N7AR/r0
github.com/aws/aws-sdk-go-v2/service/appconfig v1.25.3/go.mod h1:YO0HH+oQubpBQiAC4fWja3B43K4YTHznuaXEGe0rauY=
github.com/aws/aws-sdk-go-v2/service/appflow v1.38.3 h1:hoz+OCM2E0y4SXllN2IFgCTOH+0VPYym2Iqxk/ttuw4=
github.com/aws/aws-sdk-go-v2/service/appflow v1.38.3/go.mod h1:9X+vMl265vQZozYKOXdqsvY5ZaiL9T3KPQLOkFBYFLc=
github.com/aws/aws-sdk-go-v2/service/apprunner v1.24.4 h1:PgmMPDrOO5uIngULC2A+P0BUJssu/rZ1e2UzAS++Zs4=
github.com/aws/aws-sdk-go-v2/service/apprunner v1.24.4/go.mod h1:ecWPZOErcCqw4mHgt4W3tSFTEH6vGV4IV6qNKmY/BMQ=
github.com/aws/aws-sdk-go-v2/service/athena v1.35.1 h1:oOucUl/I9XOnIb+L9ZBY2gyQmPk389qRGmuam72EWtI=
github.com/aws/aws-sdk-go-v2/service/athena v1.35.1/go.mod h1:CAh4Navj8gOz4Y12wWUleeqY5fKkAaT80ZWo23Uz+YI=
github.com/aws/aws-sdk-go-v2/service/auditmanager v1.29.3 h1:VfmZ6+gp3Vifn0PDazz49Vll/OcQofnS85nBUrXg2Ak=
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.

214 changes: 163 additions & 51 deletions internal/service/apprunner/auto_scaling_configuration_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ package apprunner
import (
"context"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apprunner"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/apprunner"
"github.com/aws/aws-sdk-go-v2/service/apprunner/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_apprunner_auto_scaling_configuration_version", name="AutoScaling Configuration Version")
// @Tags(identifierAttribute="arn")
func ResourceAutoScalingConfigurationVersion() *schema.Resource {
func resourceAutoScalingConfigurationVersion() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAutoScalingConfigurationCreate,
ReadWithoutTimeout: resourceAutoScalingConfigurationRead,
Expand All @@ -46,6 +51,14 @@ func ResourceAutoScalingConfigurationVersion() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"has_associated_service": {
Type: schema.TypeBool,
Computed: true,
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
},
"latest": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -84,7 +97,7 @@ func ResourceAutoScalingConfigurationVersion() *schema.Resource {
}

func resourceAutoScalingConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppRunnerConn(ctx)
conn := meta.(*conns.AWSClient).AppRunnerClient(ctx)

name := d.Get("auto_scaling_configuration_name").(string)
input := &apprunner.CreateAutoScalingConfigurationInput{
Expand All @@ -93,46 +106,38 @@ func resourceAutoScalingConfigurationCreate(ctx context.Context, d *schema.Resou
}

if v, ok := d.GetOk("max_concurrency"); ok {
input.MaxConcurrency = aws.Int64(int64(v.(int)))
input.MaxConcurrency = aws.Int32(int32(v.(int)))
}

if v, ok := d.GetOk("max_size"); ok {
input.MaxSize = aws.Int64(int64(v.(int)))
input.MaxSize = aws.Int32(int32(v.(int)))
}

if v, ok := d.GetOk("min_size"); ok {
input.MinSize = aws.Int64(int64(v.(int)))
input.MinSize = aws.Int32(int32(v.(int)))
}

output, err := conn.CreateAutoScalingConfigurationWithContext(ctx, input)
output, err := conn.CreateAutoScalingConfiguration(ctx, input)

if err != nil {
return diag.Errorf("creating App Runner AutoScaling Configuration Version (%s): %s", name, err)
}

if output == nil || output.AutoScalingConfiguration == nil {
return diag.Errorf("creating App Runner AutoScaling Configuration Version (%s): empty output", name)
}

d.SetId(aws.StringValue(output.AutoScalingConfiguration.AutoScalingConfigurationArn))
d.SetId(aws.ToString(output.AutoScalingConfiguration.AutoScalingConfigurationArn))

if err := WaitAutoScalingConfigurationActive(ctx, conn, d.Id()); err != nil {
return diag.Errorf("waiting for AutoScaling Configuration Version (%s) creation: %s", d.Id(), err)
if _, err := waitAutoScalingConfigurationCreated(ctx, conn, d.Id()); err != nil {
return diag.Errorf("waiting for AutoScaling Configuration Version (%s) create: %s", d.Id(), err)
}

return resourceAutoScalingConfigurationRead(ctx, d, meta)
}

func resourceAutoScalingConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppRunnerConn(ctx)
conn := meta.(*conns.AWSClient).AppRunnerClient(ctx)

input := &apprunner.DescribeAutoScalingConfigurationInput{
AutoScalingConfigurationArn: aws.String(d.Id()),
}

output, err := conn.DescribeAutoScalingConfigurationWithContext(ctx, input)
config, err := findAutoScalingConfigurationByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apprunner.ErrCodeResourceNotFoundException) {
if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] App Runner AutoScaling Configuration Version (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
Expand All @@ -142,25 +147,11 @@ func resourceAutoScalingConfigurationRead(ctx context.Context, d *schema.Resourc
return diag.Errorf("reading App Runner AutoScaling Configuration Version (%s): %s", d.Id(), err)
}

if output == nil || output.AutoScalingConfiguration == nil {
return diag.Errorf("reading App Runner AutoScaling Configuration Version (%s): empty output", d.Id())
}

if aws.StringValue(output.AutoScalingConfiguration.Status) == AutoScalingConfigurationStatusInactive {
if d.IsNewResource() {
return diag.Errorf("reading App Runner AutoScaling Configuration Version (%s): %s after creation", d.Id(), aws.StringValue(output.AutoScalingConfiguration.Status))
}
log.Printf("[WARN] App Runner AutoScaling Configuration Version (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}

config := output.AutoScalingConfiguration
arn := aws.StringValue(config.AutoScalingConfigurationArn)

d.Set("arn", arn)
d.Set("arn", config.AutoScalingConfigurationArn)
d.Set("auto_scaling_configuration_name", config.AutoScalingConfigurationName)
d.Set("auto_scaling_configuration_revision", config.AutoScalingConfigurationRevision)
d.Set("has_associated_service", config.HasAssociatedService)
d.Set("is_default", config.IsDefault)
d.Set("latest", config.Latest)
d.Set("max_concurrency", config.MaxConcurrency)
d.Set("max_size", config.MaxSize)
Expand All @@ -176,28 +167,149 @@ func resourceAutoScalingConfigurationUpdate(ctx context.Context, d *schema.Resou
}

func resourceAutoScalingConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).AppRunnerConn(ctx)
conn := meta.(*conns.AWSClient).AppRunnerClient(ctx)

input := &apprunner.DeleteAutoScalingConfigurationInput{
log.Printf("[INFO] Deleting App Runner AutoScaling Configuration Version: %s", d.Id())
_, err := conn.DeleteAutoScalingConfiguration(ctx, &apprunner.DeleteAutoScalingConfigurationInput{
AutoScalingConfigurationArn: aws.String(d.Id()),
}
})

_, err := conn.DeleteAutoScalingConfigurationWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, apprunner.ErrCodeResourceNotFoundException) {
if errs.IsA[*types.ResourceNotFoundException](err) {
return nil
}

if err != nil {
return diag.Errorf("deleting App Runner AutoScaling Configuration Version (%s): %s", d.Id(), err)
}

if err := WaitAutoScalingConfigurationInactive(ctx, conn, d.Id()); err != nil {
if tfawserr.ErrCodeEquals(err, apprunner.ErrCodeResourceNotFoundException) {
return nil
}
return diag.Errorf("waiting for AutoScaling Configuration Version (%s) deletion: %s", d.Id(), err)
if _, err := waitAutoScalingConfigurationDeleted(ctx, conn, d.Id()); err != nil {
return diag.Errorf("waiting for AutoScaling Configuration Version (%s) delete: %s", d.Id(), err)
}

return nil
}

func findAutoScalingConfigurationByARN(ctx context.Context, conn *apprunner.Client, arn string) (*types.AutoScalingConfiguration, error) {
input := &apprunner.DescribeAutoScalingConfigurationInput{
AutoScalingConfigurationArn: aws.String(arn),
}

output, err := conn.DescribeAutoScalingConfiguration(ctx, input)

if errs.IsA[*types.ResourceNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.AutoScalingConfiguration == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if status := string(output.AutoScalingConfiguration.Status); status == autoScalingConfigurationStatusInactive {
return nil, &retry.NotFoundError{
Message: status,
LastRequest: input,
}
}

return output.AutoScalingConfiguration, nil
}

func findAutoScalingConfigurationSummary(ctx context.Context, conn *apprunner.Client, input *apprunner.ListAutoScalingConfigurationsInput, filter tfslices.Predicate[*types.AutoScalingConfigurationSummary]) (*types.AutoScalingConfigurationSummary, error) {
output, err := findAutoScalingConfigurationSummaries(ctx, conn, input, filter)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output)
}

func findAutoScalingConfigurationSummaries(ctx context.Context, conn *apprunner.Client, input *apprunner.ListAutoScalingConfigurationsInput, filter tfslices.Predicate[*types.AutoScalingConfigurationSummary]) ([]*types.AutoScalingConfigurationSummary, error) {
var output []*types.AutoScalingConfigurationSummary

pages := apprunner.NewListAutoScalingConfigurationsPaginator(conn, input)
for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

if err != nil {
return nil, err
}

for _, v := range page.AutoScalingConfigurationSummaryList {
v := v
if v := &v; filter(v) {
output = append(output, v)
}
}
}

return output, nil
}

const (
autoScalingConfigurationStatusActive = "active"
autoScalingConfigurationStatusInactive = "inactive"
)

func statusAutoScalingConfiguration(ctx context.Context, conn *apprunner.Client, arn string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := findAutoScalingConfigurationByARN(ctx, conn, arn)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return output, string(output.Status), nil
}
}

func waitAutoScalingConfigurationCreated(ctx context.Context, conn *apprunner.Client, arn string) (*types.AutoScalingConfiguration, error) {
const (
timeout = 2 * time.Minute
)
stateConf := &retry.StateChangeConf{
Pending: []string{},
Target: []string{autoScalingConfigurationStatusActive},
Refresh: statusAutoScalingConfiguration(ctx, conn, arn),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*types.AutoScalingConfiguration); ok {
return output, err
}

return nil, err
}

func waitAutoScalingConfigurationDeleted(ctx context.Context, conn *apprunner.Client, arn string) (*types.AutoScalingConfiguration, error) {
const (
timeout = 2 * time.Minute
)
stateConf := &retry.StateChangeConf{
Pending: []string{autoScalingConfigurationStatusActive},
Target: []string{},
Refresh: statusAutoScalingConfiguration(ctx, conn, arn),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*types.AutoScalingConfiguration); ok {
return output, err
}

return nil, err
}
Loading
Loading