Skip to content

Commit

Permalink
provider/cloudstack: add affinity_group_names
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Jun 27, 2016
1 parent 19c9802 commit 2920832
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions builtin/providers/cloudstack/resource_cloudstack_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ func resourceCloudStackInstance() *schema.Resource {
Set: schema.HashString,
},

"affinity_group_names": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"security_group_names": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -230,6 +239,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 security_group_names supplied, add it to the parameter struct
if sgns := d.Get("security_group_names").(*schema.Set); sgns.Len() > 0 {
var groups []string
Expand Down Expand Up @@ -339,6 +359,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)
}

sgns := &schema.Set{F: schema.HashString}
for _, group := range vm.Securitygroup {
sgns.Add(group.Name)
Expand Down

0 comments on commit 2920832

Please sign in to comment.