github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_ecs_cluster.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/service/ecs" 8 "github.com/hashicorp/terraform/helper/schema" 9 ) 10 11 func dataSourceAwsEcsCluster() *schema.Resource { 12 return &schema.Resource{ 13 Read: dataSourceAwsEcsClusterRead, 14 15 Schema: map[string]*schema.Schema{ 16 "cluster_name": { 17 Type: schema.TypeString, 18 Required: true, 19 ForceNew: true, 20 }, 21 22 "arn": { 23 Type: schema.TypeString, 24 Computed: true, 25 }, 26 27 "status": { 28 Type: schema.TypeString, 29 Computed: true, 30 }, 31 32 "pending_tasks_count": { 33 Type: schema.TypeInt, 34 Computed: true, 35 }, 36 37 "running_tasks_count": { 38 Type: schema.TypeInt, 39 Computed: true, 40 }, 41 42 "registered_container_instances_count": { 43 Type: schema.TypeInt, 44 Computed: true, 45 }, 46 }, 47 } 48 } 49 50 func dataSourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error { 51 conn := meta.(*AWSClient).ecsconn 52 53 desc, err := conn.DescribeClusters(&ecs.DescribeClustersInput{ 54 Clusters: []*string{aws.String(d.Get("cluster_name").(string))}, 55 }) 56 57 if err != nil { 58 return err 59 } 60 61 for _, cluster := range desc.Clusters { 62 if aws.StringValue(cluster.ClusterName) != d.Get("cluster_name").(string) { 63 continue 64 } 65 d.SetId(aws.StringValue(cluster.ClusterArn)) 66 d.Set("status", cluster.Status) 67 d.Set("pending_tasks_count", cluster.PendingTasksCount) 68 d.Set("running_tasks_count", cluster.RunningTasksCount) 69 d.Set("registered_container_instances_count", cluster.RegisteredContainerInstancesCount) 70 } 71 72 if d.Id() == "" { 73 return fmt.Errorf("cluster with name %q not found", d.Get("cluster_name").(string)) 74 } 75 76 return nil 77 }