Skip to content

Commit

Permalink
Add Alias mapping for cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Archibald authored and Chris Archibald committed Oct 14, 2024
1 parent eb188d4 commit 962b55d
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 5 deletions.
9 changes: 9 additions & 0 deletions internal/provider/cluster/cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ func NewClusterDataSource() datasource.DataSource {
}
}

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

// ClusterDataSource defines the data source implementation.
//
//nolint:golint
Expand Down
69 changes: 69 additions & 0 deletions internal/provider/cluster/cluster_licensing_license_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cluster_test

import (
"fmt"
"os"
"regexp"
"testing"

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

func TestLicensingLicenseResouceAlias(t *testing.T) {
testLicense := os.Getenv("TF_ACC_NETAPP_LICENSE")
name := "FCP"
credName := "cluster4"
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccLicensingLicenseResourceConfigAlias("testme"),
ExpectError: regexp.MustCompile("1115159"),
},
{
Config: testAccLicensingLicenseResourceConfigAlias(testLicense),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_cluster_licensing_license.cluster_licensing_license", "name", "insight_balance")),
},
// Test importing a resource
{
ResourceName: "netapp-ontap_cluster_licensing_license.cluster_licensing_license",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s", name, credName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_cluster_licensing_license.cluster_licensing_license", "name", "insight_balance")),
},
},
})
}

func testAccLicensingLicenseResourceConfigAlias(key 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_cluster_licensing_license_resource" "cluster_licensing_license" {
# required to know which system to interface with
cx_profile_name = "cluster4"
keys = ["%s"]
}
`, host, admin, password, key)
}
10 changes: 10 additions & 0 deletions internal/provider/cluster/cluster_licensing_license_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
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 NewClusterLicensingLicenseDataSource() datasource.DataSource {
}
}

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

// ClusterLicensingLicenseDataSource defines the data source implementation.
type ClusterLicensingLicenseDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/cluster/cluster_licensing_license_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cluster
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strings"

"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"

"github.com/hashicorp/terraform-plugin-framework/path"

"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -29,6 +30,15 @@ func NewClusterLicensingLicenseResource() resource.Resource {
}
}

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

// ClusterLicensingLicenseResource defines the resource implementation.
type ClusterLicensingLicenseResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
5 changes: 3 additions & 2 deletions internal/provider/cluster/cluster_licensing_license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cluster_test

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
ntest "github.com/netapp/terraform-provider-netapp-ontap/internal/provider"
"os"
"regexp"
"testing"

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

func TestLicensingLicenseResouce(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
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 NewClusterLicensingLicensesDataSource() datasource.DataSource {
}
}

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

// ClusterLicensingLicensesDataSource defines the data source implementation.
type ClusterLicensingLicensesDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/cluster/cluster_peer_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
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 NewClusterPeerDataSource() datasource.DataSource {
}
}

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

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

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

// ClusterPeersResource defines the resource implementation.
type ClusterPeersResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
86 changes: 86 additions & 0 deletions internal/provider/cluster/cluster_peer_resource_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package cluster_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 TestAccClusterPeerResourceAlias(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { ntest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: ntest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create svm peer and read
{
Config: testAccClusterPeerResourceConfigAlias("10.193.180.110", "10.193.176.189"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_cluster_peer.example", "remote.ip_addresses.0", "10.193.180.110"),
),
},
// Update applications
{
Config: testAccClusterPeerResourceConfigAlias("10.193.180.109", "10.193.176.189"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_cluster_peer.example", "remote.ip_addresses.0", "10.193.180.109"),
),
},
// Import and read
{
ResourceName: "netapp-ontap_cluster_peer.example",
ImportState: true,
ImportStateId: fmt.Sprintf("%s,%s", "acc_test_cluster2", "cluster4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_cluster_peer.example", "name", "acc_test_cluster2"),
),
},
},
})
}
func testAccClusterPeerResourceConfigAlias(remotIP, sourceIP string) string {
host := os.Getenv("TF_ACC_NETAPP_HOST2")
admin := os.Getenv("TF_ACC_NETAPP_USER")
password := os.Getenv("TF_ACC_NETAPP_PASS")
password2 := os.Getenv("TF_ACC_NETAPP_PASS2")
host2 := os.Getenv("TF_ACC_NETAPP_HOST")
if host == "" || admin == "" || password == "" {
fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_HOST, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS and TF_ACC_NETAPP_PASS2 must be set for acceptance tests")
os.Exit(1)
}
return fmt.Sprintf(`
provider "netapp-ontap" {
connection_profiles = [
{
name = "cluster4"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
{
name = "cluster3"
hostname = "%s"
username = "%s"
password = "%s"
validate_certs = false
},
]
}
resource "netapp-ontap_cluster_peers_resource" "example" {
cx_profile_name = "cluster4"
remote = {
ip_addresses = ["%s"]
}
source_details = {
ip_addresses = ["%s"]
}
peer_cx_profile_name = "cluster3"
passphrase = "12345678"
peer_applications = ["snapmirror"]
}`, host, admin, password2, host2, admin, password, remotIP, sourceIP)
}
10 changes: 10 additions & 0 deletions internal/provider/cluster/cluster_peers_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
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 NewClusterPeersDataSource() datasource.DataSource {
}
}

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

// ClusterPeersDataSource defines the data source implementation.
type ClusterPeersDataSource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
12 changes: 11 additions & 1 deletion internal/provider/cluster/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cluster
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"log"
"strings"

"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -35,6 +36,15 @@ func NewClusterResource() resource.Resource {
}
}

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

// ClusterResource defines the resource implementation.
type ClusterResource struct {
config connection.ResourceOrDataSourceConfig
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/cluster/cluster_schedule_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cluster
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 NewClusterScheduleDataSource() datasource.DataSource {
}
}

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

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

0 comments on commit 962b55d

Please sign in to comment.