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

tests/d/aws_ecs_cluster: Fix 'Attribute "setting.#" not set, but "setting.#" is set in aws_ecs_cluster.test as "1"' #22119

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/22119.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_ecs_cluster: Ensure that `setting` attribute is set consistently
```
4 changes: 2 additions & 2 deletions internal/service/ecs/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
15 changes: 5 additions & 10 deletions internal/service/ecs/cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions internal/service/ecs/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
16 changes: 5 additions & 11 deletions internal/service/ecs/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ecs/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down