forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_aws_ecs_cluster.go
81 lines (66 loc) · 1.75 KB
/
data_source_aws_ecs_cluster.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package aws
import (
"fmt"
"log"
"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{
"cluster_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"pending_tasks_count": {
Type: schema.TypeInt,
Computed: true,
},
"running_tasks_count": {
Type: schema.TypeInt,
Computed: true,
},
"registered_container_instances_count": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*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)
if err != nil {
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 d.Id() == "" {
return fmt.Errorf("cluster with name %q not found", d.Get("cluster_name").(string))
}
return nil
}