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

Commit b5e8215

Browse files
committed
attach interface fixed
1 parent 8c938f6 commit b5e8215

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

gcore/resource_gcore_floatingip.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func resourceFloatingIP() *schema.Resource {
3131
"project_id": &schema.Schema{
3232
Type: schema.TypeInt,
3333
Optional: true,
34-
ForceNew: true,
3534
ExactlyOneOf: []string{
3635
"project_id",
3736
"project_name",
@@ -40,7 +39,6 @@ func resourceFloatingIP() *schema.Resource {
4039
"region_id": &schema.Schema{
4140
Type: schema.TypeInt,
4241
Optional: true,
43-
ForceNew: true,
4442
ExactlyOneOf: []string{
4543
"region_id",
4644
"region_name",
@@ -49,7 +47,6 @@ func resourceFloatingIP() *schema.Resource {
4947
"project_name": &schema.Schema{
5048
Type: schema.TypeString,
5149
Optional: true,
52-
ForceNew: true,
5350
ExactlyOneOf: []string{
5451
"project_id",
5552
"project_name",
@@ -58,7 +55,6 @@ func resourceFloatingIP() *schema.Resource {
5855
"region_name": &schema.Schema{
5956
Type: schema.TypeString,
6057
Optional: true,
61-
ForceNew: true,
6258
ExactlyOneOf: []string{
6359
"region_id",
6460
"region_name",

gcore/resource_gcore_instance.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func resourceInstance() *schema.Resource {
170170
Type: schema.TypeString,
171171
Description: "required if type is 'subnet'",
172172
Optional: true,
173+
Computed: true,
173174
},
174175
//nested map is not supported, in this case, you do not need to use the list for the map
175176
"fip_source": {
@@ -503,20 +504,28 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa
503504
for _, assignment := range iface.IPAssignments {
504505
subnetID := assignment.SubnetID
505506

506-
_, ok := interfaces[subnetID]
507+
//bad idea, but what to do
508+
var iOpts instances.InterfaceOpts
509+
var ok bool
510+
for _, k := range []string{subnetID, iface.PortID, iface.NetworkID, types.ExternalInterfaceType.String()} {
511+
if iOpts, ok = interfaces[k]; ok {
512+
break
513+
}
514+
}
515+
507516
if !ok {
508517
continue
509518
}
510519

511520
i := make(map[string]interface{})
512521

513-
i["type"] = interfaces[subnetID].Type.String()
522+
i["type"] = iOpts.Type.String()
514523
i["network_id"] = iface.NetworkID
515524
i["subnet_id"] = subnetID
516525
i["port_id"] = iface.PortID
517-
if interfaces[subnetID].FloatingIP != nil {
518-
i["fip_source"] = interfaces[subnetID].FloatingIP.Source.String()
519-
i["existing_fip_id"] = interfaces[subnetID].FloatingIP.ExistingFloatingID
526+
if iOpts.FloatingIP != nil {
527+
i["fip_source"] = iOpts.FloatingIP.Source.String()
528+
i["existing_fip_id"] = iOpts.FloatingIP.ExistingFloatingID
520529
}
521530
i["ip_address"] = iface.IPAssignments[0].IPAddress.String()
522531

@@ -698,7 +707,6 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
698707
opts.SubnetID = iface["subnet_id"].(string)
699708
case types.AnySubnetInterfaceType:
700709
opts.NetworkID = iface["network_id"].(string)
701-
case types.ExternalInterfaceType:
702710
case types.ReservedFixedIpType:
703711
opts.PortID = iface["port_id"].(string)
704712
}

gcore/utils.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ func extractInstanceInterfaceIntoMap(interfaces []interface{}) (map[string]insta
228228
I.FloatingIP = &fip
229229
}
230230
Interfaces[I.SubnetID] = I
231+
Interfaces[I.NetworkID] = I
232+
Interfaces[I.PortID] = I
233+
if I.Type == types.ExternalInterfaceType {
234+
Interfaces[I.Type.String()] = I
235+
}
231236
}
232237
return Interfaces, nil
233238
}
@@ -470,8 +475,11 @@ func interfaceUniqueID(i interface{}) int {
470475
switch types.InterfaceType(iType) {
471476
case types.ReservedFixedIpType:
472477
io.WriteString(h, e["port_id"].(string))
478+
case types.AnySubnetInterfaceType:
479+
io.WriteString(h, e["network_id"].(string))
480+
case types.SubnetInterfaceType:
481+
io.WriteString(h, e["subnet_id"].(string))
473482
}
474-
io.WriteString(h, e["subnet_id"].(string))
475483
return int(binary.BigEndian.Uint64(h.Sum(nil)))
476484
}
477485

0 commit comments

Comments
 (0)