Skip to content

Commit

Permalink
Merge pull request #4286 from gheine/ecs_cluster
Browse files Browse the repository at this point in the history
ECS cluster data source: Return error on multiple clusters with same name
  • Loading branch information
bflad authored Apr 20, 2018
2 parents 03d17ff + 018dda9 commit 2689fe8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions aws/data_source_aws_ecs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error
return err
}

for _, cluster := range desc.Clusters {
if aws.StringValue(cluster.ClusterName) != d.Get("cluster_name").(string) {
continue
}
d.SetId(aws.StringValue(cluster.ClusterArn))
d.Set("arn", cluster.ClusterArn)
d.Set("status", cluster.Status)
d.Set("pending_tasks_count", cluster.PendingTasksCount)
d.Set("running_tasks_count", cluster.RunningTasksCount)
d.Set("registered_container_instances_count", cluster.RegisteredContainerInstancesCount)
if len(desc.Clusters) == 0 {
return fmt.Errorf("no matches found for name: %s", d.Get("cluster_name").(string))
}

if d.Id() == "" {
return fmt.Errorf("cluster with name %q not found", d.Get("cluster_name").(string))
if len(desc.Clusters) > 1 {
return fmt.Errorf("multiple matches found for name: %s", d.Get("cluster_name").(string))
}

cluster := desc.Clusters[0]
d.SetId(aws.StringValue(cluster.ClusterArn))
d.Set("arn", cluster.ClusterArn)
d.Set("status", cluster.Status)
d.Set("pending_tasks_count", cluster.PendingTasksCount)
d.Set("running_tasks_count", cluster.RunningTasksCount)
d.Set("registered_container_instances_count", cluster.RegisteredContainerInstancesCount)

return nil
}

0 comments on commit 2689fe8

Please sign in to comment.