Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Jul 26, 2023
1 parent ac227bb commit 5626a35
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 16 deletions.
6 changes: 2 additions & 4 deletions .github/ISSUE_TEMPLATE/00_bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ body:
attributes:
label: Affected Resource(s)
description: Please list the affected resource(s) and/or data source(s).
placeholder: "* ONTAP_xxx"
placeholder: "* netapp-ontap_xxx"
validations:
required: false

Expand Down Expand Up @@ -98,8 +98,6 @@ body:
Terraform configurations or debug logs under 25MB may be [attached directly in the field](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/attaching-files). Files larger than this should be uploaded to a file hosting service and a link shared.
For your security you can also encrypt the files using our [GPG public key](https://keybase.io/hashicorp).
**Note:** These form fields do not automatically render, so you will need to use [code fence(s)](https://help.github.com/articles/basic-writing-and-formatting-syntax/#quoting-code) to achieve proper formatting.
- type: textarea
Expand Down Expand Up @@ -170,7 +168,7 @@ body:
attributes:
label: Would you like to implement a fix?
description: |
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the ::TODO:: [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
options:
- "No"
- "Yes"
Expand Down
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/01_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ body:
value: |
# Thank you for raising a documentation issue!
This form is meant to alert the maintainers to an issue with the provider documentation found on the [Terraform Registry](https://registry.terraform.io/providers/hashicorp/ONTAP/latest) (such as resource and data source documentation, guides and examples), as well as the [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/).
This form is meant to alert the maintainers to an issue with the provider documentation found on the ::TODO:: [Terraform Registry](https://registry.terraform.io/providers/hashicorp/ONTAP/latest) (such as resource and data source documentation, guides and examples), as well as the ::TODO:: [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/).
Documentation edits are generally a bit less involved, so are often a great entrypoint if you've ever been interested in [contributing](https://hashicorp.github.io/terraform-provider-ONTAP/documentation-changes/)!
Documentation edits are generally a bit less involved, so are often a great entrypoint if you've ever been interested in ::TODO:: [contributing](https://hashicorp.github.io/terraform-provider-ONTAP/documentation-changes/)!
- type: input
id: registry_link
Expand Down Expand Up @@ -44,7 +44,7 @@ body:
attributes:
label: Would you like to implement a fix?
description: |
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the ::TODO:: [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
options:
- "No"
- "Yes"
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/02_enhancement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ body:
id: affected
attributes:
label: Affected Resource(s) and/or Data Source(s)
placeholder: "* ONTAP_xxx_yyy"
placeholder: "* netapp_ontap_xxx_yyy"
validations:
required: false

Expand Down Expand Up @@ -56,7 +56,7 @@ body:
attributes:
label: Would you like to implement a fix?
description: |
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the ::TODO:: [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
options:
- "No"
- "Yes"
Expand Down
11 changes: 8 additions & 3 deletions .github/ISSUE_TEMPLATE/03_new_resource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ body:
This form is intended to be used when requesting an entirely new resource, data source, or service be added to the provider. If you're looking for a change to be made to an existing resource or data source, consider submitting either the "Request an Enhancement" or Report a Bug" forms instead.
When possible, it's helpful to check the [ONTAP Go SDK](https://pkg.go.dev/github.com/ONTAP/ONTAP-sdk-go/service) or [ONTAP Go SDK v2](https://pkg.go.dev/github.com/ONTAP/ONTAP-sdk-go-v2#section-directories) to determine whether functionality exists to enable the requested feature. It is **not** required that you do this. Any references found when searching can be added to the "References" field below to give maintainers or the community a head start.
When possible, it's helpful to check the [ONTAP REST API](https://library.netapp.com/ecmdocs/ECMLP2885799/html/index.html) to determine whether functionality exists to enable the requested feature. It is **not** required that you do this. Any references found when searching can be added to the "References" field below to give maintainers or the community a head start.
Please update the title to match what you're requesting, e.g.:
- `[New Resource]:` - for new resource requests
- `[New Data Source]:` - for new data source requests
- `[New Service]:` - for new ONTAP services
Please add a label on the right to match what your requesting, e.g.:
- `New Resource` - for new resource requests
- `New Data Source` - for new data source requests
- type: textarea
id: description
Expand All @@ -33,7 +38,7 @@ body:
Please list any new resource(s) and/or data source(s). The naming format is `ONTAP_<service>_<resource_name>`, e.g., `ONTAP_lambda_function`.
A best guess is helpful, even if you're unsure of exactly what the end result will look like. This helps maintainers and the community better understand how you (someone who is in need of this request) envisions it.
placeholder: "* ONTAP_xxx_yyy"
placeholder: "* netapp_ontap_xxx_yyy"
validations:
required: true

Expand Down Expand Up @@ -65,7 +70,7 @@ body:
attributes:
label: Would you like to implement a fix?
description: |
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
If you plan to implement a fix for this, check this box to let the maintainers and community know (you can update this later if you change your mind). If this would be your first contribution, refer to the ::TODO:: [contribution guide](https://hashicorp.github.io/terraform-provider-ONTAP/) for tips on getting started.
options:
- "No"
- "Yes"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Build
run: |
go install golang.org/x/lint/golint@latest
golint -set_exit_status ./...
golint -set_exit_status ./...
2 changes: 1 addition & 1 deletion .github/workflows/reportcard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
make install
go install ./cmd/goreportcard-cli
- name: run report card
run: goreportcard-cli -v -t 90
run: goreportcard-cli -v -t 90
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Build
run: |
export GOFLAGS=-buildvcs=false
./scripts/unittest.sh
./scripts/unittest.sh
39 changes: 39 additions & 0 deletions docs/resources/cluster_licensing_license_resource.md
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


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
}
]
}
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"]
}
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
}
88 changes: 88 additions & 0 deletions internal/interfaces/cluster_licensing_license.go
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
}
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)
}
Loading

0 comments on commit 5626a35

Please sign in to comment.