Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 4fe907a

Browse files
[Partner] Alexander Sokolovalexk53
authored andcommitted
gcorelabscloud-go version updated, attach instance interface fixed
1 parent fce5e26 commit 4fe907a

File tree

3 files changed

+16
-48
lines changed

3 files changed

+16
-48
lines changed

gcore/resource_gcore_instance.go

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
gcorecloud "github.com/G-Core/gcorelabscloud-go"
1212
"github.com/G-Core/gcorelabscloud-go/gcore/instance/v1/instances"
1313
"github.com/G-Core/gcorelabscloud-go/gcore/instance/v1/types"
14-
"github.com/G-Core/gcorelabscloud-go/gcore/securitygroup/v1/securitygroups"
1514
"github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks"
1615
"github.com/G-Core/gcorelabscloud-go/gcore/volume/v1/volumes"
1716
"github.com/hashicorp/go-cty/cty"
@@ -212,7 +211,6 @@ func resourceInstance() *schema.Resource {
212211
"security_groups": {
213212
Type: schema.TypeList,
214213
Optional: true,
215-
Computed: true,
216214
Description: "list of security group IDs",
217215
Elem: &schema.Schema{Type: schema.TypeString},
218216
},
@@ -815,7 +813,10 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
815813
iface := i.(map[string]interface{})
816814

817815
iType := types.InterfaceType(iface["type"].(string))
818-
opts := instances.InterfaceOpts{Type: iType}
816+
opts := instances.InterfaceInstanceCreateOpts{
817+
InterfaceOpts: instances.InterfaceOpts{Type: iType},
818+
}
819+
819820
switch iType {
820821
case types.SubnetInterfaceType:
821822
opts.SubnetID = iface["subnet_id"].(string)
@@ -825,6 +826,13 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
825826
opts.PortID = iface["port_id"].(string)
826827
}
827828

829+
rawSgsID := iface["security_groups"].([]interface{})
830+
sgs := make([]gcorecloud.ItemID, len(rawSgsID))
831+
for i, sgID := range rawSgsID {
832+
sgs[i] = gcorecloud.ItemID{ID: sgID.(string)}
833+
}
834+
opts.SecurityGroups = sgs
835+
828836
log.Printf("[DEBUG] attach interface: %+v", opts)
829837
results, err := instances.AttachInterface(client, instanceID, opts).Extract()
830838
if err != nil {
@@ -833,7 +841,7 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
833841

834842
taskID := results.Tasks[0]
835843
log.Printf("[DEBUG] attach interface taskID: %s", taskID)
836-
portIDRaw, err := tasks.WaitTaskAndReturnResult(client, taskID, true, InstanceCreatingTimeout, func(task tasks.TaskID) (interface{}, error) {
844+
_, err = tasks.WaitTaskAndReturnResult(client, taskID, true, InstanceCreatingTimeout, func(task tasks.TaskID) (interface{}, error) {
837845
taskInfo, err := tasks.Get(client, string(task)).Extract()
838846
if err != nil {
839847
return nil, fmt.Errorf("cannot get task with ID: %s. Error: %w, task: %+v", task, err, taskInfo)
@@ -846,46 +854,10 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
846854
},
847855
)
848856

849-
var portID string
850857
if err != nil {
851-
if opts.PortID != "" {
852-
portID = opts.PortID
853-
} else {
854-
return diag.FromErr(err)
855-
}
856-
} else {
857-
portID = portIDRaw.(string)
858+
return diag.FromErr(err)
858859
}
859860

860-
// attach security group to interface
861-
sgIDs := iface["security_groups"].([]interface{})
862-
if len(sgIDs) > 0 {
863-
sgClient, err := CreateClient(provider, d, securityGroupPoint, versionPointV1)
864-
if err != nil {
865-
return diag.FromErr(err)
866-
}
867-
868-
sgsName := make([]string, len(sgIDs))
869-
for i, sgID := range sgIDs {
870-
sg, err := securitygroups.Get(sgClient, sgID.(string)).Extract()
871-
if err != nil {
872-
return diag.FromErr(err)
873-
}
874-
sgsName[i] = sg.Name
875-
}
876-
877-
attachOpts := instances.SecurityGroupOpts{
878-
PortsSecurityGroupNames: []instances.PortSecurityGroupNames{{
879-
PortID: &portID,
880-
SecurityGroupNames: sgsName,
881-
}},
882-
}
883-
884-
log.Printf("[DEBUG] attach security group opts: %+v", attachOpts)
885-
if err := instances.AssignSecurityGroup(client, instanceID, attachOpts).Err; err != nil {
886-
return diag.Errorf("cannot assign security group. Error: %s", err.Error())
887-
}
888-
}
889861
}
890862
}
891863

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ module github.com/terraform-providers/terraform-provider-gcorelabs
22

33
go 1.17
44

5-
//replace github.com/G-Core/gcorelabscloud-go => /home/ondi/go/src/github.com/G-Core/gcorelabscloud-go
6-
75
require (
86
github.com/AlekSi/pointer v1.2.0
97
github.com/G-Core/gcore-dns-sdk-go v0.2.3
108
github.com/G-Core/gcore-storage-sdk-go v0.1.3
119
github.com/G-Core/gcorelabscdn-go v0.1.20
12-
github.com/G-Core/gcorelabscloud-go v0.5.0
10+
github.com/G-Core/gcorelabscloud-go v0.5.2
1311
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1412
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
1513
github.com/mitchellh/mapstructure v1.4.3

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ github.com/G-Core/gcore-storage-sdk-go v0.1.3 h1:vzgt5pKB3jsxbUs7jdEX1jyRC2YqbwL
8585
github.com/G-Core/gcore-storage-sdk-go v0.1.3/go.mod h1:e/5w5R2Uh6T7g6oAc5SpTKZJInFG6FyYYvGpUgRwCQ4=
8686
github.com/G-Core/gcorelabscdn-go v0.1.20 h1:RT/k4olBTPuVyE2LUlu5D9GTvj3hPA9NnBZwXYHFZxc=
8787
github.com/G-Core/gcorelabscdn-go v0.1.20/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
88-
github.com/G-Core/gcorelabscloud-go v0.4.54 h1:KDMRSGj/StmvFyqdIFng5Eb4eZB5W5GgIHZzrysh8VY=
89-
github.com/G-Core/gcorelabscloud-go v0.4.54/go.mod h1:nuDFy76Eja1EXBrG+q+dqpC2KqrHfID3JS8833LDJG8=
90-
github.com/G-Core/gcorelabscloud-go v0.5.0 h1:PMnk2a+1VxviGcktHXZS4iIO2K1bvclsele6DMfLAr8=
91-
github.com/G-Core/gcorelabscloud-go v0.5.0/go.mod h1:nuDFy76Eja1EXBrG+q+dqpC2KqrHfID3JS8833LDJG8=
88+
github.com/G-Core/gcorelabscloud-go v0.5.2 h1:KoBre603zAwh7yJPNVDgAwXwwyz6v5xL0UXqr8kRL78=
89+
github.com/G-Core/gcorelabscloud-go v0.5.2/go.mod h1:nuDFy76Eja1EXBrG+q+dqpC2KqrHfID3JS8833LDJG8=
9290
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
9391
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
9492
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=

0 commit comments

Comments
 (0)