Skip to content

Commit

Permalink
refactor(network): prepare to implement upcloud_network with plugin…
Browse files Browse the repository at this point in the history
… framework
  • Loading branch information
kangasta committed Apr 22, 2024
1 parent 3fda798 commit a225063
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/hashicorp/go-cty/cty"
)

func ResourceNetwork() *schema.Resource {
func SDKV2ResourceNetwork() *schema.Resource {
return &schema.Resource{
Description: "This resource represents an SDN private network that cloud servers from the same zone can be attached to.",
ReadContext: resourceNetworkRead,
Expand Down
40 changes: 28 additions & 12 deletions upcloud/resource_upcloud_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ func TestAccUpCloudNetwork_basic(t *testing.T) {
cidr := fmt.Sprintf("10.0.%d.0/24", subnet)
gateway := fmt.Sprintf("10.0.%d.1", subnet)

config := testAccNetworkConfig(
netName,
"fi-hel1",
cidr,
gateway,
true,
false,
false,
[]string{"10.0.0.2", "10.0.0.3"},
[]string{"192.168.0.0/24", "192.168.100.0/32"},
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories(&providers),
Steps: []resource.TestStep{
{
Config: testAccNetworkConfig(
netName,
"fi-hel1",
cidr,
gateway,
true,
false,
false,
[]string{"10.0.0.2", "10.0.0.3"},
[]string{"192.168.0.0/24", "192.168.100.0/32"},
),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
testAccNetworkExists("upcloud_network.test_network"),
resource.TestCheckResourceAttr("upcloud_network.test_network", "name", netName),
Expand All @@ -50,6 +52,12 @@ func TestAccUpCloudNetwork_basic(t *testing.T) {
resource.TestCheckResourceAttr("upcloud_network.test_network", "ip_network.0.dhcp_routes.#", "2"),
),
},
{
Config: config,
ResourceName: "upcloud_network.test_network",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -108,12 +116,14 @@ func TestAccUpCloudNetwork_withRouter(t *testing.T) {
cidr := fmt.Sprintf("10.0.%d.0/24", subnet)
gateway := fmt.Sprintf("10.0.%d.1", subnet)

config := testAccNetworkConfig(netName, "fi-hel1", cidr, gateway, true, false, true, nil, nil)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories(&providers),
Steps: []resource.TestStep{
{
Config: testAccNetworkConfig(netName, "fi-hel1", cidr, gateway, true, false, true, nil, nil),
Config: config,
Check: resource.ComposeAggregateTestCheckFunc(
testAccNetworkExists("upcloud_network.test_network"),
resource.TestCheckResourceAttr("upcloud_network.test_network", "name", netName),
Expand All @@ -126,6 +136,12 @@ func TestAccUpCloudNetwork_withRouter(t *testing.T) {
testAccNetworkRouterIsSet("upcloud_network.test_network", "upcloud_router.test_network_router"),
),
},
{
Config: config,
ResourceName: "upcloud_network.test_network",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion upcloud/sdkv2_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Provider() *schema.Provider {
"upcloud_storage": storage.ResourceStorage(),
"upcloud_firewall_rules": firewall.ResourceFirewallRules(),
"upcloud_tag": tag.ResourceTag(),
"upcloud_network": network.ResourceNetwork(),
"upcloud_network": network.SDKV2ResourceNetwork(),
"upcloud_gateway": gateway.ResourceGateway(),
"upcloud_gateway_connection": gateway.ResourceConnection(),
"upcloud_gateway_connection_tunnel": gateway.ResourceTunnel(),
Expand Down

0 comments on commit a225063

Please sign in to comment.