provider/cloudstack: add affinity_group_names

This commit is contained in:
Mickaël Canévet 2016-06-20 17:52:35 +02:00
parent 59e2a43aa6
commit 3d9bdafb97
2 changed files with 36 additions and 5 deletions

View File

@ -74,11 +74,19 @@ func resourceCloudStackInstance() *schema.Resource {
},
"affinity_group_ids": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
ConflictsWith: []string{"affinity_group_names"},
},
"affinity_group_names": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
ConflictsWith: []string{"affinity_group_ids"},
},
"project": &schema.Schema{
@ -221,6 +229,17 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
p.SetAffinitygroupids(groups)
}
// If there is a affinity_group_names supplied, add it to the parameter struct
if agns := d.Get("affinity_group_names").(*schema.Set); agns.Len() > 0 {
var groups []string
for _, group := range agns.List() {
groups = append(groups, group.(string))
}
p.SetAffinitygroupnames(groups)
}
// If there is a project supplied, we retrieve and set the project id
if err := setProjectid(p, cs, d); err != nil {
return err
@ -319,6 +338,15 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("affinity_group_ids", groups)
}
agns := &schema.Set{F: schema.HashString}
for _, group := range vm.Affinitygroup {
agns.Add(group.Name)
}
if agns.Len() > 0 {
d.Set("affinity_group_names", agns)
}
return nil
}

View File

@ -70,6 +70,9 @@ The following arguments are supported:
gigabytes. The root disk is resized on deploy. Only applies to
template-based deployments.
* `affinity_group_names` - (Optional) List of affinity groups to apply to this
instance. Changing this forces a new resource to be created.
## Attributes Reference
The following attributes are exported: