diff --git a/builtin/providers/aws/data_source_aws_ecs_cluster.go b/builtin/providers/aws/data_source_aws_ecs_cluster.go index 14c4fa38f..e808814e7 100644 --- a/builtin/providers/aws/data_source_aws_ecs_cluster.go +++ b/builtin/providers/aws/data_source_aws_ecs_cluster.go @@ -50,29 +50,28 @@ func dataSourceAwsEcsCluster() *schema.Resource { func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ecsconn - desc, err := conn.DescribeClusters(&ecs.DescribeClustersInput{}) + desc, err := conn.DescribeClusters(&ecs.DescribeClustersInput{ + Clusters: []*string{aws.String(d.Get("cluster_name").(string))}, + }) if err != nil { return err } - var c *ecs.Cluster for _, cluster := range desc.Clusters { - if aws.StringValue(cluster.ClusterName) == d.Get("cluster_name").(string) { - c = cluster - break + if aws.StringValue(cluster.ClusterName) != d.Get("cluster_name").(string) { + continue } + d.SetId(aws.StringValue(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 c == nil { + if d.Id() == "" { return fmt.Errorf("cluster with name %q not found", d.Get("cluster_name").(string)) } - d.SetId(aws.StringValue(c.ClusterArn)) - d.Set("status", c.Status) - d.Set("pending_tasks_count", c.PendingTasksCount) - d.Set("running_tasks_count", c.RunningTasksCount) - d.Set("registered_container_instances_count", c.RegisteredContainerInstancesCount) - return nil } diff --git a/builtin/providers/aws/data_source_aws_ecs_cluster_test.go b/builtin/providers/aws/data_source_aws_ecs_cluster_test.go index 85ce1b4bf..4c92c77b0 100644 --- a/builtin/providers/aws/data_source_aws_ecs_cluster_test.go +++ b/builtin/providers/aws/data_source_aws_ecs_cluster_test.go @@ -1,7 +1,10 @@ package aws import ( + "fmt" + "math/rand" "testing" + "time" "github.com/hashicorp/terraform/helper/resource" ) @@ -24,12 +27,35 @@ func TestAccAWSEcsDataSource_ecsCluster(t *testing.T) { }) } -const testAccCheckAwsEcsClusterDataSourceConfig = ` +var testAccCheckAwsEcsClusterDataSourceConfig = fmt.Sprintf(` resource "aws_ecs_cluster" "default" { - name = "default" + name = "default-%d" +} + +resource "aws_ecs_task_definition" "mongo" { + family = "mongodb" + container_definitions = <