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

enhancement(bare_metal_server_network_interface_allow_float) : added new floating_bare_metal_server attribute #4115

Merged
merged 1 commit into from
Oct 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
isFloatedBareMetalServerID = "floating_bare_metal_server"
)

func ResourceIBMIsBareMetalServerNetworkInterfaceAllowFloat() *schema.Resource {
return &schema.Resource{
CreateContext: resourceIBMISBareMetalServerNetworkInterfaceAllowFloatCreate,
Expand All @@ -39,6 +43,12 @@ func ResourceIBMIsBareMetalServerNetworkInterfaceAllowFloat() *schema.Resource {
DiffSuppressFunc: flex.ApplyOnce,
Description: "Bare metal server identifier",
},

isFloatedBareMetalServerID: {
Type: schema.TypeString,
Computed: true,
Description: "Bare metal server identifier of the server to which nic is floating to",
},
isBareMetalServerNicID: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -294,7 +304,7 @@ func createVlanTypeNetworkInterfaceAllowFloat(context context.Context, d *schema
if err != nil || nic == nil {
return fmt.Errorf("[DEBUG] Create bare metal server (%s) network interface err %s\n%s", bareMetalServerId, err, response)
}

d.Set(isFloatedBareMetalServerID, bareMetalServerId)
switch reflect.TypeOf(nic).String() {
case "*vpcv1.BareMetalServerNetworkInterfaceByPci":
{
Expand Down Expand Up @@ -329,6 +339,7 @@ func createVlanTypeNetworkInterfaceAllowFloat(context context.Context, d *schema

func resourceIBMISBareMetalServerNetworkInterfaceAllowFloatRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
bareMetalServerId, nicID, err := ParseNICTerraformID(d.Id())
d.Set(isFloatedBareMetalServerID, bareMetalServerId)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -345,7 +356,7 @@ func resourceIBMISBareMetalServerNetworkInterfaceAllowFloatRead(context context.
nicIntf, response, err := sess.GetBareMetalServerNetworkInterfaceWithContext(context, options)
if (err != nil || nicIntf == nil) && response != nil {
//if original nic is not present, try fetching nic without server id
nicIntf, response, err = findNicsWithoutBMS(context, sess, nicID)
nicIntf, response, err = findNicsWithoutBMS(context, d, sess, nicID)
// response here can be either nil or not nil and if it returns 404 means nic is deleted
if response != nil && response.StatusCode == 404 {
d.SetId("")
Expand All @@ -367,7 +378,7 @@ func resourceIBMISBareMetalServerNetworkInterfaceAllowFloatRead(context context.
return nil
}

func findNicsWithoutBMS(context context.Context, sess *vpcv1.VpcV1, nicId string) (result vpcv1.BareMetalServerNetworkInterfaceIntf, response *core.DetailedResponse, err error) {
func findNicsWithoutBMS(context context.Context, d *schema.ResourceData, sess *vpcv1.VpcV1, nicId string) (result vpcv1.BareMetalServerNetworkInterfaceIntf, response *core.DetailedResponse, err error) {
// listing all servers
start := ""
allrecs := []vpcv1.BareMetalServer{}
Expand Down Expand Up @@ -396,6 +407,7 @@ func findNicsWithoutBMS(context context.Context, sess *vpcv1.VpcV1, nicId string
ID: &nicId,
}
//return response of the server nic matches
d.Set(isFloatedBareMetalServerID, *server.ID)
return sess.GetBareMetalServerNetworkInterfaceWithContext(context, options)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
}
return nil
}),
resource.TestCheckResourceAttrSet(
"ibm_is_bare_metal_server.testacc_bms", "floating_bare_metal_server"),
resource.TestCheckResourceAttrWith("ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server", func(v string) error {
if v == "" {
return fmt.Errorf("Attribute 'floating_bare_metal_server' %s is not populated", v)
}
return nil
}),
),
},
},
Expand Down Expand Up @@ -99,6 +107,14 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
}
return nil
}),
resource.TestCheckResourceAttrSet(
"ibm_is_bare_metal_server.testacc_bms", "floating_bare_metal_server"),
resource.TestCheckResourceAttrWith("ibm_is_bare_metal_server_network_interface_allow_float.bms_nic", "floating_bare_metal_server", func(v string) error {
if v == "" {
return fmt.Errorf("Attribute 'floating_bare_metal_server' %s is not populated", v)
}
return nil
}),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Review the argument references that you can specify for your resource.
In addition to the argument reference list, you can access the following attribute references after your data source is created.

- `allow_interface_to_float` - (Boolean) Indicates if the interface can float to any other server within the same resource_group. The interface will float automatically if the network detects a GARP or RARP on another bare metal server in the resource group. Applies only to vlan type interfaces.
- `floating_bare_metal_server` - (String) Bare metal server id of the server to which the network interface is floating to. (Same as `bare_metal_server` if its not floating)
- `floating_ips` - (List) The floating IPs associated with this network interface.

Nested scheme for `floating_ips`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ resource "ibm_is_bare_metal_server_network_interface_floating_ip" "bms_nic_fip"

```

## Example usage
The following example shows how to create a allow float network interface and associate a floating IP address to an allow float network interface on the server.

```
resource "ibm_is_floating_ip" "fip2" {
name = "testfip2"
zone = "us-south-3"
}

resource "ibm_is_bare_metal_server_network_interface_allow_float" "allow_float" {
bare_metal_server = ibm_is_bare_metal_server.bms.id
subnet = ibm_is_subnet.subnet.id
name = "eth2"
allow_ip_spoofing = false
vlan = 101
}

resource "ibm_is_bare_metal_server_network_interface_floating_ip" "bms_nic_fip" {
bare_metal_server = ibm_is_bare_metal_server_network_interface_allow_float.allow_float.floating_bare_metal_server
network_interface = ibm_is_bare_metal_server_network_interface_allow_float.allow_float.network_interface
floating_ip = ibm_is_floating_ip.fip2.id
}

```


## Timeouts
The `ibm_is_bare_metal_server_network_interface_floating_ip` provides the following [Timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options:

Expand Down