Skip to content

Commit

Permalink
Merge pull request #323 from NetApp/old-name-protocols
Browse files Browse the repository at this point in the history
add old name support to protocols
  • Loading branch information
carchi8py authored Oct 29, 2024
2 parents 73ee0aa + b9c68d7 commit 1129bea
Show file tree
Hide file tree
Showing 45 changed files with 1,643 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1129bea

Please sign in to comment.