WIP export cache nodes
Needs to wait for len(cluster.CacheNodes) == cluster.NumCacheNodes, since apparently that takes a bit of time and the initial response always has an empty collection of nodes
This commit is contained in:
parent
8a3b75d361
commit
6f3ce6bf3c
|
@ -3,6 +3,7 @@ package aws
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/awslabs/aws-sdk-go/aws"
|
"github.com/awslabs/aws-sdk-go/aws"
|
||||||
|
@ -82,6 +83,27 @@ func resourceAwsElasticacheCluster() *schema.Resource {
|
||||||
return hashcode.String(v.(string))
|
return hashcode.String(v.(string))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Exported Attributes
|
||||||
|
"cache_nodes": &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Computed: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"id": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"address": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
"port": &schema.Schema{
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,11 +189,45 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{})
|
||||||
d.Set("security_group_names", c.CacheSecurityGroups)
|
d.Set("security_group_names", c.CacheSecurityGroups)
|
||||||
d.Set("security_group_ids", c.SecurityGroups)
|
d.Set("security_group_ids", c.SecurityGroups)
|
||||||
d.Set("parameter_group_name", c.CacheParameterGroup)
|
d.Set("parameter_group_name", c.CacheParameterGroup)
|
||||||
|
|
||||||
|
if err := setCacheNodeData(d, c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setCacheNodeData(d *schema.ResourceData, c *elasticache.CacheCluster) error {
|
||||||
|
sortedCacheNodes := make([]*elasticache.CacheNode, len(c.CacheNodes))
|
||||||
|
copy(sortedCacheNodes, c.CacheNodes)
|
||||||
|
sort.Sort(byCacheNodeId(sortedCacheNodes))
|
||||||
|
|
||||||
|
cacheNodeData := make([]map[string]interface{}, 0, len(sortedCacheNodes))
|
||||||
|
|
||||||
|
for _, node := range sortedCacheNodes {
|
||||||
|
if node.CacheNodeID == nil || node.Endpoint == nil || node.Endpoint.Address == nil || node.Endpoint.Port == nil {
|
||||||
|
return fmt.Errorf("Unexpected nil pointer in: %#v", node)
|
||||||
|
}
|
||||||
|
cacheNodeData = append(cacheNodeData, map[string]interface{}{
|
||||||
|
"id": node.CacheNodeID,
|
||||||
|
"address": node.Endpoint.Address,
|
||||||
|
"port": node.Endpoint.Port,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.Set("cache_nodes", cacheNodeData)
|
||||||
|
}
|
||||||
|
|
||||||
|
type byCacheNodeId []*elasticache.CacheNode
|
||||||
|
|
||||||
|
func (b byCacheNodeId) Len() int { return len(b) }
|
||||||
|
func (b byCacheNodeId) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
func (b byCacheNodeId) Less(i, j int) bool {
|
||||||
|
return b[i].CacheNodeID != nil && b[j].CacheNodeID != nil &&
|
||||||
|
*b[i].CacheNodeID < *b[j].CacheNodeID
|
||||||
|
}
|
||||||
|
|
||||||
func resourceAwsElasticacheClusterDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsElasticacheClusterDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
conn := meta.(*AWSClient).elasticacheconn
|
conn := meta.(*AWSClient).elasticacheconn
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ func TestAccAWSElasticacheCluster(t *testing.T) {
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
testAccCheckAWSElasticacheSecurityGroupExists("aws_elasticache_security_group.bar"),
|
||||||
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar"),
|
testAccCheckAWSElasticacheClusterExists("aws_elasticache_cluster.bar"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_elasticache_cluster.bar", "cache_nodes.0.id", "001"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue