0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-02 03:22:59 +00:00
terraform-provider-proxmox/fwprovider/tests/resource_linux_bridge_test.go
Pavel Boldyrev 4aed7cb085
fix(network): multiple fixes to network_linux_bridge resource (#1095)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2024-03-08 19:47:43 -05:00

99 lines
2.8 KiB
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package tests
import (
"context"
"fmt"
"testing"
"github.com/brianvoe/gofakeit/v7"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
func TestAccResourceLinuxBridge(t *testing.T) {
accProviders := testAccMuxProviders(context.Background(), t)
iface := fmt.Sprintf("vmbr%d", gofakeit.Number(10, 9999))
ipV4cidr1 := fmt.Sprintf("%s/24", gofakeit.IPv4Address())
ipV4cidr2 := fmt.Sprintf("%s/24", gofakeit.IPv4Address())
ipV6cidr := "FE80:0000:0000:0000:0202:B3FF:FE1E:8329/64"
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: accProviders,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: fmt.Sprintf(`
resource "proxmox_virtual_environment_network_linux_bridge" "test" {
address = "%s"
autostart = true
comment = "created by terraform"
mtu = 1499
name = "%s"
node_name = "%s"
vlan_aware = true
}
`, ipV4cidr1, iface, accTestNodeName),
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_network_linux_bridge.test", map[string]string{
"address": ipV4cidr1,
"autostart": "true",
"comment": "created by terraform",
"mtu": "1499",
"name": iface,
"vlan_aware": "true",
}),
testResourceAttributesSet("proxmox_virtual_environment_network_linux_bridge.test", []string{
"id",
}),
),
},
// Update testing
{
Config: fmt.Sprintf(`
resource "proxmox_virtual_environment_network_linux_bridge" "test" {
address = "%s"
address6 = "%s"
autostart = false
comment = ""
mtu = null
name = "%s"
node_name = "%s"
vlan_aware = false
}`, ipV4cidr2, ipV6cidr, iface, accTestNodeName),
Check: resource.ComposeTestCheckFunc(
testResourceAttributes("proxmox_virtual_environment_network_linux_bridge.test", map[string]string{
"address": ipV4cidr2,
"address6": ipV6cidr,
"autostart": "false",
"comment": "",
"name": iface,
"vlan_aware": "false",
}),
testNoResourceAttributesSet("proxmox_virtual_environment_network_linux_bridge.test", []string{
"mtu",
}),
testResourceAttributesSet("proxmox_virtual_environment_network_linux_bridge.test", []string{
"id",
}),
),
},
// ImportState testing
{
ResourceName: "proxmox_virtual_environment_network_linux_bridge.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"comment", // "" comments translates to null in the PVE, but nulls are not imported as empty strings.
},
},
},
})
}