diff --git a/.changelog/22119.txt b/.changelog/22119.txt new file mode 100644 index 00000000000..7c4bd2d3bad --- /dev/null +++ b/.changelog/22119.txt @@ -0,0 +1,3 @@ +```release-note:bug +data-source/aws_ecs_cluster: Ensure that `setting` attribute is set consistently +``` \ No newline at end of file diff --git a/internal/service/ecs/cluster.go b/internal/service/ecs/cluster.go index 428c78f2e37..e49581daa68 100644 --- a/internal/service/ecs/cluster.go +++ b/internal/service/ecs/cluster.go @@ -242,7 +242,7 @@ func resourceClusterRead(d *schema.ResourceData, meta interface{}) error { var out *ecs.DescribeClustersOutput err := resource.Retry(2*time.Minute, func() *resource.RetryError { var err error - out, err = FindClusterByARN(conn, d.Id()) + out, err = FindClusterByNameOrARN(conn, d.Id()) if err != nil { return resource.NonRetryableError(err) @@ -258,7 +258,7 @@ func resourceClusterRead(d *schema.ResourceData, meta interface{}) error { return nil }) if tfresource.TimedOut(err) { - out, err = FindClusterByARN(conn, d.Id()) + out, err = FindClusterByNameOrARN(conn, d.Id()) } if tfresource.NotFound(err) { diff --git a/internal/service/ecs/cluster_data_source.go b/internal/service/ecs/cluster_data_source.go index 2b46aa93145..7fb12dfc4a3 100644 --- a/internal/service/ecs/cluster_data_source.go +++ b/internal/service/ecs/cluster_data_source.go @@ -2,10 +2,8 @@ package ecs import ( "fmt" - "log" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ecs" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" ) @@ -68,22 +66,19 @@ func DataSourceCluster() *schema.Resource { func dataSourceClusterRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).ECSConn - params := &ecs.DescribeClustersInput{ - Clusters: []*string{aws.String(d.Get("cluster_name").(string))}, - } - log.Printf("[DEBUG] Reading ECS Cluster: %s", params) - desc, err := conn.DescribeClusters(params) + clusterName := d.Get("cluster_name").(string) + desc, err := FindClusterByNameOrARN(conn, d.Get("cluster_name").(string)) if err != nil { - return err + return fmt.Errorf("error reading ECS Cluster (%s): %w", clusterName, err) } if len(desc.Clusters) == 0 { - return fmt.Errorf("no matches found for name: %s", d.Get("cluster_name").(string)) + return fmt.Errorf("no matches found for name: %s", clusterName) } if len(desc.Clusters) > 1 { - return fmt.Errorf("multiple matches found for name: %s", d.Get("cluster_name").(string)) + return fmt.Errorf("multiple matches found for name: %s", clusterName) } cluster := desc.Clusters[0] diff --git a/internal/service/ecs/cluster_test.go b/internal/service/ecs/cluster_test.go index 9ed82999b7a..c231b8b8344 100644 --- a/internal/service/ecs/cluster_test.go +++ b/internal/service/ecs/cluster_test.go @@ -345,7 +345,7 @@ func testAccCheckClusterDestroy(s *terraform.State) error { continue } - out, err := tfecs.FindClusterByARN(conn, rs.Primary.ID) + out, err := tfecs.FindClusterByNameOrARN(conn, rs.Primary.ID) if err != nil { return err @@ -369,7 +369,7 @@ func testAccCheckClusterExists(resourceName string, cluster *ecs.Cluster) resour } conn := acctest.Provider.Meta().(*conns.AWSClient).ECSConn - output, err := tfecs.FindClusterByARN(conn, rs.Primary.ID) + output, err := tfecs.FindClusterByNameOrARN(conn, rs.Primary.ID) if err != nil { return fmt.Errorf("error reading ECS Cluster (%s): %w", rs.Primary.ID, err) diff --git a/internal/service/ecs/find.go b/internal/service/ecs/find.go index 3f743d88430..c0b4502ad5d 100644 --- a/internal/service/ecs/find.go +++ b/internal/service/ecs/find.go @@ -4,6 +4,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ecs" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) func FindCapacityProviderByARN(conn *ecs.ECS, arn string) (*ecs.CapacityProvider, error) { @@ -37,14 +38,10 @@ func FindCapacityProviderByARN(conn *ecs.ECS, arn string) (*ecs.CapacityProvider return capacityProvider, nil } -func FindClusterByARN(conn *ecs.ECS, arn string) (*ecs.DescribeClustersOutput, error) { +func FindClusterByNameOrARN(conn *ecs.ECS, nameOrARN string) (*ecs.DescribeClustersOutput, error) { input := &ecs.DescribeClustersInput{ - Clusters: []*string{aws.String(arn)}, - Include: []*string{ - aws.String(ecs.ClusterFieldTags), - aws.String(ecs.ClusterFieldConfigurations), - aws.String(ecs.ClusterFieldSettings), - }, + Clusters: aws.StringSlice([]string{nameOrARN}), + Include: aws.StringSlice([]string{ecs.ClusterFieldTags, ecs.ClusterFieldConfigurations, ecs.ClusterFieldSettings}), } output, err := conn.DescribeClusters(input) @@ -57,10 +54,7 @@ func FindClusterByARN(conn *ecs.ECS, arn string) (*ecs.DescribeClustersOutput, e } if output == nil { - return nil, &resource.NotFoundError{ - Message: "Empty result", - LastRequest: input, - } + return nil, tfresource.NewEmptyResultError(input) } return output, nil diff --git a/internal/service/ecs/status.go b/internal/service/ecs/status.go index fce46b8d2e3..ae9dd2c21fd 100644 --- a/internal/service/ecs/status.go +++ b/internal/service/ecs/status.go @@ -87,7 +87,7 @@ func statusService(conn *ecs.ECS, id, cluster string) resource.StateRefreshFunc func statusCluster(conn *ecs.ECS, arn string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindClusterByARN(conn, arn) + output, err := FindClusterByNameOrARN(conn, arn) if tfawserr.ErrCodeEquals(err, ecs.ErrCodeClusterNotFoundException) { return nil, clusterStatusNone, nil