diff --git a/internal/service/opsworks/layers.go b/internal/service/opsworks/layers.go index ab7da46a43a..5112148edbe 100644 --- a/internal/service/opsworks/layers.go +++ b/internal/service/opsworks/layers.go @@ -6,7 +6,6 @@ import ( "strconv" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/opsworks" "github.com/hashicorp/aws-sdk-go-base/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -429,15 +428,27 @@ func (lt *opsworksLayerType) Create(d *schema.ResourceData, meta interface{}) er } } - arn := arn.ARN{ - Partition: meta.(*conns.AWSClient).Partition, - Region: meta.(*conns.AWSClient).Region, - Service: "opsworks", - AccountID: meta.(*conns.AWSClient).AccountID, - Resource: fmt.Sprintf("layer/%s", d.Id()), - }.String() - if len(tags) > 0 { + req := &opsworks.DescribeLayersInput{ + LayerIds: []*string{ + aws.String(d.Id()), + }, + } + + log.Printf("[DEBUG] Reading OpsWorks layer: %s", d.Id()) + + resp, err := conn.DescribeLayers(req) + if err != nil { + if tfawserr.ErrMessageContains(err, opsworks.ErrCodeResourceNotFoundException, "") { + d.SetId("") + return nil + } + return err + } + + layer := resp.Layers[0] + arn := aws.StringValue(layer.Arn) + if err := UpdateTags(conn, arn, nil, tags); err != nil { return fmt.Errorf("error updating Opsworks stack (%s) tags: %s", arn, err) } diff --git a/internal/service/opsworks/stack.go b/internal/service/opsworks/stack.go index 36fa659d53b..a61df3dd0b2 100644 --- a/internal/service/opsworks/stack.go +++ b/internal/service/opsworks/stack.go @@ -581,7 +581,7 @@ func resourceStackUpdate(d *schema.ResourceData, meta interface{}) error { arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, - Region: meta.(*conns.AWSClient).Region, + Region: d.Get("region").(string), Service: "opsworks", AccountID: meta.(*conns.AWSClient).AccountID, Resource: fmt.Sprintf("stack/%s/", d.Id()),