Skip to content

Commit

Permalink
Merge pull request #326 from NetApp/old-name-storage
Browse files Browse the repository at this point in the history
add support for old name for storage
  • Loading branch information
carchi8py authored Oct 29, 2024
2 parents 0dca2f8 + b8b46f4 commit 54813a5
Show file tree
Hide file tree
Showing 25 changed files with 931 additions and 5 deletions.
18 changes: 18 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down
9 changes: 9 additions & 0 deletions internal/provider/storage/storage_aggregate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/storage/storage_aggregate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions internal/provider/storage/storage_aggregate_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 10 additions & 0 deletions internal/provider/storage/storage_aggregates_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/storage/storage_flexcache_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/storage/storage_flexcache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
159 changes: 159 additions & 0 deletions internal/provider/storage/storage_flexcache_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit 54813a5

Please sign in to comment.