Skip to content

Commit

Permalink
provider/cloudstack: add security_group_names
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Jun 20, 2016
1 parent 717dced commit 84b767a
Show file tree
Hide file tree
Showing 2 changed files with 32 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,
},

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

"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -215,6 +224,17 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
p.SetAffinitygroupids(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

for _, group := range sgns.List() {
groups = append(groups, group.(string))
}

p.SetSecuritygroupnames(groups)
}

// If there is a project supplied, we retrieve and set the project id
if err := setProjectid(p, cs, d); err != nil {
return err
Expand Down Expand Up @@ -308,6 +328,15 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("affinity_group_ids", groups)
}

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

if sgns.Len() > 0 {
d.Set("security_group_names", sgns)
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ The following arguments are supported:
* `expunge` - (Optional) This determines if the instance is expunged when it is
destroyed (defaults false)

* `security_group_names` - (Optional) List of security groups to apply to this
isnstance. Changing this forces a new resource to be created.

## Attributes Reference

The following attributes are exported:
Expand Down

0 comments on commit 84b767a

Please sign in to comment.