diff --git a/internal/provider/protocols/protocols_cifs_local_group_data_source.go b/internal/provider/protocols/protocols_cifs_local_group_data_source.go index d3126d71..660a4ee5 100644 --- a/internal/provider/protocols/protocols_cifs_local_group_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_group_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsLocalGroupDataSource() datasource.DataSource { } } +// NewCifsLocalGroupDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupDataSourceAlias() datasource.DataSource { + return &CifsLocalGroupDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_group_data_source", + }, + } +} + // CifsLocalGroupDataSource defines the data source implementation. type CifsLocalGroupDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_group_member_data_source.go b/internal/provider/protocols/protocols_cifs_local_group_member_data_source.go index 2b12f7c4..e7fa3a7d 100644 --- a/internal/provider/protocols/protocols_cifs_local_group_member_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_group_member_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsLocalGroupMemberDataSource() datasource.DataSource { } } +// NewCifsLocalGroupMemberDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupMemberDataSourceAlias() datasource.DataSource { + return &CifsLocalGroupMemberDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_group_member_data_source", + }, + } +} + // CifsLocalGroupMemberDataSource defines the data source implementation. type CifsLocalGroupMemberDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_group_members_data_source.go b/internal/provider/protocols/protocols_cifs_local_group_members_data_source.go index 471484af..9b402525 100644 --- a/internal/provider/protocols/protocols_cifs_local_group_members_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_group_members_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsLocalGroupMembersDataSource() datasource.DataSource { } } +// NewCifsLocalGroupMembersDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupMembersDataSourceAlias() datasource.DataSource { + return &CifsLocalGroupMembersDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_group_members_data_source", + }, + } +} + // CifsLocalGroupMembersDataSource defines the data source implementation. type CifsLocalGroupMembersDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_group_members_resource.go b/internal/provider/protocols/protocols_cifs_local_group_members_resource.go index 8c79214c..12eaae3b 100644 --- a/internal/provider/protocols/protocols_cifs_local_group_members_resource.go +++ b/internal/provider/protocols/protocols_cifs_local_group_members_resource.go @@ -34,6 +34,15 @@ func NewCifsLocalGroupMembersResource() resource.Resource { } } +// NewCifsLocalGroupMembersResourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupMembersResourceAlias() resource.Resource { + return &CifsLocalGroupMemberResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_group_member_resource", + }, + } +} + // CifsLocalGroupMemberResource defines the resource implementation. type CifsLocalGroupMemberResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_group_members_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_local_group_members_resource_alias_test.go new file mode 100644 index 00000000..3292ea85 --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_local_group_members_resource_alias_test.go @@ -0,0 +1,92 @@ +package protocols_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 TestAccCifsLocalGroupMembersResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCifsLocalGroupMembersResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // create with basic argument on a local group member + { + // configuration of group name and memmber name have to be double \ otherwise it will be treated as escape character + Config: testAccCifsLocalGroupMembersResourceConfigAlias("svm3", "SVM3_SERVER\\\\accgroup1", "SVM3_SERVER\\\\accuser3"), + Check: resource.ComposeTestCheckFunc( + // check member + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "member", "SVM3_SERVER\\accuser3"), + // check group_name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "group_name", "SVM3_SERVER\\accgroup1"), + // check svm_name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "svm_name", "svm3"), + // check ID + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "id"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_cifs_local_group_member_resource.example1", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "SVM3_SERVER\\accuser3", "SVM3_SERVER\\accgroup1", "svm3", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "svm_name", "svm3"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "group_name", "SVM3_SERVER\\accgroup1"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "member", "SVM3_SERVER\\accuser3"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_group_member_resource.example1", "id"), + ), + }, + }, + }) +} + +func testAccCifsLocalGroupMembersResourceConfigAliasMissingVars(svmName string) string { + return fmt.Sprintf(` +resource "netapp-ontap_protocols_cifs_local_group_member_resource" "example1" { + svm_name = "%s" + group_name = "SVM3_SERVER\\accgroup1" + member = "SVM3_SERVER\\accuser3" +} +`, svmName) +} + +func testAccCifsLocalGroupMembersResourceConfigAlias(svmName, groupName, member 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_protocols_cifs_local_group_member_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + group_name = "%s" + member = "%s" +} +`, host, admin, password, svmName, groupName, member) +} diff --git a/internal/provider/protocols/protocols_cifs_local_group_resource.go b/internal/provider/protocols/protocols_cifs_local_group_resource.go index f947a21f..740d85ba 100644 --- a/internal/provider/protocols/protocols_cifs_local_group_resource.go +++ b/internal/provider/protocols/protocols_cifs_local_group_resource.go @@ -3,9 +3,10 @@ package protocols 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/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -32,6 +33,15 @@ func NewCifsLocalGroupResource() resource.Resource { } } +// NewCifsLocalGroupResourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupResourceAlias() resource.Resource { + return &CifsLocalGroupResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_group_resource", + }, + } +} + // CifsLocalGroupResource defines the resource implementation. type CifsLocalGroupResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_group_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_local_group_resource_alias_test.go new file mode 100644 index 00000000..edc52551 --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_local_group_resource_alias_test.go @@ -0,0 +1,115 @@ +package protocols_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 TestAccCifsLocalGroupResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCifsLocalGroupResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // create with basic argument + { + Config: testAccCifsLocalGroupResourceConfigAlias("ansibleSVM", "group1"), + Check: resource.ComposeTestCheckFunc( + // check name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_resource.example1", "name", "group1"), + // check svm_name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_resource.example1", "svm_name", "ansibleSVM"), + // check ID + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_group_resource.example1", "id"), + ), + }, + // update test + { + Config: testAccCifsLocalGroupResourceConfigAlias("ansibleSVM", "newgroup"), + Check: resource.ComposeTestCheckFunc( + // check renamed group name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_resource.example1", "name", "newgroup"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_group_resource.example1", "id")), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_cifs_local_group_resource.example1", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "Administrators", "ansibleSVM", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_resource.example1", "svm_name", "ansibleSVM"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_group_resource.example1", "name", "Administrators"), + resource.TestMatchResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule.example1", "description", regexp.MustCompile(`Built-in Administrators`)), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_group_resource.example1", "id"), + ), + }, + }, + }) +} + +func testAccCifsLocalGroupResourceConfigAliasMissingVars(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_protocols_cifs_local_group_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" +} +`, host, admin, password, svmName) +} + +func testAccCifsLocalGroupResourceConfigAlias(svmName string, groupName 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_protocols_cifs_local_group_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + name = "%s" +} +`, host, admin, password, svmName, groupName) +} diff --git a/internal/provider/protocols/protocols_cifs_local_groups_data_source.go b/internal/provider/protocols/protocols_cifs_local_groups_data_source.go index d6739d42..2e06dda2 100644 --- a/internal/provider/protocols/protocols_cifs_local_groups_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_groups_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsLocalGroupsDataSource() datasource.DataSource { } } +// NewCifsLocalGroupsDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalGroupsDataSourceAlias() datasource.DataSource { + return &CifsLocalGroupsDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_groups_data_source", + }, + } +} + // CifsLocalGroupsDataSource defines the data source implementation. type CifsLocalGroupsDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_user_data_source.go b/internal/provider/protocols/protocols_cifs_local_user_data_source.go index 1d8328cc..1e5bdafd 100644 --- a/internal/provider/protocols/protocols_cifs_local_user_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_user_data_source.go @@ -25,6 +25,15 @@ func NewCifsLocalUserDataSource() datasource.DataSource { } } +// NewCifsLocalUserDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalUserDataSourceAlias() datasource.DataSource { + return &CifsLocalUserDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_user_data_source", + }, + } +} + // CifsLocalUserDataSource defines the data source implementation. type CifsLocalUserDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_user_resource.go b/internal/provider/protocols/protocols_cifs_local_user_resource.go index 478c77c2..e53f2326 100644 --- a/internal/provider/protocols/protocols_cifs_local_user_resource.go +++ b/internal/provider/protocols/protocols_cifs_local_user_resource.go @@ -3,9 +3,10 @@ package protocols 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/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -33,6 +34,15 @@ func NewCifsLocalUserResource() resource.Resource { } } +// NewCifsLocalUserResourcAlias is a helper function to simplify the provider implementation. +func NewCifsLocalUserResourcAlias() resource.Resource { + return &CifsLocalUserResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_user_resource", + }, + } +} + // CifsLocalUserResource defines the resource implementation. type CifsLocalUserResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_local_user_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_local_user_resource_alias_test.go new file mode 100644 index 00000000..4164618f --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_local_user_resource_alias_test.go @@ -0,0 +1,117 @@ +package protocols_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 TestAccCifsLocalUserResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCifsLocalUserResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // create with basic argument + { + Config: testAccCifsLocalUserResourceConfigAlias("ansibleSVM", "user1"), + Check: resource.ComposeTestCheckFunc( + // check name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_user_resource.example1", "name", "user1"), + // check svm_name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_user_resource.example1", "svm_name", "ansibleSVM"), + // check ID + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_user_resource.example1", "id"), + ), + }, + // update test + { + Config: testAccCifsLocalUserResourceConfigAlias("ansibleSVM", "newuser"), + Check: resource.ComposeTestCheckFunc( + // check renamed user name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_user_resource.example1", "name", "newuser"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_user_resource.example1", "id")), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_cifs_local_user_resource.example1", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "Administrator", "ansibleSVM", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_user_resource.example1", "svm_name", "ansibleSVM"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_local_user_resource.example1", "name", "Administrator"), + resource.TestMatchResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule.example1", "description", regexp.MustCompile(`Built-in administrator account`)), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule.example1", "membership.*", "Administrators"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_local_user_resource.example1", "id"), + ), + }, + }, + }) +} + +func testAccCifsLocalUserResourceConfigAliasMissingVars(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_protocols_cifs_local_user_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" +} +`, host, admin, password, svmName) +} + +func testAccCifsLocalUserResourceConfigAlias(svmName string, userName 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_protocols_cifs_local_user_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + name = "%s" + password = "password!!!" +} +`, host, admin, password, svmName, userName) +} diff --git a/internal/provider/protocols/protocols_cifs_local_users_data_source.go b/internal/provider/protocols/protocols_cifs_local_users_data_source.go index 73a094e7..64e3446c 100644 --- a/internal/provider/protocols/protocols_cifs_local_users_data_source.go +++ b/internal/provider/protocols/protocols_cifs_local_users_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsLocalUsersDataSource() datasource.DataSource { } } +// NewCifsLocalUsersDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsLocalUsersDataSourceAlias() datasource.DataSource { + return &CifsLocalUsersDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_local_users_data_source", + }, + } +} + // CifsLocalUsersDataSource defines the data source implementation. type CifsLocalUsersDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_service_data_source.go b/internal/provider/protocols/protocols_cifs_service_data_source.go index 89ec3903..dc55b028 100644 --- a/internal/provider/protocols/protocols_cifs_service_data_source.go +++ b/internal/provider/protocols/protocols_cifs_service_data_source.go @@ -25,6 +25,15 @@ func NewCifsServiceDataSource() datasource.DataSource { } } +// NewCifsServiceDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsServiceDataSourceAlias() datasource.DataSource { + return &CifsServiceDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_service_data_source", + }, + } +} + // CifsServiceDataSource defines the data source implementation. type CifsServiceDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_service_resource.go b/internal/provider/protocols/protocols_cifs_service_resource.go index de40f031..d95e571d 100644 --- a/internal/provider/protocols/protocols_cifs_service_resource.go +++ b/internal/provider/protocols/protocols_cifs_service_resource.go @@ -3,9 +3,10 @@ package protocols 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/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -40,6 +41,15 @@ func NewCifsServiceResource() resource.Resource { } } +// NewCifsServiceResourceAlias is a helper function to simplify the provider implementation. +func NewCifsServiceResourceAlias() resource.Resource { + return &CifsServiceResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_service_resource", + }, + } +} + // CifsServiceResource defines the resource implementation. type CifsServiceResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_service_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_service_resource_alias_test.go new file mode 100644 index 00000000..711f868b --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_service_resource_alias_test.go @@ -0,0 +1,132 @@ +package protocols_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 TestAccCifsServiceResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test error + { + Config: testAccCifsServiceResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // Create and read + { + Config: testAccCifsServiceResourceConfigAlias("tftestcifs", "testSVM"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "svm_name", "testSVM"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "name", "tftestcifs"), + ), + }, + // update and read + { + Config: testAccCifsServiceResourceUpdateConfigAlias("tftestcifs", "testSVM"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "svm_name", "testSVM"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "name", "tftestcifs"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "security.lm_compatibility_level", "ntlm_ntlmv2_krb"), + ), + }, + // Import and read + { + ResourceName: "netapp-ontap_protocols_cifs_service_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s,%s", "TFCIFS", "tfsvm", "clustercifs", "cifstest", os.Getenv("TF_ACC_NETAPP_CIFS_ADDOMAIN_PASS")), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "name", "TFCIFS"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_service_resource.example", "svm_name", "tfsvm"), + ), + }, + }, + }) +} + +func testAccCifsServiceResourceConfigAliasMissingVars(svmName string) string { + return fmt.Sprintf(` + resource "netapp-ontap_protocols_cifs_service_resource" "example1" { + svm_name = "%s" + } + `, svmName) +} + +func testAccCifsServiceResourceConfigAlias(name string, svmName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS_CIFS") + cifspassword := os.Getenv("TF_ACC_NETAPP_CIFS_ADDOMAIN_PASS") + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS_CIFS and TF_ACC_NETAPP_CIFS_ADDOMAIN_PASS must be set for acceptance tests") + os.Exit(1) + } + return fmt.Sprintf(` +provider "netapp-ontap" { + connection_profiles = [ + { + name = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} +resource "netapp-ontap_protocols_cifs_service_resource" "example" { + cx_profile_name = "clustercifs" + svm_name = "%s" + name = "%s" + ad_domain = { + fqdn = "mytfdomain.com" + user = "cifstest" + password = "%s" + } +} +`, host, admin, password, svmName, name, cifspassword) +} + +func testAccCifsServiceResourceUpdateConfigAlias(name string, svmName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS_CIFS") + cifspassword := os.Getenv("TF_ACC_NETAPP_CIFS_ADDOMAIN_PASS") + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS_CIFS and TF_ACC_NETAPP_CIFS_ADDOMAIN_PASS must be set for acceptance tests") + os.Exit(1) + } + return fmt.Sprintf(` +provider "netapp-ontap" { + connection_profiles = [ + { + name = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} +resource "netapp-ontap_protocols_cifs_service_resource" "example" { + cx_profile_name = "clustercifs" + svm_name = "%s" + name = "%s" + ad_domain = { + fqdn = "mytfdomain.com" + user = "cifstest" + password = "%s" + } + security = { + lm_compatibility_level = "ntlm_ntlmv2_krb" + } +} +`, host, admin, password, svmName, name, cifspassword) +} diff --git a/internal/provider/protocols/protocols_cifs_services_data_source.go b/internal/provider/protocols/protocols_cifs_services_data_source.go index 0dc71339..bc121107 100644 --- a/internal/provider/protocols/protocols_cifs_services_data_source.go +++ b/internal/provider/protocols/protocols_cifs_services_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsServicesDataSource() datasource.DataSource { } } +// NewCifsServicesDataSource is a helper function to simplify the provider implementation. +func NewCifsServicesDataSourceAlias() datasource.DataSource { + return &CifsServicesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_services_data_source", + }, + } +} + // CifsServicesDataSource defines the data source implementation. type CifsServicesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_share_data_source.go b/internal/provider/protocols/protocols_cifs_share_data_source.go index 8ae613f8..4a17524b 100644 --- a/internal/provider/protocols/protocols_cifs_share_data_source.go +++ b/internal/provider/protocols/protocols_cifs_share_data_source.go @@ -3,6 +3,7 @@ package protocols import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -28,6 +29,15 @@ func NewProtocolsCIFSShareDataSource() datasource.DataSource { } } +// NewProtocolsCIFSShareDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsCIFSShareDataSourceAlias() datasource.DataSource { + return &ProtocolsCIFSShareDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_share_data_source", + }, + } +} + // ProtocolsCIFSShareDataSource defines the data source implementation. type ProtocolsCIFSShareDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_share_resource.go b/internal/provider/protocols/protocols_cifs_share_resource.go index e8b7ee62..e7141c8c 100644 --- a/internal/provider/protocols/protocols_cifs_share_resource.go +++ b/internal/provider/protocols/protocols_cifs_share_resource.go @@ -3,9 +3,10 @@ package protocols 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/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" @@ -35,6 +36,15 @@ func NewProtocolsCIFSShareResource() resource.Resource { } } +// NewProtocolsCIFSShareResourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsCIFSShareResourceAlias() resource.Resource { + return &ProtocolsCIFSShareResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_share_resource", + }, + } +} + // ProtocolsCIFSShareResource defines the resource implementation. type ProtocolsCIFSShareResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_share_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_share_resource_alias_test.go new file mode 100644 index 00000000..ccfd885f --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_share_resource_alias_test.go @@ -0,0 +1,224 @@ +package protocols_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 TestAccProtocolsCIFSShareResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test non existant SVM + { + Config: testAccProtocolsCIFSShareResourceConfigAlias("non-existant", "terraformTest4"), + ExpectError: regexp.MustCompile("2621462"), + }, + // Read testing + { + Config: testAccProtocolsCIFSShareResourceConfigAlias("tfsvm", "acc_test_cifs_share"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "name", "acc_test_cifs_share"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "comment", "this is a comment"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "continuously_available", "false"), + ), + }, + { + Config: testAccProtocolsCIFSShareResourceConfigAliasUpdate("tfsvm", "acc_test_cifs_share"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "name", "acc_test_cifs_share"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "comment", "update comment"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "continuously_available", "true"), + ), + }, + { + Config: testAccProtocolsCIFSShareResourceConfigAliasUpdateAddACL("tfsvm", "acc_test_cifs_share"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "name", "acc_test_cifs_share"), + ), + }, + { + Config: testAccProtocolsCIFSShareResourceConfigAliasUpdateDeleteACL("tfsvm", "acc_test_cifs_share"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "name", "acc_test_cifs_share"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_cifs_share_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "acc_test_cifs_share_import", "tfsvm", "clustercifs"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_share_resource.example", "name", "acc_test_cifs_share_import"), + ), + }, + }, + }) +} + +func testAccProtocolsCIFSShareResourceConfigAlias(svm, shareName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, 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 = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_protocols_cifs_share_resource" "example" { + cx_profile_name = "clustercifs" + name = "%s" + svm_name = "%s" + path = "/acc_test_cifs_share_volume" + acls = [ + { + "permission": "read", + "type": "windows", + "user_or_group": "BUILTIN\\Administrators" + } + ] + comment = "this is a comment" +}`, host, admin, password, shareName, svm) +} + +func testAccProtocolsCIFSShareResourceConfigAliasUpdate(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, 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 = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_protocols_cifs_share_resource" "example" { + cx_profile_name = "clustercifs" + name = "%s" + svm_name = "%s" + path = "/acc_test_cifs_share_volume" + acls = [ + { + "permission": "full_control", + "type": "windows", + "user_or_group": "BUILTIN\\Administrators" + } + ] + comment = "update comment" + continuously_available = true +}`, host, admin, password, volName, svm) +} + +func testAccProtocolsCIFSShareResourceConfigAliasUpdateAddACL(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, 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 = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_protocols_cifs_share_resource" "example" { + cx_profile_name = "clustercifs" + name = "%s" + svm_name = "%s" + path = "/acc_test_cifs_share_volume" + acls = [ + { + "permission": "read", + "type": "windows", + "user_or_group": "Everyone" + }, + { + "permission": "full_control", + "type": "windows", + "user_or_group": "BUILTIN\\Administrators" + } + ] + comment = "update comment" + continuously_available = true +}`, host, admin, password, volName, svm) +} + +func testAccProtocolsCIFSShareResourceConfigAliasUpdateDeleteACL(svm, volName string) string { + host := os.Getenv("TF_ACC_NETAPP_HOST_CIFS") + admin := os.Getenv("TF_ACC_NETAPP_USER") + password := os.Getenv("TF_ACC_NETAPP_PASS2") + + if host == "" || admin == "" || password == "" { + fmt.Println("TF_ACC_NETAPP_HOST_CIFS, 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 = "clustercifs" + hostname = "%s" + username = "%s" + password = "%s" + validate_certs = false + }, + ] +} + +resource "netapp-ontap_protocols_cifs_share_resource" "example" { + cx_profile_name = "clustercifs" + name = "%s" + svm_name = "%s" + path = "/acc_test_cifs_share_volume" + acls = [ + { + "permission": "read", + "type": "windows", + "user_or_group": "Everyone" + } + ] + comment = "update comment" + continuously_available = true +}`, host, admin, password, volName, svm) +} diff --git a/internal/provider/protocols/protocols_cifs_shares_data_source.go b/internal/provider/protocols/protocols_cifs_shares_data_source.go index a81ca452..6c0bd702 100644 --- a/internal/provider/protocols/protocols_cifs_shares_data_source.go +++ b/internal/provider/protocols/protocols_cifs_shares_data_source.go @@ -3,9 +3,10 @@ package protocols 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-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -29,6 +30,15 @@ func NewProtocolsCIFSSharesDataSource() datasource.DataSource { } } +// NewProtocolsCIFSSharesDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsCIFSSharesDataSourceAlias() datasource.DataSource { + return &ProtocolsCIFSSharesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_shares_data_source", + }, + } +} + // ProtocolsCIFSSharesDataSource defines the data source implementation. type ProtocolsCIFSSharesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_user_group_privilege_data_source.go b/internal/provider/protocols/protocols_cifs_user_group_privilege_data_source.go index 7ac2d229..703b9aae 100644 --- a/internal/provider/protocols/protocols_cifs_user_group_privilege_data_source.go +++ b/internal/provider/protocols/protocols_cifs_user_group_privilege_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsUserGroupPrivilegeDataSource() datasource.DataSource { } } +// NewCifsUserGroupPrivilegeDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsUserGroupPrivilegeDataSourceAlias() datasource.DataSource { + return &CifsUserGroupPrivilegeDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_user_group_privilege_data_source", + }, + } +} + // CifsUserGroupPrivilegeDataSource defines the data source implementation. type CifsUserGroupPrivilegeDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_user_group_privileges_data_source.go b/internal/provider/protocols/protocols_cifs_user_group_privileges_data_source.go index 87235c8a..f1830168 100644 --- a/internal/provider/protocols/protocols_cifs_user_group_privileges_data_source.go +++ b/internal/provider/protocols/protocols_cifs_user_group_privileges_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewCifsUserGroupPrivilegesDataSource() datasource.DataSource { } } +// NewCifsUserGroupPrivilegesDataSourceAlias is a helper function to simplify the provider implementation. +func NewCifsUserGroupPrivilegesDataSourceAlias() datasource.DataSource { + return &CifsUserGroupPrivilegesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_user_group_privileges_data_source", + }, + } +} + // CifsUserGroupPrivilegesDataSource defines the data source implementation. type CifsUserGroupPrivilegesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_user_group_privileges_resource.go b/internal/provider/protocols/protocols_cifs_user_group_privileges_resource.go index 8354ec79..c2cef7dd 100644 --- a/internal/provider/protocols/protocols_cifs_user_group_privileges_resource.go +++ b/internal/provider/protocols/protocols_cifs_user_group_privileges_resource.go @@ -35,6 +35,15 @@ func NewCifsUserGroupPrivilegeResource() resource.Resource { } } +// NewCifsUserGroupPrivilegeResourceAlias is a helper function to simplify the provider implementation. +func NewCifsUserGroupPrivilegeResourceAlias() resource.Resource { + return &CifsUserGroupPrivilegeResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_cifs_user_group_privilege_resource", + }, + } +} + // CifsUserGroupPrivilegeResource defines the resource implementation. type CifsUserGroupPrivilegeResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_cifs_user_group_privileges_resource_alias_test.go b/internal/provider/protocols/protocols_cifs_user_group_privileges_resource_alias_test.go new file mode 100644 index 00000000..5da602bb --- /dev/null +++ b/internal/provider/protocols/protocols_cifs_user_group_privileges_resource_alias_test.go @@ -0,0 +1,101 @@ +package protocols_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 TestAccCifsUserGroupPrivilegesResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCifsUserGroupPrivilegesResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // create with basic argument on a local user + { + Config: testAccCifsUserGroupPrivilegesResourceConfigAlias("svm3", "accuser1", "sechangenotifyprivilege"), + Check: resource.ComposeTestCheckFunc( + // check name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "name", "accuser1"), + // check svm_name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "svm_name", "svm3"), + // check ID + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "id"), + // check privileges + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "privileges.*", "sechangenotifyprivilege"), + ), + }, + // update one privilege + { + Config: testAccCifsUserGroupPrivilegesResourceConfigAlias("svm3", "accuser1", "setakeownershipprivilege"), + Check: resource.ComposeTestCheckFunc( + // check user name + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "name", "accuser1"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "id"), + // check updated privileges + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "privileges.*", "setakeownershipprivilege"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "accuser1", "svm3", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "svm_name", "svm3"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "name", "accuser1"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "privileges.*", "sesecurityprivilege"), + // check id + resource.TestCheckResourceAttrSet("netapp-ontap_protocols_cifs_user_group_privilege_resource.example1", "id"), + ), + }, + }, + }) +} + +func testAccCifsUserGroupPrivilegesResourceConfigAliasMissingVars(svmName string) string { + return fmt.Sprintf(` + resource "netapp-ontap_protocols_cifs_user_group_privilege_resource" "example1" { + svm_name = "%s" + } + `, svmName) +} + +func testAccCifsUserGroupPrivilegesResourceConfigAlias(svmName string, name string, privilege 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_protocols_cifs_user_group_privilege_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + name = "%s" + privileges = ["%s", "sesecurityprivilege"] +}`, host, admin, password, svmName, name, privilege) +} diff --git a/internal/provider/protocols/protocols_nfs_export_policies_data_source.go b/internal/provider/protocols/protocols_nfs_export_policies_data_source.go index 0c88b946..2a2df763 100644 --- a/internal/provider/protocols/protocols_nfs_export_policies_data_source.go +++ b/internal/provider/protocols/protocols_nfs_export_policies_data_source.go @@ -25,6 +25,15 @@ func NewExportPoliciesDataSource() datasource.DataSource { } } +// NewExportPoliciesDataSourceAlias is a helper function to simplify the provider implementation. +func NewExportPoliciesDataSourceAlias() datasource.DataSource { + return &ExportPoliciesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policies_data_source", + }, + } +} + // ExportPoliciesDataSource defines the data source implementation. type ExportPoliciesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_export_policy_data_source.go b/internal/provider/protocols/protocols_nfs_export_policy_data_source.go index 44ea13a4..29dc7c9c 100644 --- a/internal/provider/protocols/protocols_nfs_export_policy_data_source.go +++ b/internal/provider/protocols/protocols_nfs_export_policy_data_source.go @@ -3,9 +3,10 @@ package protocols import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "strconv" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -27,6 +28,15 @@ func NewExportPolicyDataSource() datasource.DataSource { } } +// NewExportPolicyDataSourceAlias is a helper function to simplify the provider implementation. +func NewExportPolicyDataSourceAlias() datasource.DataSource { + return &ExportPolicyDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policy_data_source", + }, + } +} + // ExportPolicyDataSource defines the source implementation. type ExportPolicyDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_export_policy_resource.go b/internal/provider/protocols/protocols_nfs_export_policy_resource.go index 1aee3bcf..ff80b6f4 100644 --- a/internal/provider/protocols/protocols_nfs_export_policy_resource.go +++ b/internal/provider/protocols/protocols_nfs_export_policy_resource.go @@ -33,6 +33,15 @@ func NewExportPolicyResource() resource.Resource { } } +// NewExportPolicyResourceAlias is a helper function to simplify the provider implementation. +func NewExportPolicyResourceAlias() resource.Resource { + return &ExportPolicyResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policy_resource", + }, + } +} + // ExportPolicyResource defines the resource implementation. type ExportPolicyResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_export_policy_resource_alias_test.go b/internal/provider/protocols/protocols_nfs_export_policy_resource_alias_test.go new file mode 100644 index 00000000..4339d060 --- /dev/null +++ b/internal/provider/protocols/protocols_nfs_export_policy_resource_alias_test.go @@ -0,0 +1,70 @@ +package protocols_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 TestAccNFSExportPolicyResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNFSExportPolicyResourceConfigAlias("non-existant"), + ExpectError: regexp.MustCompile("svm non-existant not found"), + }, + // Create and read testing + { + Config: testAccNFSExportPolicyResourceConfigAlias("carchi-test"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_resource.example", "name", "acc_test"), + resource.TestCheckNoResourceAttr("netapp-ontap_protocols_nfs_export_policy_resource.example", "volname"), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_nfs_export_policy_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "acc_test", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_resource.example", "name", "acc_test"), + ), + }, + }, + }) +} + +func testAccNFSExportPolicyResourceConfigAlias(svm 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_protocols_nfs_export_policy_resource" "example" { + cx_profile_name = "cluster4" + svm_name = "%s" + name = "acc_test" +}`, host, admin, password, svm) +} diff --git a/internal/provider/protocols/protocols_nfs_export_policy_rule_data_source.go b/internal/provider/protocols/protocols_nfs_export_policy_rule_data_source.go index 06a3b03e..509bb10f 100644 --- a/internal/provider/protocols/protocols_nfs_export_policy_rule_data_source.go +++ b/internal/provider/protocols/protocols_nfs_export_policy_rule_data_source.go @@ -3,9 +3,10 @@ package protocols import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "strconv" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -27,6 +28,15 @@ func NewExportPolicyRuleDataSource() datasource.DataSource { } } +// NewExportPolicyRuleDataSourceAlias is a helper function to simplify the provider implementation. +func NewExportPolicyRuleDataSourceAlias() datasource.DataSource { + return &ExportPolicyRuleDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policy_rule_data_source", + }, + } +} + // ExportPolicyRuleDataSource defines the source implementation. type ExportPolicyRuleDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_export_policy_rule_resource.go b/internal/provider/protocols/protocols_nfs_export_policy_rule_resource.go index e0bbd774..a0316319 100644 --- a/internal/provider/protocols/protocols_nfs_export_policy_rule_resource.go +++ b/internal/provider/protocols/protocols_nfs_export_policy_rule_resource.go @@ -3,10 +3,11 @@ package protocols import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "strconv" "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" @@ -38,6 +39,15 @@ func NewExportPolicyRuleResource() resource.Resource { } } +// NewExportPolicyRuleResourceAlias is a helper function to simplify the provider implementation. +func NewExportPolicyRuleResourceAlias() resource.Resource { + return &ExportPolicyRuleResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policy_rule_resource", + }, + } +} + // ExportPolicyRuleResource defines the resource implementation. type ExportPolicyRuleResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_export_policy_rule_resource_alias_test.go b/internal/provider/protocols/protocols_nfs_export_policy_rule_resource_alias_test.go new file mode 100644 index 00000000..b24e25ec --- /dev/null +++ b/internal/provider/protocols/protocols_nfs_export_policy_rule_resource_alias_test.go @@ -0,0 +1,159 @@ +package protocols_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 TestAccNFSExportPolicyRuleResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccNFSExportPolicyRuleResourceConfigAliasMissingVars("non-existant"), + ExpectError: regexp.MustCompile("Missing required argument"), + }, + // create with basic argument + { + Config: testAccNFSExportPolicyRuleResourceConfigAlias("carchi-test", "default"), + Check: resource.ComposeTestCheckFunc( + // check default values + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "allow_suid", "true"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "protocols.*", "any"), + // check id + resource.TestMatchResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "id", regexp.MustCompile(`carchi-test_default_`)), + ), + }, + // update test + { + Config: testAccNFSExportPolicyRuleResourceConfigAliasUpdateProtocolsROrule("carchi-test", "default"), + Check: resource.ComposeTestCheckFunc( + // check default values + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "allow_suid", "true"), + // check if the modification successful + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "protocols.*", "nfs3"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "ro_rule.*", "krb5i"), + // check id + resource.TestMatchResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "id", regexp.MustCompile(`carchi-test_default_`)), + ), + }, + // Test importing a resource + { + ResourceName: "netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "1", "default", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "export_policy_name", "default"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "allow_suid", "true"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "protocols.*", "nfs3"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "ro_rule.*", "krb5i"), + resource.TestCheckTypeSetElemAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "rw_rule.*", "any"), + // check id + resource.TestMatchResourceAttr("netapp-ontap_protocols_nfs_export_policy_rule_resource.example1", "id", regexp.MustCompile(`carchi-test_default_`)), + ), + }, + }, + }) +} + +func testAccNFSExportPolicyRuleResourceConfigAliasMissingVars(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_protocols_nfs_export_policy_rule_resource" "example" { + cx_profile_name = "cluster4" + svm_name = "%s" +} +`, host, admin, password, svmName) +} + +func testAccNFSExportPolicyRuleResourceConfigAlias(svmName string, exportPolicyName 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_protocols_nfs_export_policy_rule_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + export_policy_name = "%s" + clients_match = ["0.0.0.0/0"] + ro_rule = ["any"] + rw_rule = ["any"] +} +`, host, admin, password, svmName, exportPolicyName) +} + +// update protocols and ro_rule +func testAccNFSExportPolicyRuleResourceConfigAliasUpdateProtocolsROrule(svmName string, exportPolicyName 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_protocols_nfs_export_policy_rule_resource" "example1" { + cx_profile_name = "cluster4" + svm_name = "%s" + export_policy_name = "%s" + protocols = ["nfs3","nfs"] + clients_match = ["0.0.0.0/0"] + ro_rule = ["krb5","krb5i"] + rw_rule = ["any"] +} +`, host, admin, password, svmName, exportPolicyName) +} diff --git a/internal/provider/protocols/protocols_nfs_export_policy_rules_data_source.go b/internal/provider/protocols/protocols_nfs_export_policy_rules_data_source.go index 69fb870e..34a8893f 100644 --- a/internal/provider/protocols/protocols_nfs_export_policy_rules_data_source.go +++ b/internal/provider/protocols/protocols_nfs_export_policy_rules_data_source.go @@ -3,9 +3,10 @@ package protocols import ( "context" "fmt" - "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "strconv" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" + "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -26,6 +27,15 @@ func NewExportPolicyRulesDataSource() datasource.DataSource { } } +// NewExportPolicyRulesDataSourceAlias is a helper function to simplify the provider implementation. +func NewExportPolicyRulesDataSourceAlias() datasource.DataSource { + return &ProtocolsNFSExportPolicyRulesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_export_policy_rules_data_source", + }, + } +} + // ProtocolsNFSExportPolicyRulesDataSource defines the data source implementation. type ProtocolsNFSExportPolicyRulesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_service_data_source.go b/internal/provider/protocols/protocols_nfs_service_data_source.go index 0056530d..649abd85 100644 --- a/internal/provider/protocols/protocols_nfs_service_data_source.go +++ b/internal/provider/protocols/protocols_nfs_service_data_source.go @@ -3,6 +3,7 @@ package protocols import ( "context" "fmt" + "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" @@ -25,6 +26,15 @@ func NewProtocolsNfsServiceDataSource() datasource.DataSource { } } +// NewProtocolsNfsServiceDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsNfsServiceDataSourceAlias() datasource.DataSource { + return &ProtocolsNfsServiceDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_service_data_source", + }, + } +} + // ProtocolsNfsServiceDataSource defines the data source implementation. type ProtocolsNfsServiceDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_service_resource.go b/internal/provider/protocols/protocols_nfs_service_resource.go index 4edf00fd..bf923909 100644 --- a/internal/provider/protocols/protocols_nfs_service_resource.go +++ b/internal/provider/protocols/protocols_nfs_service_resource.go @@ -40,6 +40,15 @@ func NewProtocolsNfsServiceResource() resource.Resource { } } +// NewProtocolsNfsServiceResourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsNfsServiceResourceAlias() resource.Resource { + return &ProtocolsNfsServiceResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_service_resource", + }, + } +} + // ProtocolsNfsServiceResource defines the resource implementation. type ProtocolsNfsServiceResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_nfs_service_resource_alias_test.go b/internal/provider/protocols/protocols_nfs_service_resource_alias_test.go new file mode 100644 index 00000000..fd19e9fa --- /dev/null +++ b/internal/provider/protocols/protocols_nfs_service_resource_alias_test.go @@ -0,0 +1,90 @@ +package protocols_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 TestAccNfsServiceResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Test error + { + Config: testAccNfsServiceResourceConfigAlias("non-existant", "false"), + ExpectError: regexp.MustCompile("svm non-existant not found"), + }, + // Create and read + { + Config: testAccNfsServiceResourceConfigAlias("carchi-test", "false"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v3_enabled", "false"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v40_enabled", "true"), + ), + }, + // update and read + { + Config: testAccNfsServiceResourceConfigAlias("carchi-test", "true"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "svm_name", "carchi-test"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v3_enabled", "true"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v40_enabled", "true"), + ), + }, + // Import and read + { + ResourceName: "netapp-ontap_protocols_nfs_service_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v3_enabled", "true"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_nfs_service_resource.example", "protocol.v40_enabled", "true"), + ), + }, + }, + }) +} + +func testAccNfsServiceResourceConfigAlias(svnName, enableV3 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_protocols_nfs_service_resource" "example" { + # required to know which system to interface with + cx_profile_name = "cluster4" + svm_name = "%s" + enabled = true + protocol = { + v3_enabled = "%s" + v40_enabled = true + v40_features = { + acl_enabled = true + } + } +}`, host, admin, password, svnName, enableV3) +} diff --git a/internal/provider/protocols/protocols_nfs_services_data_source.go b/internal/provider/protocols/protocols_nfs_services_data_source.go index 6b263c14..bd1cd0cc 100644 --- a/internal/provider/protocols/protocols_nfs_services_data_source.go +++ b/internal/provider/protocols/protocols_nfs_services_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewProtocolsNfsServicesDataSource() datasource.DataSource { } } +// NewProtocolsNfsServicesDataSource is a helper function to simplify the provider implementation. +func NewProtocolsNfsServicesDataSourceAlias() datasource.DataSource { + return &ProtocolsNfsServicesDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_nfs_services_data_source", + }, + } +} + // ProtocolsNfsServicesDataSource defines the data source implementation. type ProtocolsNfsServicesDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_igroup_data_source.go b/internal/provider/protocols/protocols_san_igroup_data_source.go index a3553fac..b866213b 100644 --- a/internal/provider/protocols/protocols_san_igroup_data_source.go +++ b/internal/provider/protocols/protocols_san_igroup_data_source.go @@ -3,6 +3,7 @@ package protocols 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 NewProtocolsSanIgroupDataSource() datasource.DataSource { } } +// NewProtocolsSanIgroupDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanIgroupDataSourceAlias() datasource.DataSource { + return &ProtocolsSanIgroupDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_igroup_data_source", + }, + } +} + // ProtocolsSanIgroupDataSource defines the data source implementation. type ProtocolsSanIgroupDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_igroup_resource.go b/internal/provider/protocols/protocols_san_igroup_resource.go index 7085e65a..809b9cc1 100644 --- a/internal/provider/protocols/protocols_san_igroup_resource.go +++ b/internal/provider/protocols/protocols_san_igroup_resource.go @@ -37,6 +37,15 @@ func NewProtocolsSanIgroupResource() resource.Resource { } } +// NewProtocolsSanIgroupResourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanIgroupResourceAlias() resource.Resource { + return &ProtocolsSanIgroupResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_igroup_resource", + }, + } +} + // ProtocolsSanIgroupResource defines the resource implementation. type ProtocolsSanIgroupResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_igroup_resource_alias_test.go b/internal/provider/protocols/protocols_san_igroup_resource_alias_test.go new file mode 100644 index 00000000..5b5b56be --- /dev/null +++ b/internal/provider/protocols/protocols_san_igroup_resource_alias_test.go @@ -0,0 +1,109 @@ +package protocols_test + +import ( + "fmt" + "os" + "testing" + + ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccProtocolsSanIgroupResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create protocols_san_igroup and read + { + Config: testAccProtocolsSanIgroupResourceBasicConfigAlias("acc_test2", "carchi-test"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_igroup_resource.example", "name", "acc_test2"), + ), + }, + // Update options and read + { + Config: testAccProtocolsSanIgroupResourceUpdateConfigAlias("acc_test2", "carchi-test", "windows", "test_acc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_igroup_resource.example", "os_type", "windows"), + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_igroup_resource.example", "name", "acc_test2"), + ), + }, + // Import and read + { + ResourceName: "netapp-ontap_protocols_san_igroup_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s", "acc_test", "carchi-test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_igroup_resource.example", "name", "acc_test"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + +func testAccProtocolsSanIgroupResourceBasicConfigAlias(name string, 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_protocols_san_igroup_resource" "example" { + cx_profile_name = "cluster4" + name = "%s" + svm = { + name = "%s" + } + os_type = "linux" + comment = "test" +}`, host, admin, password, name, svmName) +} + +func testAccProtocolsSanIgroupResourceUpdateConfigAlias(name string, svmName string, osType 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_protocols_san_igroup_resource" "example" { + cx_profile_name = "cluster4" + name = "%s" + svm = { + name = "%s" + } + os_type = "%s" + comment = "%s" +}`, host, admin, password, name, svmName, osType, comment) +} diff --git a/internal/provider/protocols/protocols_san_igroups_data_source.go b/internal/provider/protocols/protocols_san_igroups_data_source.go index 6c7bf161..27b0dd62 100644 --- a/internal/provider/protocols/protocols_san_igroups_data_source.go +++ b/internal/provider/protocols/protocols_san_igroups_data_source.go @@ -3,6 +3,7 @@ package protocols import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces" "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/netapp/terraform-provider-netapp-ontap/internal/utils" @@ -25,6 +26,15 @@ func NewProtocolsSanIgroupsDataSource() datasource.DataSource { } } +// NewProtocolsSanIgroupsDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanIgroupsDataSourceAlias() datasource.DataSource { + return &ProtocolsSanIgroupsDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_igroups_data_source", + }, + } +} + // ProtocolsSanIgroupsDataSource defines the data source implementation. type ProtocolsSanIgroupsDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_lun-map_data_source.go b/internal/provider/protocols/protocols_san_lun-map_data_source.go index f5cbfd24..aefc30ff 100644 --- a/internal/provider/protocols/protocols_san_lun-map_data_source.go +++ b/internal/provider/protocols/protocols_san_lun-map_data_source.go @@ -26,6 +26,15 @@ func NewProtocolsSanLunMapDataSource() datasource.DataSource { } } +// NewProtocolsSanLunMapDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanLunMapDataSourceAlias() datasource.DataSource { + return &ProtocolsSanLunMapDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_lun-map_data_source", + }, + } +} + // ProtocolsSanLunMapDataSource defines the data source implementation. type ProtocolsSanLunMapDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_lun-map_resource.go b/internal/provider/protocols/protocols_san_lun-map_resource.go index 4dad9766..2e8cdba3 100644 --- a/internal/provider/protocols/protocols_san_lun-map_resource.go +++ b/internal/provider/protocols/protocols_san_lun-map_resource.go @@ -33,6 +33,15 @@ func NewProtocolsSanLunMapResource() resource.Resource { } } +// NewProtocolsSanLunMapResourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanLunMapResourceAlias() resource.Resource { + return &ProtocolsSanLunMapsResource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_lun-maps_resource", + }, + } +} + // ProtocolsSanLunMapsResource defines the resource implementation. type ProtocolsSanLunMapsResource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/protocols/protocols_san_lun-map_resource_alias_test.go b/internal/provider/protocols/protocols_san_lun-map_resource_alias_test.go new file mode 100644 index 00000000..b62ba521 --- /dev/null +++ b/internal/provider/protocols/protocols_san_lun-map_resource_alias_test.go @@ -0,0 +1,72 @@ +package protocols_test + +import ( + "fmt" + "os" + "testing" + + ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccProtocolsSanLunMapResourceAlias(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { ntest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create protocols_san_lun-maps and read + { + Config: testAccProtocolsSanLunMapResourceBasicConfigAlias("/vol/lunTest/ACC-import-lun", "test", "carchi-test"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_lun-maps_resource.example", "svm.name", "carchi-test"), + ), + }, + // Import and read + { + ResourceName: "netapp-ontap_protocols_san_lun-maps_resource.example", + ImportState: true, + ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "carchi-test", "acc_test", "/vol/lunTest/test", "cluster4"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("netapp-ontap_protocols_san_lun-maps_resource.example", "svm.name", "carchi-test"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + +func testAccProtocolsSanLunMapResourceBasicConfigAlias(lunName string, igroupName string, 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_protocols_san_lun-maps_resource" "example" { + cx_profile_name = "cluster4" + svm = { + name = "%s" + } + lun = { + name = "%s" + } + igroup = { + name = "%s" + } +}`, host, admin, password, svmName, lunName, igroupName) +} diff --git a/internal/provider/protocols/protocols_san_lun-maps_data_source.go b/internal/provider/protocols/protocols_san_lun-maps_data_source.go index 248fa9ac..026884df 100644 --- a/internal/provider/protocols/protocols_san_lun-maps_data_source.go +++ b/internal/provider/protocols/protocols_san_lun-maps_data_source.go @@ -3,6 +3,7 @@ package protocols import ( "context" "fmt" + "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection" "github.com/netapp/terraform-provider-netapp-ontap/internal/provider/svm" @@ -26,6 +27,15 @@ func NewProtocolsSanLunMapsDataSource() datasource.DataSource { } } +// NewProtocolsSanLunMapsDataSourceAlias is a helper function to simplify the provider implementation. +func NewProtocolsSanLunMapsDataSourceAlias() datasource.DataSource { + return &ProtocolsSanLunMapsDataSource{ + config: connection.ResourceOrDataSourceConfig{ + Name: "protocols_san_lun-maps_data_source", + }, + } +} + // ProtocolsSanLunMapsDataSource defines the data source implementation. type ProtocolsSanLunMapsDataSource struct { config connection.ResourceOrDataSourceConfig diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 224932e2..63b956c1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -261,6 +261,17 @@ func (p *ONTAPProvider) Resources(ctx context.Context) []func() resource.Resourc name_services.NewNameServicesLDAPResourceAlias, networking.NewIPInterfaceResourceAlias, networking.NewIPRouteResourceAlias, + protocols.NewCifsLocalGroupMembersResourceAlias, + protocols.NewCifsLocalGroupResourceAlias, + protocols.NewCifsLocalUserResourcAlias, + protocols.NewCifsServiceResourceAlias, + protocols.NewProtocolsCIFSShareResourceAlias, + protocols.NewCifsUserGroupPrivilegeResourceAlias, + protocols.NewExportPolicyResourceAlias, + protocols.NewExportPolicyRuleResourceAlias, + protocols.NewProtocolsNfsServiceResourceAlias, + protocols.NewProtocolsSanIgroupResourceAlias, + protocols.NewProtocolsSanLunMapResourceAlias, } } @@ -357,6 +368,28 @@ func (p *ONTAPProvider) DataSources(ctx context.Context) []func() datasource.Dat networking.NewIPInterfacesDataSourceAlias, networking.NewIPRouteDataSourceAlias, networking.NewIPRoutesDataSourceAlias, + protocols.NewCifsLocalGroupDataSourceAlias, + protocols.NewCifsLocalGroupMemberDataSourceAlias, + protocols.NewCifsLocalGroupMembersDataSourceAlias, + protocols.NewCifsLocalGroupsDataSourceAlias, + protocols.NewCifsLocalUserDataSourceAlias, + protocols.NewCifsLocalUsersDataSourceAlias, + protocols.NewCifsServiceDataSourceAlias, + protocols.NewCifsServicesDataSourceAlias, + protocols.NewProtocolsCIFSShareDataSourceAlias, + protocols.NewProtocolsCIFSSharesDataSourceAlias, + protocols.NewCifsUserGroupPrivilegeDataSourceAlias, + protocols.NewCifsUserGroupPrivilegesDataSourceAlias, + protocols.NewExportPoliciesDataSourceAlias, + protocols.NewExportPolicyDataSourceAlias, + protocols.NewExportPolicyRuleDataSourceAlias, + protocols.NewExportPolicyRulesDataSourceAlias, + protocols.NewProtocolsNfsServiceDataSourceAlias, + protocols.NewProtocolsNfsServicesDataSourceAlias, + protocols.NewProtocolsSanIgroupDataSourceAlias, + protocols.NewProtocolsSanIgroupsDataSourceAlias, + protocols.NewProtocolsSanLunMapDataSourceAlias, + protocols.NewProtocolsSanLunMapsDataSourceAlias, } }