2017-01-31 17:27:58 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ecs"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func dataSourceAwsEcsCluster() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Read: dataSourceAwsEcsClusterRead,
|
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
2017-02-01 15:51:26 +01:00
|
|
|
"cluster_name": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
|
2017-02-01 15:51:26 +01:00
|
|
|
"arn": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
|
2017-02-01 15:51:26 +01:00
|
|
|
"status": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
|
2017-02-01 15:51:26 +01:00
|
|
|
"pending_tasks_count": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
|
2017-02-01 15:51:26 +01:00
|
|
|
"running_tasks_count": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
|
2017-02-01 15:51:26 +01:00
|
|
|
"registered_container_instances_count": {
|
2017-01-31 17:27:58 +01:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
conn := meta.(*AWSClient).ecsconn
|
|
|
|
|
2017-01-31 23:40:31 +01:00
|
|
|
desc, err := conn.DescribeClusters(&ecs.DescribeClustersInput{
|
|
|
|
Clusters: []*string{aws.String(d.Get("cluster_name").(string))},
|
|
|
|
})
|
2017-01-31 17:27:58 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cluster := range desc.Clusters {
|
2017-01-31 23:40:31 +01:00
|
|
|
if aws.StringValue(cluster.ClusterName) != d.Get("cluster_name").(string) {
|
|
|
|
continue
|
2017-01-31 17:27:58 +01:00
|
|
|
}
|
2017-01-31 23:40:31 +01:00
|
|
|
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)
|
2017-01-31 17:27:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-31 23:40:31 +01:00
|
|
|
if d.Id() == "" {
|
2017-01-31 17:27:58 +01:00
|
|
|
return fmt.Errorf("cluster with name %q not found", d.Get("cluster_name").(string))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|