Fix a panic that could occur if no ECS Cluster was found for a given cluster name

This commit is contained in:
clint shryock 2015-11-09 14:33:20 -06:00
parent deb17b90eb
commit 2694022b4a
1 changed files with 9 additions and 2 deletions

View File

@ -59,9 +59,16 @@ func resourceAwsEcsClusterRead(d *schema.ResourceData, meta interface{}) error {
} }
log.Printf("[DEBUG] Received ECS clusters: %s", out.Clusters) log.Printf("[DEBUG] Received ECS clusters: %s", out.Clusters)
d.SetId(*out.Clusters[0].ClusterArn) for _, c := range out.Clusters {
d.Set("name", *out.Clusters[0].ClusterName) if *c.ClusterName == clusterName {
d.SetId(*c.ClusterArn)
d.Set("name", c.ClusterName)
return nil
}
}
log.Printf("[ERR] No matching ECS Cluster found for (%s)", d.Id())
d.SetId("")
return nil return nil
} }