Skip to content

Commit

Permalink
Merge pull request #322 from NetApp/old-name-networking
Browse files Browse the repository at this point in the history
Old name networking
  • Loading branch information
carchi8py authored Oct 29, 2024
2 parents d5cede9 + 61cbcb2 commit 73ee0aa
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func NewIPInterfaceDataSource() datasource.DataSource {
}
}

// NewIPInterfaceDataSourceAlias is a helper function to simplify the provider implementation.
func NewIPInterfaceDataSourceAlias() datasource.DataSource {
return &IPInterfaceDataSource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_interface_data_source",
},
}
}

// IPInterfaceDataSource defines the data source implementation.
type IPInterfaceDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/networking/network_ip_interface_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func NewIPInterfaceResource() resource.Resource {
}
}

// NewIPInterfaceResourceAlias is a helper function to simplify the provider implementation.
func NewIPInterfaceResourceAlias() resource.Resource {
return &IPInterfaceResource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_interface_resource",
},
}
}

// IPInterfaceResource defines the resource implementation.
type IPInterfaceResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package networking_test

import (
"fmt"
"os"
"regexp"
"testing"

ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNetworkIpInterfaceResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// non-existant SVM return code 2621462. Must happen before create/read
{
Config: testAccNetworkIPInterfaceResourceConfigAlias("non-existant", "10.10.10.10", "ontap_cluster_1-01"),
ExpectError: regexp.MustCompile("2621462"),
},
// non-existant home node
{
Config: testAccNetworkIPInterfaceResourceConfigAlias("svm0", "10.10.10.10", "non-existant_home_node"),
ExpectError: regexp.MustCompile("393271"),
},
// Create and Read
{
Config: testAccNetworkIPInterfaceResourceConfigAlias("svm0", "10.10.10.10", "ontap_cluster_1-01"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "name", "test-interface"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "svm_name", "svm0"),
),
},
// Update and Read
{
Config: testAccNetworkIPInterfaceResourceConfigAlias("svm0", "10.10.10.20", "ontap_cluster_1-01"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "name", "test-interface"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "ip.address", "10.10.10.20"),
),
},
// Test importing a resource
{
ResourceName: "netapp-ontap_networking_ip_interface_resource.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s,%s", "test-interface", "svm0", "cluster4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "name", "test-interface"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_interface_resource.example", "ip.address", "10.10.10.20"),
),
},
},
})
}

func testAccNetworkIPInterfaceResourceConfigAlias(svmName, address, homeNode string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_networking_ip_interface_resource" "example" {
cx_profile_name = "cluster4"
name = "test-interface"
svm_name = "%s"
ip = {
address = "%s"
netmask = 18
}
location = {
home_port = "e0d"
home_node = "%s"
}
}
`, host, admin, password, svmName, address, homeNode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ func NewIPInterfacesDataSource() datasource.DataSource {
}
}

// NewIPInterfacesDataSourceAlias is a helper function to simplify the provider implementation.
func NewIPInterfacesDataSourceAlias() datasource.DataSource {
return &IPInterfacesDataSource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_interfaces_data_source",
},
}
}

// IPInterfacesDataSource defines the data source implementation.
type IPInterfacesDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/networking/network_ip_route_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func NewIPRouteDataSource() datasource.DataSource {
}
}

// NewIPRouteDataSourceAlias is a helper function to simplify the provider implementation.
func NewIPRouteDataSourceAlias() datasource.DataSource {
return &IPRouteDataSource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_route_data_source",
},
}
}

// IPRouteDataSource defines the data source implementation.
type IPRouteDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
9 changes: 9 additions & 0 deletions internal/provider/networking/network_ip_route_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func NewIPRouteResource() resource.Resource {
}
}

// NewIPRouteResourceAlias is a helper function to simplify the provider implementation.
func NewIPRouteResourceAlias() resource.Resource {
return &IPRouteResource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_route_resource",
},
}
}

// IPRouteResource defines the resource implementation.
type IPRouteResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
148 changes: 148 additions & 0 deletions internal/provider/networking/network_ip_route_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package networking_test

import (
"fmt"
"os"
"regexp"
"testing"

ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNetworkIpRouteResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Missing Required argument
{
Config: testAccNetworkIPIRouteResourceConfigAliasMissingVars("non-existent"),
ExpectError: regexp.MustCompile("Missing required argument"),
},
// Non existent SVM
{
Config: testAccNetworkIPIRouteResourceConfigAlias("non-existent"),
ExpectError: regexp.MustCompile("2621462"),
},
// Test create with no gateway
{
Config: testAccNetworkIPIRouteResourceConfigAlias("ansibleSVM"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "svm_name", "ansibleSVM"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "destination.address", "0.0.0.0"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "destination.netmask", "0"),
),
},
// test create with a gateway
{
Config: testAccNetworkIPIRouteResourceWithGatewayConfigAlias("ansibleSVM", "10.10.10.254", 20),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "svm_name", "ansibleSVM"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "destination.address", "10.10.10.254"),
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "destination.netmask", "20"),
),
},
// Import and read
{
ResourceName: "netapp-ontap_networking_ip_route_resource.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s,%s", "carchi-test", "10.10.10.254", "cluster4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_networking_ip_route_resource.example", "svm_name", "carchi-test"),
),
},
},
})
}

func testAccNetworkIPIRouteResourceConfigAlias(svmName string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_networking_ip_route_resource" "example" {
cx_profile_name = "cluster4"
svm_name = "%s"
gateway = "10.10.10.1"
}
`, host, admin, password, svmName)
}

func testAccNetworkIPIRouteResourceWithGatewayConfigAlias(svmName string, address string, netmask int) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_networking_ip_route_resource" "example" {
cx_profile_name = "cluster4"
svm_name = "%s"
gateway = "10.10.10.1"
destination = {
address = "%s"
netmask = %d
}
}
`, host, admin, password, svmName, address, netmask)
}

func testAccNetworkIPIRouteResourceConfigAliasMissingVars(svmName string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_networking_ip_route_resource" "example" {
cx_profile_name = "cluster4"
svm_name = "%s"
}
`, host, admin, password, svmName)
}
9 changes: 9 additions & 0 deletions internal/provider/networking/network_ip_routes_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func NewIPRoutesDataSource() datasource.DataSource {
}
}

// NewIPRoutesDataSourceAlias is a helper function to simplify the provider implementation.
func NewIPRoutesDataSourceAlias() datasource.DataSource {
return &IPRoutesDataSource{
config: connection.ResourceOrDataSourceConfig{
Name: "networking_ip_routes_data_source",
},
}
}

// IPRoutesDataSource defines the data source implementation.
type IPRoutesDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ func (p *ONTAPProvider) Resources(ctx context.Context) []func() resource.Resourc
cluster.NewClusterScheduleResourceAlias,
name_services.NewNameServicesDNSResourceAlias,
name_services.NewNameServicesLDAPResourceAlias,
networking.NewIPInterfaceResourceAlias,
networking.NewIPRouteResourceAlias,
}
}

Expand Down Expand Up @@ -351,6 +353,10 @@ func (p *ONTAPProvider) DataSources(ctx context.Context) []func() datasource.Dat
name_services.NewNameServicesDNSsDataSourceAlias,
name_services.NewNameServicesLDAPDataSourceAlias,
name_services.NewNameServicesLDAPsDataSourceAlias,
networking.NewIPInterfaceDataSourceAlias,
networking.NewIPInterfacesDataSourceAlias,
networking.NewIPRouteDataSourceAlias,
networking.NewIPRoutesDataSourceAlias,
}
}

Expand Down

0 comments on commit 73ee0aa

Please sign in to comment.