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 27, 2016
1 parent 59e2a43 commit 77cf813
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 @@ -221,6 +230,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 @@ -319,6 +339,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 @@ -70,6 +70,9 @@ The following arguments are supported:
gigabytes. The root disk is resized on deploy. Only applies to
template-based deployments.

* `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 77cf813

Please sign in to comment.