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

F #547: Add floating_only VR nic IP allocation #549

Merged
merged 1 commit into from
May 22, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FEATURES:

* resources/opennebula_virtual_network: allow to modify the user owning the resource (#529)
* resources/opennebula_virtual_machine: add nil checks before type casting (#530)
* resources/opennebula_virtual_router_nic: add floating_only nic argument (#547)

ENHANCEMENTS:

Expand Down
13 changes: 13 additions & 0 deletions opennebula/resource_opennebula_virtual_router_nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func resourceOpennebulaVirtualRouterNIC() *schema.Resource {
Default: false,
ForceNew: true,
},
"floating_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -125,6 +131,11 @@ func resourceOpennebulaVirtualRouterNICCreate(ctx context.Context, d *schema.Res
nicTpl.Add("FLOATING_IP", "YES")
}
}
if v, ok := d.GetOk("floating_only"); ok {
if v.(bool) {
nicTpl.Add("FLOATING_ONLY", "YES")
}
}

// wait before checking NIC
nicID, err := vrNICAttach(ctx, d.Timeout(schema.TimeoutCreate), controller, vRouterID, nicTpl)
Expand Down Expand Up @@ -197,6 +208,7 @@ func resourceOpennebulaVirtualRouterNICRead(ctx context.Context, d *schema.Resou
}

floatingIP, _ := nic.GetStr("FLOATING_IP")
floatingOnly, _ := nic.GetStr("FLOATING_ONLY")

d.Set("network_id", networkID)
d.Set("virtual_router_id", vr.ID)
Expand All @@ -206,6 +218,7 @@ func resourceOpennebulaVirtualRouterNICRead(ctx context.Context, d *schema.Resou
d.Set("virtio_queues", virtioQueues)
d.Set("security_groups", sg)
d.Set("floating_ip", strings.ToUpper(floatingIP) == "YES")
d.Set("floating_only", strings.ToUpper(floatingOnly) == "YES")

return nil
}
Expand Down
5 changes: 5 additions & 0 deletions opennebula/resource_opennebula_virtual_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func TestAccVirtualRouter(t *testing.T) {
resource.TestCheckResourceAttrSet("opennebula_virtual_router_nic.nic1", "network_id"),
resource.TestCheckResourceAttrSet("opennebula_virtual_router_nic.nic2", "network_id"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic1", "floating_ip", "true"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic1", "floating_only", "true"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic2", "floating_ip", "false"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic2", "floating_only", "false"),
testAccCheckVirtualRouterPermissions(&shared.Permissions{
OwnerU: 1,
OwnerM: 1,
Expand All @@ -127,7 +129,9 @@ func TestAccVirtualRouter(t *testing.T) {
resource.TestCheckResourceAttrSet("opennebula_virtual_router_nic.nic1", "network_id"),
resource.TestCheckResourceAttrSet("opennebula_virtual_router_nic.nic2", "network_id"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic1", "floating_ip", "false"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic1", "floating_only", "false"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic2", "floating_ip", "false"),
resource.TestCheckResourceAttr("opennebula_virtual_router_nic.nic2", "floating_only", "false"),
testAccCheckVirtualRouterPermissions(&shared.Permissions{
OwnerU: 1,
OwnerM: 1,
Expand Down Expand Up @@ -409,6 +413,7 @@ resource "opennebula_virtual_router_nic" "nic2" {

resource "opennebula_virtual_router_nic" "nic1" {
floating_ip = true
floating_only = true
virtual_router_id = opennebula_virtual_router.test.id
network_id = opennebula_virtual_network.network1.id
}
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/virtual_router_nic.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ resource "opennebula_virtual_network" "example" {

resource "opennebula_virtual_router_nic" "example1" {
floating_ip = true
floating_only = true
virtual_router_id = opennebula_virtual_router.example.id
network_id = opennebula_virtual_network.example.id
}
Expand All @@ -112,6 +113,7 @@ The following arguments are supported:
* `physical_device` - (Optional) Physical device hosting the virtual network.
* `security_groups` - (Optional) List of security group IDs to use on the virtual network.
* `floating_ip` - (Optional) Allocate floating IP for the NIC. Defaults to `false`.
* `floating_only` - (Optional) Do not allocate IP for the NIC. Defaults to `false`.

## Attribute Reference

Expand All @@ -123,6 +125,7 @@ The following attribute are exported:
* `physical_device` - Physical device hosting the virtual network.
* `security_groups` - List of security group IDs to use on the virtual network.
* `floating_ip` - Allocate floating IP for the NIC. Defaults to `false`.
* `floating_only` - (Optional) Do not allocate IP for the NIC. Defaults to `false`.

## Import

Expand Down
Loading