@@ -11,7 +11,6 @@ import (
11
11
gcorecloud "github.com/G-Core/gcorelabscloud-go"
12
12
"github.com/G-Core/gcorelabscloud-go/gcore/instance/v1/instances"
13
13
"github.com/G-Core/gcorelabscloud-go/gcore/instance/v1/types"
14
- "github.com/G-Core/gcorelabscloud-go/gcore/securitygroup/v1/securitygroups"
15
14
"github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks"
16
15
"github.com/G-Core/gcorelabscloud-go/gcore/volume/v1/volumes"
17
16
"github.com/hashicorp/go-cty/cty"
@@ -212,7 +211,6 @@ func resourceInstance() *schema.Resource {
212
211
"security_groups" : {
213
212
Type : schema .TypeList ,
214
213
Optional : true ,
215
- Computed : true ,
216
214
Description : "list of security group IDs" ,
217
215
Elem : & schema.Schema {Type : schema .TypeString },
218
216
},
@@ -815,7 +813,10 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
815
813
iface := i .(map [string ]interface {})
816
814
817
815
iType := types .InterfaceType (iface ["type" ].(string ))
818
- opts := instances.InterfaceOpts {Type : iType }
816
+ opts := instances.InterfaceInstanceCreateOpts {
817
+ InterfaceOpts : instances.InterfaceOpts {Type : iType },
818
+ }
819
+
819
820
switch iType {
820
821
case types .SubnetInterfaceType :
821
822
opts .SubnetID = iface ["subnet_id" ].(string )
@@ -825,6 +826,13 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
825
826
opts .PortID = iface ["port_id" ].(string )
826
827
}
827
828
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
+
828
836
log .Printf ("[DEBUG] attach interface: %+v" , opts )
829
837
results , err := instances .AttachInterface (client , instanceID , opts ).Extract ()
830
838
if err != nil {
@@ -833,7 +841,7 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
833
841
834
842
taskID := results .Tasks [0 ]
835
843
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 ) {
837
845
taskInfo , err := tasks .Get (client , string (task )).Extract ()
838
846
if err != nil {
839
847
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
846
854
},
847
855
)
848
856
849
- var portID string
850
857
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 )
858
859
}
859
860
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
- }
889
861
}
890
862
}
891
863
0 commit comments