Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix security group not restored #378

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion outscale/data_source_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ func getOAPIVMSecurityGroups(groupSet []oscgo.SecurityGroupLight) []map[string]i
return res
}

func getVMSecurityGroupIds(sgIds []oscgo.SecurityGroupLight) []string {
res := make([]string, len(sgIds))
for k, ids := range sgIds {
res[k] = ids.GetSecurityGroupId()
}
return res
}

func getDataSourceOAPIVMSchemas() map[string]*schema.Schema {
wholeSchema := map[string]*schema.Schema{
"filter": dataSourceFiltersSchema(),
Expand Down Expand Up @@ -354,7 +362,7 @@ func getOApiVMAttributesSchema() map[string]*schema.Schema {
Computed: true,
},
"security_group_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down
11 changes: 8 additions & 3 deletions outscale/resource_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func resourceOutscaleOApiVM() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
"security_group_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -667,6 +667,11 @@ func resourceOAPIVMRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("admin_password", adminPassword); err != nil {
return err
}
if len(utils.SetToStringSlice(d.Get("security_group_ids").(*schema.Set))) > 0 {
if err := set("security_group_ids", getVMSecurityGroupIds(vm.GetSecurityGroups())); err != nil {
return err
}
}
d.SetId(vm.GetVmId())
return oapiVMDescriptionAttributes(set, &vm)
}); err != nil {
Expand Down Expand Up @@ -789,7 +794,7 @@ func resourceOAPIVMUpdate(d *schema.ResourceData, meta interface{}) error {
if d.HasChange("security_group_ids") && !d.IsNewResource() {
opts := oscgo.UpdateVmRequest{VmId: id}

opts.SetSecurityGroupIds(utils.InterfaceSliceToStringSlice(d.Get("security_group_ids").([]interface{})))
opts.SetSecurityGroupIds(utils.SetToStringSlice(d.Get("security_group_ids").(*schema.Set)))
if err := updateVmAttr(conn, opts); err != nil {
return err
}
Expand Down Expand Up @@ -976,7 +981,7 @@ func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.Crea
request.SetPrivateIps(privateIPs)
}

if sgIDs := utils.InterfaceSliceToStringSlice(d.Get("security_group_ids").([]interface{})); len(sgIDs) > 0 {
if sgIDs := utils.SetToStringSlice(d.Get("security_group_ids").(*schema.Set)); len(sgIDs) > 0 {
outscale-toa marked this conversation as resolved.
Show resolved Hide resolved
request.SetSecurityGroupIds(sgIDs)
}

Expand Down