-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
512 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ jobs: | |
- name: Build | ||
run: | | ||
export GOFLAGS=-buildvcs=false | ||
./scripts/unittest.sh | ||
./scripts/unittest.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "ONTAP: Licensing_License" | ||
subcategory: "cluster" | ||
description: |- | ||
Add/Remove License from ONTAP | ||
--- | ||
|
||
# Resource licensing_license | ||
|
||
Add/Remove License from ONTAP | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "netapp-ontap_cluster_licensing_license_resource" "cluster_licensing_license" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
keys = ["testme"] | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cx_profile_name` (String) Connection profile name | ||
- `keys` (List of String) List of NLF or 26-character keys | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `name` (String) Name of the license | ||
- `scope` (String) Scope of the license | ||
- `serial_number` (String) | ||
- `state` (String) State of the license | ||
|
||
|
44 changes: 44 additions & 0 deletions
44
examples/resources/netapp-ontap_cluster_licensing_license/provider.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
terraform { | ||
required_providers { | ||
netapp-ontap = { | ||
source = "NetApp/netapp-ontap" | ||
version = "0.0.1" | ||
} | ||
} | ||
} | ||
|
||
|
||
provider "netapp-ontap" { | ||
# A connection profile defines how to interface with an ONTAP cluster or vserver. | ||
# At least one is required. | ||
connection_profiles = [ | ||
{ | ||
name = "cluster1" | ||
hostname = "********219" | ||
username = var.username | ||
password = var.password | ||
validate_certs = var.validate_certs | ||
}, | ||
{ | ||
name = "cluster2" | ||
hostname = "********222" | ||
username = var.username | ||
password = var.password | ||
validate_certs = var.validate_certs | ||
}, | ||
{ | ||
name = "cluster3" | ||
hostname = "10.193.176.159" | ||
username = var.username | ||
password = var.password | ||
validate_certs = var.validate_certs | ||
}, | ||
{ | ||
name = "cluster4" | ||
hostname = "10.193.180.108" | ||
username = var.username | ||
password = var.password | ||
validate_certs = var.validate_certs | ||
} | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
examples/resources/netapp-ontap_cluster_licensing_license/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "netapp-ontap_cluster_licensing_license_resource" "cluster_licensing_license" { | ||
# required to know which system to interface with | ||
cx_profile_name = "cluster4" | ||
keys = ["testme"] | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/resources/netapp-ontap_cluster_licensing_license/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Terraform will prompt for values, unless a tfvars file is present. | ||
variable "username" { | ||
type = string | ||
} | ||
variable "password" { | ||
type = string | ||
sensitive = true | ||
} | ||
variable "validate_certs" { | ||
type = bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package interfaces | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/restclient" | ||
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils" | ||
) | ||
|
||
// ClusterLicensingLicenseKeyDataModelONTAP a single record from cluster/licensing/licenses | ||
type ClusterLicensingLicenseKeyDataModelONTAP struct { | ||
Name string `mapstructure:"name"` | ||
Scope string `mapstructure:"scope"` | ||
State string `mapstructure:"state"` | ||
Licenses []ClusterLicensingLicenseLicensesDataModelONTAP `mapstructure:"licenses"` | ||
} | ||
|
||
// ClusterLicensingLicenseLicensesDataModelONTAP a single serial number | ||
type ClusterLicensingLicenseLicensesDataModelONTAP struct { | ||
SerialNumber string `mapstructure:"serial_number"` | ||
} | ||
|
||
// ClusterLicensingLicenseResourceBodyDataModelONTAP describes the body data model using go types for mapping. | ||
type ClusterLicensingLicenseResourceBodyDataModelONTAP struct { | ||
Keys []string `mapstructure:"keys"` | ||
} | ||
|
||
// GetClusterLicensingLicenses to get /cluster/licensing/licenses info | ||
func GetClusterLicensingLicenses(errorHandler *utils.ErrorHandler, r restclient.RestClient) ([]ClusterLicensingLicenseKeyDataModelONTAP, error) { | ||
api := "/cluster/licensing/licenses" | ||
query := r.NewQuery() | ||
query.Fields([]string{"name", "state", "licenses"}) | ||
statusCode, records, err := r.GetZeroOrMoreRecords(api, query, nil) | ||
if err == nil && records == nil { | ||
err = fmt.Errorf("no response for GET %s", api) | ||
} | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("error reading /cluster/licensing/licenses info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
|
||
var dataONTAP ClusterLicensingLicenseKeyDataModelONTAP | ||
keys := []ClusterLicensingLicenseKeyDataModelONTAP{} | ||
for _, record := range records { | ||
if err := mapstructure.Decode(record, &dataONTAP); err != nil { | ||
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api), | ||
fmt.Sprintf("error: %s, statusCode %d, response %#v", err, statusCode, record)) | ||
} | ||
keys = append(keys, dataONTAP) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Read /cluster/licensing/licenses data source: %#v", dataONTAP)) | ||
return keys, nil | ||
} | ||
|
||
// CreateClusterLicensingLicense to create /cluster/licensing/licenses | ||
func CreateClusterLicensingLicense(errorHandler *utils.ErrorHandler, r restclient.RestClient, body ClusterLicensingLicenseResourceBodyDataModelONTAP) (*ClusterLicensingLicenseKeyDataModelONTAP, error) { | ||
api := "/cluster/licensing/licenses" | ||
var bodyMap map[string]interface{} | ||
if err := mapstructure.Decode(body, &bodyMap); err != nil { | ||
return nil, errorHandler.MakeAndReportError("error encoding /cluster/licensing/licenses body", fmt.Sprintf("error on encoding %s body: %s, body: %#v", api, err, body)) | ||
} | ||
query := r.NewQuery() | ||
query.Add("return_records", "true") | ||
statusCode, response, err := r.CallCreateMethod(api, query, bodyMap) | ||
if err != nil { | ||
return nil, errorHandler.MakeAndReportError("error creating /cluster/licensing/licenses", fmt.Sprintf("error on POST %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
|
||
var dataONTAP ClusterLicensingLicenseKeyDataModelONTAP | ||
// TODO: Fix it may be possible for a Key to unlock mutiple keys | ||
if err := mapstructure.Decode(response.Records[0], &dataONTAP); err != nil { | ||
return nil, errorHandler.MakeAndReportError("error decoding /cluster/licensing/licenses info", fmt.Sprintf("error on decode storage//cluster/licensing/licensess info: %s, statusCode %d, response %#v", err, statusCode, response)) | ||
} | ||
tflog.Debug(errorHandler.Ctx, fmt.Sprintf("Create /cluster/licensing/licenses source - udata: %#v", dataONTAP)) | ||
return &dataONTAP, nil | ||
} | ||
|
||
// DeleteClusterLicensingLicense to delete /cluster/licensing/licenses | ||
func DeleteClusterLicensingLicense(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, serialNumber string) error { | ||
api := "/cluster/licensing/licenses" | ||
query := r.NewQuery() | ||
query.Add("serial_number", serialNumber) | ||
statusCode, _, err := r.CallDeleteMethod(api+"/"+name, query, nil) | ||
if err != nil { | ||
return errorHandler.MakeAndReportError("error deleting /cluster/licensing/licenses", fmt.Sprintf("error on DELETE %s: %s, statusCode %d", api, err, statusCode)) | ||
} | ||
return nil | ||
} |
57 changes: 57 additions & 0 deletions
57
internal/provider/acceptancetests/cluster_licensing_license_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package acceptancetests | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"os" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func TestLicensingLicenseResouce(t *testing.T) { | ||
testLicense := os.Getenv("TF_ACC_NETAPP_LICENSE") | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccLicensingLicenseResourceConfig("testme"), | ||
ExpectError: regexp.MustCompile("1115159"), | ||
}, | ||
{ | ||
Config: testAccLicensingLicenseResourceConfig(testLicense), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("netapp-ontap_cluster_licensing_license_resource.cluster_licensing_license", "name", "insight_balance")), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccLicensingLicenseResourceConfig(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) | ||
} |
Oops, something went wrong.