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

Add old name support for SVM #327

Open
wants to merge 1 commit into
base: old-name-storage
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (p *ONTAPProvider) Resources(ctx context.Context) []func() resource.Resourc
storage.NewSnapshotPolicyResourceAlias,
storage.NewStorageVolumeResourceAlias,
storage.NewStorageVolumeSnapshotResourceAlias,
svm.NewSVMPeerResourceAlias,
svm.NewSvmResourceAlias,
}
}

Expand Down Expand Up @@ -417,6 +419,10 @@ func (p *ONTAPProvider) DataSources(ctx context.Context) []func() datasource.Dat
storage.NewStorageVolumeSnapshotDataSourceAlias,
storage.NewStorageVolumeSnapshotsDataSourceAlias,
storage.NewStorageVolumesDataSourceAlias,
svm.NewSvmDataSourceAlias,
svm.NewSVMPeerDataSourceAlias,
svm.NewSVMPeersDataSourceAlias,
svm.NewSvmsDataSourceAlias,
}
}

Expand Down
10 changes: 10 additions & 0 deletions internal/provider/svm/svm_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package svm
import (
"context"
"fmt"

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

"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand All @@ -25,6 +26,15 @@ func NewSvmDataSource() datasource.DataSource {
}
}

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

// SvmDataSource defines the data source implementation.
type SvmDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/svm/svm_peer_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package svm
import (
"context"
"fmt"

"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/snapmirror"

Expand All @@ -26,6 +27,15 @@ func NewSVMPeerDataSource() datasource.DataSource {
}
}

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

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

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

// SVMPeersResource defines the resource implementation.
type SVMPeersResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
98 changes: 98 additions & 0 deletions internal/provider/svm/svm_peer_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package svm_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 TestAccSvmPeerResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Test cluster peer non existant to do svm peer
{
Config: testAccSvmPeerResourceConfigAlias("testme", "testme2", "abcd", "snapmirror"),
ExpectError: regexp.MustCompile("9895941"),
},
// Testing in VSIM is failing to peer
// // Create svm peer and read
// {
// Config: testAccSvmPeersResourceConfig("acc_test_peer2", "acc_test2", "swenjuncluster-1", "snapmirror"),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "svm.name", "acc_test_peer2"),
// ),
// },
// // Update applications
// {
// Config: testAccSvmPeersResourceConfig("acc_test_peer2", "acc_test2", "swenjuncluster-1", "flexcache"),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "applications.0", "flexcache"),
// resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resources.example", "svm.name", "acc_test_peer2"),
// ),
// },
// Import and read
{
ResourceName: "netapp-ontap_svm_peers_resource.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "terraform", "tf_peer", "swenjuncluster-1", "cluster4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resource.example", "svm.name", "snapmirror_dest_dp"),
),
},
},
})
}
func testAccSvmPeerResourceConfigAlias(svm, peerSvm, peerCluster, applications string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST5")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
password2 := os.Getenv("TF_ACC_NETAPP_PASS2")
host2 := os.Getenv("TF_ACC_NETAPP_HOST2")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_HOST5, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS2 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
},
{
name = "cluster3"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}

resource "netapp-ontap_svm_peers_resource" "example" {
cx_profile_name = "cluster4"
svm = {
name = "%s"
}
peer = {
svm = {
name = "%s"
}
cluster = {
name = "%s"
}
peer_cx_profile_name = "cluster3"
}
applications = ["%s"]
}`, host, admin, password2, host2, admin, password2, svm, peerSvm, peerCluster, applications)
}
10 changes: 10 additions & 0 deletions internal/provider/svm/svm_peers_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package svm
import (
"context"
"fmt"

"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/snapmirror"

Expand All @@ -26,6 +27,15 @@ func NewSVMPeersDataSource() datasource.DataSource {
}
}

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

// SVMPeersDataSource defines the data source implementation.
type SVMPeersDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/svm/svm_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package svm
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strings"

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

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand All @@ -30,6 +31,15 @@ func NewSvmResource() resource.Resource {
}
}

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

// SvmResource defines the resource implementation.
type SvmResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
123 changes: 123 additions & 0 deletions internal/provider/svm/svm_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package svm_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 TestAccSvmResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccSvmResourceConfigAlias("tfsvm4", "test", "default"),
Check: resource.ComposeTestCheckFunc(
// Check to see the svm name is correct,
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4"),
// Check to see if Ipspace is set correctly
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "ipspace", "ansibleIpspace_newname"),
// Check that a ID has been set (we don't know what the vaule is as it changes
resource.TestCheckResourceAttrSet("netapp-ontap_svm_resource.example", "id"),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "test")),
},
// Update a comment
{
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", "default"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")),
},
// Update a comment with an empty string
{
Config: testAccSvmResourceConfigAlias("tfsvm4", "", "default"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", ""),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")),
},
// Update snapshot policy default-1weekly and comment "carchi8py was here"
{
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", "default-1weekly"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "snapshot_policy", "default-1weekly"),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm4")),
},
// Update snapshot policy with empty string
{
Config: testAccSvmResourceConfigAlias("tfsvm4", "carchi8py was here", ""),
ExpectError: regexp.MustCompile("cannot be updated with empty string"),
},
// change SVM name
{
Config: testAccSvmResourceConfigAlias("tfsvm3", "carchi8py was here", "default"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "comment", "carchi8py was here"),
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "tfsvm3")),
},
// Fail if the name already exist
{
Config: testAccSvmResourceConfigAlias("svm5", "carchi8py was here", "default"),
ExpectError: regexp.MustCompile("13434908"),
},
// Import and read
{
ResourceName: "netapp-ontap_svm_resource.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s", "ansibleSVM", "cluster4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_svm_resource.example", "name", "ansibleSVM"),
),
},
},
})
}
func testAccSvmResourceConfigAlias(svm, comment string, snapshotPolicy 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_svm_resource" "example" {
cx_profile_name = "cluster4"
name = "%s"
ipspace = "ansibleIpspace_newname"
comment = "%s"
snapshot_policy = "%s"
subtype = "default"
language = "en_us.utf_8"
aggregates = [
{
name = "aggr1"
},
{
name = "aggr2"
},
{
name = "aggr3"
},
]
max_volumes = "unlimited"
}`, host, admin, password, svm, comment, snapshotPolicy)
}
10 changes: 10 additions & 0 deletions internal/provider/svm/svms_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package svm
import (
"context"
"fmt"

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

"github.com/hashicorp/terraform-plugin-framework/datasource"
Expand All @@ -25,6 +26,15 @@ func NewSvmsDataSource() datasource.DataSource {
}
}

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

// SvmsDataSource defines the data source implementation.
type SvmsDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
Loading