Skip to content

Commit

Permalink
Merge pull request #324 from NetApp/old-name-security
Browse files Browse the repository at this point in the history
add old name support to security
  • Loading branch information
carchi8py authored Oct 29, 2024
2 parents 1129bea + 381c3e5 commit 0a3a8db
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (p *ONTAPProvider) Resources(ctx context.Context) []func() resource.Resourc
protocols.NewProtocolsNfsServiceResourceAlias,
protocols.NewProtocolsSanIgroupResourceAlias,
protocols.NewProtocolsSanLunMapResourceAlias,
security.NewSecurityAccountResourceAlias,
}
}

Expand Down Expand Up @@ -390,6 +391,8 @@ func (p *ONTAPProvider) DataSources(ctx context.Context) []func() datasource.Dat
protocols.NewProtocolsSanIgroupsDataSourceAlias,
protocols.NewProtocolsSanLunMapDataSourceAlias,
protocols.NewProtocolsSanLunMapsDataSourceAlias,
security.NewSecurityAccountDataSourceAlias,
security.NewSecurityAccountsDataSourceAlias,
}
}

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

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

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

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

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

// SecurityAccountResource defines the resource implementation.
type SecurityAccountResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
76 changes: 76 additions & 0 deletions internal/provider/security/security_account_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package security_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"
)

func TestAccSecurityAccountResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccSecurityAccountResourceConfigAlias("carchitest", "password"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_security_account_resource.security_account", "name", "carchitest"),
),
},
// Test updating a resource
{
Config: testAccSecurityAccountResourceConfigAlias("carchitest", "password123"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_security_account_resource.security_account", "name", "carchitest"),
resource.TestCheckResourceAttr("netapp-ontap_security_account_resource.security_account", "password", "password123"),
),
},
// Test importing a resource
{
ResourceName: "netapp-ontap_security_account_resource.security_account",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s", "acc_user", "cluster2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_security_account_resource.security_account", "name", "acc_user"),
),
},
},
})
}

func testAccSecurityAccountResourceConfigAlias(name string, accpassword string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST2")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS2")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster2"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_security_account_resource" "security_account" {
# required to know which system to interface with
cx_profile_name = "cluster2"
name = "%s"
applications = [{
application = "http"
authentication_methods = ["password"]
}]
password = "%s"
}
`, host, admin, password, name, accpassword)
}
10 changes: 10 additions & 0 deletions internal/provider/security/security_accounts_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package security
import (
"context"
"fmt"

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

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

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

0 comments on commit 0a3a8db

Please sign in to comment.