diff --git a/internal/service/appstream/directory_config.go b/internal/service/appstream/directory_config.go index b331d52ad7e..52d5c957e19 100644 --- a/internal/service/appstream/directory_config.go +++ b/internal/service/appstream/directory_config.go @@ -151,16 +151,19 @@ func resourceDirectoryConfigUpdate(ctx context.Context, d *schema.ResourceData, func resourceDirectoryConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).AppStreamConn + log.Printf("[DEBUG] Deleting AppStream Directory Config: (%s)", d.Id()) _, err := conn.DeleteDirectoryConfigWithContext(ctx, &appstream.DeleteDirectoryConfigInput{ DirectoryName: aws.String(d.Id()), }) + if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { + return nil + } + if err != nil { - if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { - return nil - } return diag.FromErr(fmt.Errorf("error deleting AppStream Directory Config (%s): %w", d.Id(), err)) } + return nil } diff --git a/internal/service/appstream/fleet.go b/internal/service/appstream/fleet.go index 2e5b3f7f0a3..6dfeef13cae 100644 --- a/internal/service/appstream/fleet.go +++ b/internal/service/appstream/fleet.go @@ -275,20 +275,20 @@ func resourceFleetCreate(ctx context.Context, d *schema.ResourceData, meta inter return diag.FromErr(fmt.Errorf("error creating Appstream Fleet (%s): %w", d.Id(), err)) } + d.SetId(aws.StringValue(output.Fleet.Name)) + // Start fleet workflow _, err = conn.StartFleetWithContext(ctx, &appstream.StartFleetInput{ - Name: output.Fleet.Name, + Name: aws.String(d.Id()), }) if err != nil { return diag.FromErr(fmt.Errorf("error starting Appstream Fleet (%s): %w", d.Id(), err)) } - if _, err = waitFleetStateRunning(ctx, conn, aws.StringValue(output.Fleet.Name)); err != nil { + if _, err = waitFleetStateRunning(ctx, conn, d.Id()); err != nil { return diag.FromErr(fmt.Errorf("error waiting for Appstream Fleet (%s) to be running: %w", d.Id(), err)) } - d.SetId(aws.StringValue(output.Fleet.Name)) - return resourceFleetRead(ctx, d, meta) } @@ -492,6 +492,7 @@ func resourceFleetDelete(ctx context.Context, d *schema.ResourceData, meta inter conn := meta.(*conns.AWSClient).AppStreamConn // Stop fleet workflow + log.Printf("[DEBUG] Stopping AppStream Fleet: (%s)", d.Id()) _, err := conn.StopFleetWithContext(ctx, &appstream.StopFleetInput{ Name: aws.String(d.Id()), }) @@ -503,16 +504,19 @@ func resourceFleetDelete(ctx context.Context, d *schema.ResourceData, meta inter return diag.FromErr(fmt.Errorf("error waiting for Appstream Fleet (%s) to be stopped: %w", d.Id(), err)) } + log.Printf("[DEBUG] Deleting AppStream Fleet: (%s)", d.Id()) _, err = conn.DeleteFleetWithContext(ctx, &appstream.DeleteFleetInput{ Name: aws.String(d.Id()), }) + if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { + return nil + } + if err != nil { - if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { - return nil - } return diag.FromErr(fmt.Errorf("error deleting Appstream Fleet (%s): %w", d.Id(), err)) } + return nil } diff --git a/internal/service/appstream/image_builder.go b/internal/service/appstream/image_builder.go index 04704d2ce16..172363b711f 100644 --- a/internal/service/appstream/image_builder.go +++ b/internal/service/appstream/image_builder.go @@ -324,6 +324,7 @@ func resourceImageBuilderUpdate(ctx context.Context, d *schema.ResourceData, met func resourceImageBuilderDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).AppStreamConn + log.Printf("[DEBUG] Deleting AppStream Image Builder: (%s)", d.Id()) _, err := conn.DeleteImageBuilderWithContext(ctx, &appstream.DeleteImageBuilderInput{ Name: aws.String(d.Id()), }) diff --git a/internal/service/appstream/stack.go b/internal/service/appstream/stack.go index 60ddc4ca68e..e3b0a75f338 100644 --- a/internal/service/appstream/stack.go +++ b/internal/service/appstream/stack.go @@ -379,13 +379,16 @@ func resourceStackUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceStackDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).AppStreamConn + log.Printf("[DEBUG] Deleting AppStream Stack: (%s)", d.Id()) _, err := conn.DeleteStackWithContext(ctx, &appstream.DeleteStackInput{ Name: aws.String(d.Id()), }) + + if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { + return nil + } + if err != nil { - if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) { - return nil - } return diag.FromErr(fmt.Errorf("error deleting Appstream Stack (%s): %w", d.Id(), err)) } diff --git a/internal/service/appstream/sweep.go b/internal/service/appstream/sweep.go index fca67960766..8dfb63aead0 100644 --- a/internal/service/appstream/sweep.go +++ b/internal/service/appstream/sweep.go @@ -4,13 +4,11 @@ package appstream import ( - "context" "fmt" "log" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/appstream" - "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/sweep" @@ -40,32 +38,22 @@ func init() { func sweepDirectoryConfigs(region string) error { client, err := sweep.SharedRegionalSweepClient(region) - if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.(*conns.AWSClient).AppStreamConn - sweepResources := make([]*sweep.SweepResource, 0) - var errs *multierror.Error - input := &appstream.DescribeDirectoryConfigsInput{} + sweepResources := make([]*sweep.SweepResource, 0) - err = describeDirectoryConfigsPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeDirectoryConfigsOutput, lastPage bool) bool { + err = describeDirectoryConfigsPages(conn, input, func(page *appstream.DescribeDirectoryConfigsOutput, lastPage bool) bool { if page == nil { return !lastPage } - for _, directoryConfig := range page.DirectoryConfigs { - if directoryConfig == nil { - continue - } - - id := aws.StringValue(directoryConfig.DirectoryName) - + for _, v := range page.DirectoryConfigs { r := ResourceDirectoryConfig() d := r.Data(nil) - d.SetId(id) + d.SetId(aws.StringValue(v.DirectoryName)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -74,54 +62,41 @@ func sweepDirectoryConfigs(region string) error { }) if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping Appstream Directory Config sweep for %s: %s", region, err) + log.Printf("[WARN] Skipping AppStream Directory Config sweep for %s: %s", region, err) return nil } if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing AppStream Directory Configs: %w", err)) + return fmt.Errorf("error listing AppStream Directory Configs (%s): %w", region, err) } - if err = sweep.SweepOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping AppStream Directory Configs for %s: %w", region, err)) - } + err = sweep.SweepOrchestrator(sweepResources) - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping AppStream Directory Config sweep for %s: %s", region, err) - return nil // In case we have completed some pages, but had errors + if err != nil { + return fmt.Errorf("error sweeping AppStream Directory Configs (%s): %w", region, err) } - return errs.ErrorOrNil() + return nil } func sweepFleets(region string) error { client, err := sweep.SharedRegionalSweepClient(region) - if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.(*conns.AWSClient).AppStreamConn - sweepResources := make([]*sweep.SweepResource, 0) - var errs *multierror.Error - input := &appstream.DescribeFleetsInput{} + sweepResources := make([]*sweep.SweepResource, 0) - err = describeFleetsPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeFleetsOutput, lastPage bool) bool { + err = describeFleetsPages(conn, input, func(page *appstream.DescribeFleetsOutput, lastPage bool) bool { if page == nil { return !lastPage } - for _, fleet := range page.Fleets { - if fleet == nil { - continue - } - - id := aws.StringValue(fleet.Name) - - r := ResourceImageBuilder() + for _, v := range page.Fleets { + r := ResourceFleet() d := r.Data(nil) - d.SetId(id) + d.SetId(aws.StringValue(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -130,24 +105,21 @@ func sweepFleets(region string) error { }) if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping Appstream Fleets sweep for %s: %s", region, err) + log.Printf("[WARN] Skipping AppStream Fleet sweep for %s: %s", region, err) return nil } if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing AppStream Fleets: %w", err)) + return fmt.Errorf("error listing AppStream Fleets (%s): %w", region, err) } - if err = sweep.SweepOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping AppStream Fleets for %s: %w", region, err)) - } + err = sweep.SweepOrchestrator(sweepResources) - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping AppStream Fleets sweep for %s: %s", region, err) - return nil // In case we have completed some pages, but had errors + if err != nil { + return fmt.Errorf("error sweeping AppStream Fleets (%s): %w", region, err) } - return errs.ErrorOrNil() + return nil } func sweepImageBuilders(region string) error { @@ -155,28 +127,19 @@ func sweepImageBuilders(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.(*conns.AWSClient).AppStreamConn - sweepResources := make([]*sweep.SweepResource, 0) - var errs *multierror.Error - input := &appstream.DescribeImageBuildersInput{} + sweepResources := make([]*sweep.SweepResource, 0) - err = describeImageBuildersPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool { + err = describeImageBuildersPages(conn, input, func(page *appstream.DescribeImageBuildersOutput, lastPage bool) bool { if page == nil { return !lastPage } - for _, imageBuilder := range page.ImageBuilders { - if imageBuilder == nil { - continue - } - - id := aws.StringValue(imageBuilder.Name) - + for _, v := range page.ImageBuilders { r := ResourceImageBuilder() d := r.Data(nil) - d.SetId(id) + d.SetId(aws.StringValue(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -185,54 +148,41 @@ func sweepImageBuilders(region string) error { }) if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping Appstream Image Builders sweep for %s: %s", region, err) + log.Printf("[WARN] Skipping AppStream Image Builder sweep for %s: %s", region, err) return nil } if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing AppStream Image Builders: %w", err)) + return fmt.Errorf("error listing AppStream Image Builders (%s): %w", region, err) } - if err = sweep.SweepOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping AppStream Image Builders for %s: %w", region, err)) - } + err = sweep.SweepOrchestrator(sweepResources) - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping AppStream Image Builders sweep for %s: %s", region, err) - return nil // In case we have completed some pages, but had errors + if err != nil { + return fmt.Errorf("error sweeping AppStream Image Builders (%s): %w", region, err) } - return errs.ErrorOrNil() + return nil } func sweepStacks(region string) error { client, err := sweep.SharedRegionalSweepClient(region) - if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.(*conns.AWSClient).AppStreamConn - sweepResources := make([]*sweep.SweepResource, 0) - var errs *multierror.Error - input := &appstream.DescribeStacksInput{} + sweepResources := make([]*sweep.SweepResource, 0) - err = describeStacksPagesWithContext(context.TODO(), conn, input, func(page *appstream.DescribeStacksOutput, lastPage bool) bool { + err = describeStacksPages(conn, input, func(page *appstream.DescribeStacksOutput, lastPage bool) bool { if page == nil { return !lastPage } - for _, stack := range page.Stacks { - if stack == nil { - continue - } - - id := aws.StringValue(stack.Name) - - r := ResourceImageBuilder() + for _, v := range page.Stacks { + r := ResourceStack() d := r.Data(nil) - d.SetId(id) + d.SetId(aws.StringValue(v.Name)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -241,22 +191,19 @@ func sweepStacks(region string) error { }) if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping Appstream Stacks sweep for %s: %s", region, err) + log.Printf("[WARN] Skipping AppStream Stack sweep for %s: %s", region, err) return nil } if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error listing AppStream Stacks: %w", err)) + return fmt.Errorf("error listing AppStream Stacks (%s): %w", region, err) } - if err = sweep.SweepOrchestrator(sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping AppStream Stacks for %s: %w", region, err)) - } + err = sweep.SweepOrchestrator(sweepResources) - if sweep.SkipSweepError(err) { - log.Printf("[WARN] Skipping AppStream Stacks sweep for %s: %s", region, err) - return nil // In case we have completed some pages, but had errors + if err != nil { + return fmt.Errorf("error sweeping AppStream Stacks (%s): %w", region, err) } - return errs.ErrorOrNil() + return nil }