From b8b46f47813306218993742f268f052b659a69b2 Mon Sep 17 00:00:00 2001 From: Chris Archibald Date: Mon, 14 Oct 2024 16:35:35 -0700 Subject: [PATCH] add support for old name for storage --- internal/provider/provider.go | 18 ++ .../storage/storage_aggregate_data_source.go | 9 + .../storage/storage_aggregate_resource.go | 12 +- .../storage_aggregate_resource_alias_test.go | 70 ++++++++ .../storage/storage_aggregates_data_source.go | 10 ++ .../storage/storage_flexcache_data_source.go | 10 ++ .../storage/storage_flexcache_resource.go | 12 +- .../storage_flexcache_resource_alias_test.go | 159 +++++++++++++++++ .../storage/storage_flexcaches_data_source.go | 12 +- .../storage/storage_lun_data_source.go | 9 + .../provider/storage/storage_lun_resource.go | 9 + .../storage_lun_resource_alias_test.go | 164 ++++++++++++++++++ .../storage/storage_luns_data_source.go | 9 + .../storage_snapshot_policies_data_source.go | 10 ++ .../storage_snapshot_policy_alias_test.go | 92 ++++++++++ .../storage_snapshot_policy_data_source.go | 10 ++ .../storage_snapshot_policy_resource.go | 12 +- .../storage/storage_volume_data_source.go | 9 + .../storage/storage_volume_resource.go | 9 + .../storage_volume_resource_alias_test.go | 164 ++++++++++++++++++ .../storage_volume_snapshot_data_source.go | 10 ++ .../storage_volume_snapshot_resource.go | 12 +- ...age_volume_snapshot_resource_alias_test.go | 85 +++++++++ .../storage_volume_snapshots_data_source.go | 10 ++ .../storage/storage_volumes_data_source.go | 10 ++ 25 files changed, 931 insertions(+), 5 deletions(-) create mode 100644 internal/provider/storage/storage_aggregate_resource_alias_test.go create mode 100644 internal/provider/storage/storage_flexcache_resource_alias_test.go create mode 100644 internal/provider/storage/storage_lun_resource_alias_test.go create mode 100644 internal/provider/storage/storage_snapshot_policy_alias_test.go create mode 100644 internal/provider/storage/storage_volume_resource_alias_test.go create mode 100644 internal/provider/storage/storage_volume_snapshot_resource_alias_test.go diff --git a/internal/provider/provider.go b/internal/provider/provider.go index cb94e84c..9660c1de 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -275,6 +275,12 @@ func (p *ONTAPProvider) Resources(ctx context.Context) []func() resource.Resourc security.NewSecurityAccountResourceAlias, snapmirror.NewSnapmirrorPolicyResourceAlias, snapmirror.NewSnapmirrorResourceAlias, + storage.NewAggregateResourceAlias, + storage.NewStorageFlexcacheRsourceAlias, + storage.NewStorageLunResourceAlias, + storage.NewSnapshotPolicyResourceAlias, + storage.NewStorageVolumeResourceAlias, + storage.NewStorageVolumeSnapshotResourceAlias, } } @@ -399,6 +405,18 @@ func (p *ONTAPProvider) DataSources(ctx context.Context) []func() datasource.Dat snapmirror.NewSnapmirrorPoliciesDataSourceAlias, snapmirror.NewSnapmirrorPolicyDataSourceAlias, snapmirror.NewSnapmirrorsDataSourceAlias, + storage.NewStorageAggregateDataSourceAlias, + storage.NewStorageAggregatesDataSourceAlias, + storage.NewStorageFlexcacheDataSourceAlias, + storage.NewStorageFlexcachesDataSourceAlias, + storage.NewStorageLunDataSourceAlias, + storage.NewStorageLunsDataSourceAlias, + storage.NewSnapshotPoliciesDataSourceAlias, + storage.NewSnapshotPolicyDataSourceAlias, + storage.NewStorageVolumeDataSourceAlias, + storage.NewStorageVolumeSnapshotDataSourceAlias, + storage.NewStorageVolumeSnapshotsDataSourceAlias, + storage.NewStorageVolumesDataSourceAlias, } } diff --git a/internal/provider/storage/storage_aggregate_data_source.go b/internal/provider/storage/storage_aggregate_data_source.go index 4718fc72..79133a51 100644 --- a/internal/provider/storage/storage_aggregate_data_source.go +++ b/internal/provider/storage/storage_aggregate_data_source.go @@ -26,6 +26,15 @@ func NewStorageAggregateDataSource() datasource.DataSource { } } +// NewStorageAggregateDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageAggregateDataSourceAlias() datasource.DataSource { + return &StorageAggregateDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_aggregate_data_source", + }, + } +} + // StorageAggregateDataSource defines the data source implementation. type StorageAggregateDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_aggregate_resource.go b/internal/provider/storage/storage_aggregate_resource.go index 88afb230..d623d85a 100644 --- a/internal/provider/storage/storage_aggregate_resource.go +++ b/internal/provider/storage/storage_aggregate_resource.go @@ -3,9 +3,10 @@ package storage 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-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -37,6 +38,15 @@ func NewAggregateResource() resource.Resource { } } +// NewAggregateResourceAlias is a helper function to simplify the provider implementation. +func NewAggregateResourceAlias() resource.Resource { + return &AggregateResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_aggregate_resource", + }, + } +} + // AggregateResource defines the resource implementation. type AggregateResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_aggregate_resource_alias_test.go b/internal/provider/storage/storage_aggregate_resource_alias_test.go new file mode 100644 index 00000000..cc1cbcc6 --- /dev/null +++ b/internal/provider/storage/storage_aggregate_resource_alias_test.go @@ -0,0 +1,70 @@ +package storage_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 TestAccStorageAggregateResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccStorageAggregateResourceConfigAlias("non-existant"), + ExpectError: regexp.MustCompile("is an invalid value"), + }, + { + Config: testAccStorageAggregateResourceConfigAlias("swenjun-vsim2"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_aggregate_resource.example", "name", "acc_test_aggr"), + resource.TestCheckNoResourceAttr("netapp-ontap_storage_aggregate_resource.example", "vol"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_aggregate_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s", "acc_test_aggr", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_aggregate_resource.example", "name", "acc_test_aggr"), + ), + }, + }, + }) +} + +func testAccStorageAggregateResourceConfigAlias(node string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST2") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS2 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_storage_aggregate_resource" "example" { + cx_profile_name = "cluster4" + node = "%s" + name = "acc_test_aggr" + disk_count = 5 +}`, host, admin, password, node) +} diff --git a/internal/provider/storage/storage_aggregates_data_source.go b/internal/provider/storage/storage_aggregates_data_source.go index 7e5244e1..7c9ea736 100644 --- a/internal/provider/storage/storage_aggregates_data_source.go +++ b/internal/provider/storage/storage_aggregates_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -25,6 +26,15 @@ func NewStorageAggregatesDataSource() datasource.DataSource { } } +// NewStorageAggregatesDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageAggregatesDataSourceAlias() datasource.DataSource { + return &StorageAggregatesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_aggregates_data_source", + }, + } +} + // StorageAggregatesDataSource defines the data source implementation. type StorageAggregatesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_flexcache_data_source.go b/internal/provider/storage/storage_flexcache_data_source.go index ffb0e005..4af9bc85 100644 --- a/internal/provider/storage/storage_flexcache_data_source.go +++ b/internal/provider/storage/storage_flexcache_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -25,6 +26,15 @@ func NewStorageFlexcacheDataSource() datasource.DataSource { } } +// NewStorageFlexcacheDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageFlexcacheDataSourceAlias() datasource.DataSource { + return &StorageFlexcacheDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_flexcache_data_source", + }, + } +} + // StorageFlexcacheDataSource implements the datasource interface and defines the data model for the resource. type StorageFlexcacheDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_flexcache_resource.go b/internal/provider/storage/storage_flexcache_resource.go index ffe3312d..e5abd961 100644 --- a/internal/provider/storage/storage_flexcache_resource.go +++ b/internal/provider/storage/storage_flexcache_resource.go @@ -3,10 +3,11 @@ package storage import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "log" "strings" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -33,6 +34,15 @@ func NewStorageFlexcacheRsource() resource.Resource { } } +// NewStorageFlexcacheRsourceAlias is a helper function to simplify the provider implementation. +func NewStorageFlexcacheRsourceAlias() resource.Resource { + return &StorageFlexcacheResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_flexcache_resource", + }, + } +} + // StorageFlexcacheResource defines the resource implementation. type StorageFlexcacheResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_flexcache_resource_alias_test.go b/internal/provider/storage/storage_flexcache_resource_alias_test.go new file mode 100644 index 00000000..b9f981ad --- /dev/null +++ b/internal/provider/storage/storage_flexcache_resource_alias_test.go @@ -0,0 +1,159 @@ +package storage_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 TestAccStorageFlexcacheResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test non existant SVM + { + Config: testAccStorageFlexcacheResourceConfigAlias("non-existant", "terraformTest4"), + ExpectError: regexp.MustCompile("2621462"), + }, + // test bad volume name + { + Config: testAccStorageFlexcacheResourceConfigAlias("non-existant", "name-cant-have-dashes"), + ExpectError: regexp.MustCompile("917888"), + }, + // Test create the resource + { + Config: testAccStorageFlexcacheResourceConfigAlias("acc_test", "accFlexcache"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_flexcache_resource.example", "name", "accFlexcache"), + resource.TestCheckNoResourceAttr("netapp-ontap_storage_flexcache_resource.example", "volname"), + ), + }, + // Test create the resource with junction path + { + Config: testAccStorageFlexcacheResourcePathConfigAlias("acc_test", "accFlexcacheJP", "/accFlexcachejp"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_flexcache_resource.jpexample", "name", "accFlexcacheJP"), + resource.TestCheckResourceAttr("netapp-ontap_storage_flexcache_resource.jpexample", "junction_path", "/accFlexcachejp"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_flexcache_resource.jpexample", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "accFlexcacheJP", "acc_test", "cluster5"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_flexcache_resource.jpexample", "name", "accFlexcache"), + ), + }, + }, + }) +} + +func testAccStorageFlexcacheResourceConfigAlias(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST2") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + 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 = "cluster5" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_storage_flexcache_resource" "example" { + cx_profile_name = "cluster5" + name = "%s" + svm_name = "%s" + + origins = [ + { + volume = { + name = "acc_test_storage_flexcache_origin_volume" + }, + svm = { + name = "acc_test" + } + } + ] + size = 200 + size_unit = "mb" + guarantee = { + type = "none" + } + dr_cache = false + global_file_locking_enabled = false + aggregates = [ + { + name = "acc_test" + } + ] +}`, host, admin, password, volName, svm) +} + +func testAccStorageFlexcacheResourcePathConfigAlias(svm, volName string, junctionPath string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST2") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + 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 = "cluster5" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} +resource "netapp-ontap_storage_flexcache_resource" "jpexample" { + cx_profile_name = "cluster5" + name = "%s" + svm_name = "%s" + origins = [ + { + volume = { + name = "acc_test_storage_flexcache_origin_volume" + }, + svm = { + name = "acc_test" + } + } + ] + size = 200 + size_unit = "mb" + guarantee = { + type = "none" + } + dr_cache = false + junction_path = "%s" + global_file_locking_enabled = false + aggregates = [ + { + name = "acc_test" + } + ] +}`, host, admin, password, volName, svm, junctionPath) +} diff --git a/internal/provider/storage/storage_flexcaches_data_source.go b/internal/provider/storage/storage_flexcaches_data_source.go index 0f0644ab..281de987 100644 --- a/internal/provider/storage/storage_flexcaches_data_source.go +++ b/internal/provider/storage/storage_flexcaches_data_source.go @@ -3,9 +3,10 @@ package storage import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "log" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -27,6 +28,15 @@ func NewStorageFlexcachesDataSource() datasource.DataSource { } } +// NewStorageFlexcachesDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageFlexcachesDataSourceAlias() datasource.DataSource { + return &StorageFlexcachesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_flexcaches_data_source", + }, + } +} + // StorageFlexcachesDataSource defines the resource implementation. type StorageFlexcachesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_lun_data_source.go b/internal/provider/storage/storage_lun_data_source.go index 27cffeb2..818afe76 100644 --- a/internal/provider/storage/storage_lun_data_source.go +++ b/internal/provider/storage/storage_lun_data_source.go @@ -25,6 +25,15 @@ func NewStorageLunDataSource() datasource.DataSource { } } +// NewStorageLunDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageLunDataSourceAlias() datasource.DataSource { + return &StorageLunDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_lun_data_source", + }, + } +} + // StorageLunDataSource defines the data source implementation. type StorageLunDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_lun_resource.go b/internal/provider/storage/storage_lun_resource.go index cef10d7f..267d6b87 100644 --- a/internal/provider/storage/storage_lun_resource.go +++ b/internal/provider/storage/storage_lun_resource.go @@ -31,6 +31,15 @@ func NewStorageLunResource() resource.Resource { } } +// NewStorageLunResourceAlias is a helper function to simplify the provider implementation. +func NewStorageLunResourceAlias() resource.Resource { + return &StorageLunResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_lun_resource", + }, + } +} + // StorageLunResource defines the resource implementation. type StorageLunResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_lun_resource_alias_test.go b/internal/provider/storage/storage_lun_resource_alias_test.go new file mode 100644 index 00000000..9ea171a2 --- /dev/null +++ b/internal/provider/storage/storage_lun_resource_alias_test.go @@ -0,0 +1,164 @@ +package storage_test + +import ( + "fmt" + "os" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider" +) + +func TestAccStorageLunResouceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test create storage lun svm not found + { + Config: testAccStorageLunResourceConfigAlias("ACC-lun", "unknownsvm", "lunTest", "linux", 1048576), + ExpectError: regexp.MustCompile("2621462"), + }, + // Test create storage lun volume not found + { + Config: testAccStorageLunResourceConfigAlias("ACC-lun", "carchi-test", "unnownsvm", "linux", 1048576), + ExpectError: regexp.MustCompile("917927"), + }, + // Create storage lun and read without size_unit + { + Config: testAccStorageLunResourceConfigAlias("ACC-lun", "carchi-test", "lunTest", "linux", 1048576), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "name", "/vol/lunTest/ACC-lun"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "volume_name", "lunTest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "size", "1048576"), + ), + }, + // Update name + { + Config: testAccStorageLunResourceConfigAlias("ACC-lun2", "carchi-test", "lunTest", "linux", 1048576), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "logical_unit", "ACC-lun2"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "volume_name", "lunTest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "size", "1048576"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_lun_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "/vol/lunTest/ACC-import-lun", "lunTest", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "name", "ACC-import-lun"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example", "size", "1048576"), + ), + }, + // create storage lun with size_unit + { + Config: testAccStorageLunResourceWithSizeUnitConfigAlias("ACC-lun-size", "carchi-test", "lunTest", "linux", 4, "kb"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "name", "/vol/lunTest/ACC-lun-size"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "volume_name", "lunTest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size", "4"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size_unit", "kb"), + ), + }, + // update storage lun with size_unit + { + Config: testAccStorageLunResourceWithSizeUnitConfigAlias("ACC-lun-size", "carchi-test", "lunTest", "linux", 5, "kb"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "name", "/vol/lunTest/ACC-lun-size"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "volume_name", "lunTest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size", "5"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size_unit", "kb"), + ), + }, + // update storage lun size_unit + { + Config: testAccStorageLunResourceWithSizeUnitConfigAlias("ACC-lun-size", "carchi-test", "lunTest", "linux", 5, "mb"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "name", "/vol/lunTest/ACC-lun-size"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "volume_name", "lunTest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "os_type", "linux"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size", "5"), + resource.TestCheckResourceAttr("netapp-ontap_storage_lun_resource.example_size", "size_unit", "mb"), + ), + }, + }, + }) +} + +func testAccStorageLunResourceConfigAlias(logicalUnit string, svmname string, volumeName string, osType string, size int64) 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_storage_lun_resource" "example" { + # required to know which system to interface with + cx_profile_name = "cluster4" + logical_unit = "%s" + svm_name = "%s" + volume_name = "%s" + os_type = "%s" + size = "%d" +}`, host, admin, password, logicalUnit, svmname, volumeName, osType, size) +} + +func testAccStorageLunResourceWithSizeUnitConfigAlias(logicalUnit string, svmname string, volumeName string, osType string, size int64, size_unit 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_storage_lun_resource" "example_size" { + # required to know which system to interface with + cx_profile_name = "cluster4" + logical_unit = "%s" + svm_name = "%s" + volume_name = "%s" + os_type = "%s" + size = "%d" + size_unit = "%s" +}`, host, admin, password, logicalUnit, svmname, volumeName, osType, size, size_unit) +} diff --git a/internal/provider/storage/storage_luns_data_source.go b/internal/provider/storage/storage_luns_data_source.go index 4ec4251a..ba770a9d 100644 --- a/internal/provider/storage/storage_luns_data_source.go +++ b/internal/provider/storage/storage_luns_data_source.go @@ -25,6 +25,15 @@ func NewStorageLunsDataSource() datasource.DataSource { } } +// NewStorageLunsDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageLunsDataSourceAlias() datasource.DataSource { + return &StorageLunsDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_luns_data_source", + }, + } +} + // StorageLunsDataSource defines the data source implementation. type StorageLunsDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_snapshot_policies_data_source.go b/internal/provider/storage/storage_snapshot_policies_data_source.go index cbd51c71..9d35be8c 100644 --- a/internal/provider/storage/storage_snapshot_policies_data_source.go +++ b/internal/provider/storage/storage_snapshot_policies_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -25,6 +26,15 @@ func NewSnapshotPoliciesDataSource() datasource.DataSource { } } +// NewSnapshotPoliciesDataSourceAlias is a helper function to simplify the provider implementation. +func NewSnapshotPoliciesDataSourceAlias() datasource.DataSource { + return &SnapshotPoliciesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_snapshot_policies_data_source", + }, + } +} + // SnapshotPoliciesDataSource defines the data source implementation. type SnapshotPoliciesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_snapshot_policy_alias_test.go b/internal/provider/storage/storage_snapshot_policy_alias_test.go new file mode 100644 index 00000000..7119028b --- /dev/null +++ b/internal/provider/storage/storage_snapshot_policy_alias_test.go @@ -0,0 +1,92 @@ +package storage_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 TestAccStorageSnapshotPolicyResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test create storage snapshot policy error + { + Config: testAccStorageSnapshotPolicyResourceConfigAlias("non-existant", "unknowsvm", "wrong case", false), + ExpectError: regexp.MustCompile("error creating storage_snapshot_policy"), + }, + // Create storage snapshot policy and read + { + Config: testAccStorageSnapshotPolicyResourceConfigAlias("tf-sn-policy", "carchi-test", "create a test snapshot policy", true), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "name", "tf-sn-policy"), + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "comment", "create a test snapshot policy"), + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "enabled", "true"), + ), + }, + // Update storage snapshot policy on comment and read + { + Config: testAccStorageSnapshotPolicyResourceConfigAlias("tf-sn-policy", "carchi-test", "Update the existing snapshot policy", true), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "name", "tf-sn-policy"), + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "comment", "Update the existing snapshot policy"), + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "enabled", "true"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_snapshot_policy_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "tfimportpolicy", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_snapshot_policy_resource.example", "name", "tfimportpolicy"), + ), + }, + }, + }) +} + +func testAccStorageSnapshotPolicyResourceConfigAlias(name string, svmname string, comment string, enabled bool) 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_storage_snapshot_policy_resource" "example" { + # required to know which system to interface with + cx_profile_name = "cluster4" + name = "%s" + svm_name = "%s" + comment = "%s" + enabled = "%t" + copies = [ + { + count = 3 + schedule = { + name = "daily" + } + }, + ] +}`, host, admin, password, name, svmname, comment, enabled) +} diff --git a/internal/provider/storage/storage_snapshot_policy_data_source.go b/internal/provider/storage/storage_snapshot_policy_data_source.go index 7449fdd4..22937b87 100644 --- a/internal/provider/storage/storage_snapshot_policy_data_source.go +++ b/internal/provider/storage/storage_snapshot_policy_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -25,6 +26,15 @@ func NewSnapshotPolicyDataSource() datasource.DataSource { } } +// NewSnapshotPolicyDataSourceAlias is a helper function to simplify the provider implementation. +func NewSnapshotPolicyDataSourceAlias() datasource.DataSource { + return &SnapshotPolicyDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_snapshot_policy_data_source", + }, + } +} + // SnapshotPolicyDataSource defines the data source implementation. type SnapshotPolicyDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_snapshot_policy_resource.go b/internal/provider/storage/storage_snapshot_policy_resource.go index addf87b9..168a1e4f 100644 --- a/internal/provider/storage/storage_snapshot_policy_resource.go +++ b/internal/provider/storage/storage_snapshot_policy_resource.go @@ -3,9 +3,10 @@ package storage 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" @@ -36,6 +37,15 @@ func NewSnapshotPolicyResource() resource.Resource { } } +// NewSnapshotPolicyResource is a helper function to simplify the provider implementation. +func NewSnapshotPolicyResourceAlias() resource.Resource { + return &SnapshotPolicyResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_snapshot_policy_resource", + }, + } +} + // SnapshotPolicyResource defines the resource implementation. type SnapshotPolicyResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volume_data_source.go b/internal/provider/storage/storage_volume_data_source.go index d6d3ce33..c241ef16 100644 --- a/internal/provider/storage/storage_volume_data_source.go +++ b/internal/provider/storage/storage_volume_data_source.go @@ -24,6 +24,15 @@ func NewStorageVolumeDataSource() datasource.DataSource { } } +// NewStorageVolumeDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumeDataSourceAlias() datasource.DataSource { + return &StorageVolumeDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volume_data_source", + }, + } +} + // StorageVolumeDataSource defines the data source implementation. type StorageVolumeDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volume_resource.go b/internal/provider/storage/storage_volume_resource.go index cb6ef534..48ff3abb 100644 --- a/internal/provider/storage/storage_volume_resource.go +++ b/internal/provider/storage/storage_volume_resource.go @@ -38,6 +38,15 @@ func NewStorageVolumeResource() resource.Resource { } } +// NewStorageVolumeResourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumeResourceAlias() resource.Resource { + return &StorageVolumeResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volume_resource", + }, + } +} + // StorageVolumeResource defines the resource implementation. type StorageVolumeResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volume_resource_alias_test.go b/internal/provider/storage/storage_volume_resource_alias_test.go new file mode 100644 index 00000000..fd80f18b --- /dev/null +++ b/internal/provider/storage/storage_volume_resource_alias_test.go @@ -0,0 +1,164 @@ +package storage_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 TestAccStorageVolumeResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test non existant SVM + { + Config: testAccStorageVolumeResourceConfigAlias("non-existant", "terraformTest4"), + ExpectError: regexp.MustCompile("2621462"), + }, + // test bad volume name + { + Config: testAccStorageVolumeResourceConfigAlias("non-existant", "name-cant-have-dashes"), + ExpectError: regexp.MustCompile("917888"), + }, + // Read testing + { + Config: testAccStorageVolumeResourceConfigAlias("acc_test", "accVolume1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_resource.example", "name", "accVolume1"), + resource.TestCheckNoResourceAttr("netapp-ontap_storage_volume_resource.example", "volname"), + ), + }, + { + Config: testAccStorageVolumeResourceConfigAliasUpdate("automation", "accVolume1"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_resource.example", "name", "accVolume1"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_resource.example", "nas.group_id", "10"), + resource.TestCheckNoResourceAttr("netapp-ontap_storage_volume_resource.example", "volname"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_volume_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "acc_test_root", "acc_test", "cluster5"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_resource.example", "name", "automation"), + ), + }, + }, + }) +} + +func testAccStorageVolumeResourceConfigAlias(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST2") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS2 must be set for acceptance tests") + os.Exit(1) + } + return fmt.Sprintf(` +provider "netapp-ontap" { + connection_profiles = [ + { + name = "cluster5" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_storage_volume_resource" "example" { + cx_profile_name = "cluster5" + name = "%s" + svm_name = "%s" + aggregates = [ + {name = "acc_test"} +] + space_guarantee = "none" + snapshot_policy = "default-1weekly" + space = { + size = 30 + size_unit = "mb" + percent_snapshot_space = 10 + logical_space = { + enforcement = true + reporting = true + } + } + tiering = { + policy_name = "all" + } + nas = { + export_policy_name = "test" + group_id = 1 + user_id = 2 + unix_permissions = "100" + security_style = "mixed" + junction_path = "/testacc" + } +}`, host, admin, password, volName, svm) +} + +func testAccStorageVolumeResourceConfigAliasUpdate(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST2") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS2 must be set for acceptance tests") + os.Exit(1) + } + return fmt.Sprintf(` +provider "netapp-ontap" { + connection_profiles = [ + { + name = "cluster5" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_storage_volume_resource" "example" { + cx_profile_name = "cluster5" + name = "%s" + svm_name = "%s" + aggregates = [ + {name = "acc_test"} +] + space_guarantee = "none" + snapshot_policy = "default-1weekly" + space = { + size = 30 + size_unit = "mb" + percent_snapshot_space = 20 + logical_space = { + enforcement = true + reporting = true + } + } + tiering = { + policy_name = "all" + } + nas = { + export_policy_name = "test" + group_id = 10 + user_id = 20 + unix_permissions = "755" + security_style = "mixed" + junction_path = "/testacc" + } +}`, host, admin, password, volName, svm) +} diff --git a/internal/provider/storage/storage_volume_snapshot_data_source.go b/internal/provider/storage/storage_volume_snapshot_data_source.go index 514923c6..b6f8e0e5 100644 --- a/internal/provider/storage/storage_volume_snapshot_data_source.go +++ b/internal/provider/storage/storage_volume_snapshot_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -25,6 +26,15 @@ func NewStorageVolumeSnapshotDataSource() datasource.DataSource { } } +// NewStorageVolumeSnapshotDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumeSnapshotDataSourceAlias() datasource.DataSource { + return &StorageVolumeSnapshotDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volume_snapshot_data_source", + }, + } +} + // StorageVolumeSnapshotDataSource defines the data source implementation. type StorageVolumeSnapshotDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volume_snapshot_resource.go b/internal/provider/storage/storage_volume_snapshot_resource.go index 974a307f..efb5cdb2 100644 --- a/internal/provider/storage/storage_volume_snapshot_resource.go +++ b/internal/provider/storage/storage_volume_snapshot_resource.go @@ -3,9 +3,10 @@ package storage 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" @@ -30,6 +31,15 @@ func NewStorageVolumeSnapshotResource() resource.Resource { } } +// NewStorageVolumeSnapshotResourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumeSnapshotResourceAlias() resource.Resource { + return &StorageVolumeSnapshotResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volume_snapshot_resource", + }, + } +} + // StorageVolumeSnapshotResource defines the resource implementation. type StorageVolumeSnapshotResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volume_snapshot_resource_alias_test.go b/internal/provider/storage/storage_volume_snapshot_resource_alias_test.go new file mode 100644 index 00000000..aa00d7e6 --- /dev/null +++ b/internal/provider/storage/storage_volume_snapshot_resource_alias_test.go @@ -0,0 +1,85 @@ +package storage_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 TestAccStorageVolumeSnapshotResourceAlias(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: testAccStorageVolumeSnapshotResourceConfigAlias("non-existant", "my comment"), + ExpectError: regexp.MustCompile("svm non-existant not found"), + }, + // Create and read testing + { + Config: testAccStorageVolumeSnapshotResourceConfigAlias("carchi-test", "my comment"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "volume_name", "carchi_test_root"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "name", "snaptest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "comment", "my comment"), + ), + }, + // Update and read testing + { + Config: testAccStorageVolumeSnapshotResourceConfigAlias("carchi-test", "new comment"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "volume_name", "carchi_test_root"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "name", "snaptest"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "comment", "new comment"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_storage_volume_snapshot_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "snaptest", "carchi_test_root", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_storage_volume_snapshot_resource.example", "name", "snaptest"), + ), + }, + }, + }) +} + +func testAccStorageVolumeSnapshotResourceConfigAlias(svmName string, comment 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_storage_volume_snapshot_resource" "example" { + cx_profile_name = "cluster4" + name = "snaptest" + volume_name = "carchi_test_root" + svm_name = "%s" + comment = "%s" +}`, host, admin, password, svmName, comment) +} diff --git a/internal/provider/storage/storage_volume_snapshots_data_source.go b/internal/provider/storage/storage_volume_snapshots_data_source.go index e0888d40..b0d1ddf6 100644 --- a/internal/provider/storage/storage_volume_snapshots_data_source.go +++ b/internal/provider/storage/storage_volume_snapshots_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -25,6 +26,15 @@ func NewStorageVolumeSnapshotsDataSource() datasource.DataSource { } } +// NewStorageVolumeSnapshotsDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumeSnapshotsDataSourceAlias() datasource.DataSource { + return &StorageVolumeSnapshotsDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volume_snapshots_data_source", + }, + } +} + // StorageVolumeSnapshotsDataSource defines the data source implementation. type StorageVolumeSnapshotsDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/storage/storage_volumes_data_source.go b/internal/provider/storage/storage_volumes_data_source.go index b88a46e8..706a610e 100644 --- a/internal/provider/storage/storage_volumes_data_source.go +++ b/internal/provider/storage/storage_volumes_data_source.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -24,6 +25,15 @@ func NewStorageVolumesDataSource() datasource.DataSource { } } +// NewStorageVolumesDataSourceAlias is a helper function to simplify the provider implementation. +func NewStorageVolumesDataSourceAlias() datasource.DataSource { + return &StorageVolumesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "storage_volumes_data_source", + }, + } +} + // StorageVolumesDataSource defines the data source implementation. type StorageVolumesDataSource struct { config connection.ResourceOrDataSourceConfig