Skip to content

Commit

Permalink
add skip_config_validation to netapp-ontap_name_services_dns
Browse files Browse the repository at this point in the history
  • Loading branch information
chuyich committed Oct 8, 2024
1 parent 832603e commit f36d4c1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ FEATURES:
ENHANCEMENTS:
* **netapp-ontap_lun**: added `size_unit` option. ([#227](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/227))
* **netapp-ontap_security_account**: Add support for import and update ([#243](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/243))
* **netapp-ontap_name_services_dns**: Add `skip_config_validation`([#316](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/316))

## 1.1.4 (2024-09-05)

Expand Down
5 changes: 2 additions & 3 deletions docs/resources/name_services_dns_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ Create/Modify/Delete and Import a name services DNS resource
```

## Supported Platforms
* On-perm ONTAP system 9.6 or higher
* On-perm ONTAP system 9.9 or higher
* Amazon FSx for NetApp ONTAP

[comment]: <> (TODO: Add support for Amazon FSx for NetApp ONTAP )

## Example Usage
```terraform
resource "netapp-ontap_name_services_dns" "name_services_dns" {
Expand All @@ -47,6 +45,7 @@ resource "netapp-ontap_name_services_dns" "name_services_dns" {

- `dns_domains` (Set of String) List of DNS domains such as 'sales.bar.com'. The first domain is the one that the svm belongs to
- `name_servers` (Set of String) List of IPv4 addresses of name servers such as '123.123.123.123'.
- `skip_config_validation` (Bool) Indicates whether or not the validation for the specified DNS configuration is disabled. (9.9)

### Read-Only

Expand Down
9 changes: 5 additions & 4 deletions internal/interfaces/name_services_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

// NameServicesDNSGetDataModelONTAP describes the GET record data model using go types for mapping.
type NameServicesDNSGetDataModelONTAP struct {
Domains []string `mapstructure:"domains"`
Servers []string `mapstructure:"servers"`
SVM SvmDataModelONTAP `mapstructure:"svm"`
Domains []string `mapstructure:"domains"`
Servers []string `mapstructure:"servers"`
SVM SvmDataModelONTAP `mapstructure:"svm"`
SkipConfigValidation bool `mapstructure:"skip_config_validation"`
}

// NameServicesDNSDataSourceFilterModel describes filter model.
Expand Down Expand Up @@ -111,7 +112,7 @@ func CreateNameServicesDNS(errorHandler *utils.ErrorHandler, r restclient.RestCl

// DeleteNameServicesDNS deletes a DNS
func DeleteNameServicesDNS(errorHandler *utils.ErrorHandler, r restclient.RestClient, uuid string) error {
statusCode, _, err := r.CallDeleteMethod("name-services/dns"+uuid, nil, nil)
statusCode, _, err := r.CallDeleteMethod("name-services/dns/"+uuid, nil, nil)
if err != nil {
return errorHandler.MakeAndReportError("error deleting DNS", fmt.Sprintf("error on DELETE name-services/dns: %s, statusCode %d", err, statusCode))
}
Expand Down
49 changes: 32 additions & 17 deletions internal/provider/name_services/name_services_dns_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package name_services
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"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces"
Expand All @@ -35,11 +39,12 @@ type NameServicesDNSResource struct {

// NameServicesDNSResourceModel describes the resource data model.
type NameServicesDNSResourceModel struct {
CxProfileName types.String `tfsdk:"cx_profile_name"`
SVMName types.String `tfsdk:"svm_name"`
ID types.String `tfsdk:"id"`
Domains []types.String `tfsdk:"dns_domains"`
NameServers []types.String `tfsdk:"name_servers"`
CxProfileName types.String `tfsdk:"cx_profile_name"`
SVMName types.String `tfsdk:"svm_name"`
ID types.String `tfsdk:"id"`
SkipConfigValidation types.Bool `tfsdk:"skip_config_validation"`
Domains []types.String `tfsdk:"dns_domains"`
NameServers []types.String `tfsdk:"name_servers"`
}

// Metadata returns the resource type name.
Expand Down Expand Up @@ -76,6 +81,15 @@ func (r *NameServicesDNSResource) Schema(ctx context.Context, req resource.Schem
MarkdownDescription: "List of IPv4 addresses of name servers such as '123.123.123.123'.",
Optional: true,
},
"skip_config_validation": schema.BoolAttribute{
MarkdownDescription: "Indicates whether or not the validation for the specified DNS configuration is disabled. (9.9)",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
},
}
}
Expand Down Expand Up @@ -129,20 +143,20 @@ func (r *NameServicesDNSResource) Read(ctx context.Context, req resource.ReadReq

data.SVMName = types.StringValue(restInfo.SVM.Name)
data.ID = types.StringValue(restInfo.SVM.UUID)
var servers []types.String
for _, v := range restInfo.Servers {
if !connection.StringInSlice(v, data.NameServers) {
servers = append(servers, types.StringValue(v))

if restInfo.Servers != nil {
data.NameServers = make([]types.String, len(restInfo.Servers))
for index, server := range restInfo.Servers {
data.NameServers[index] = types.StringValue(server)
}
}
data.NameServers = servers
var domains []types.String
for _, v := range restInfo.Domains {
if !connection.StringInSlice(v, data.Domains) {
domains = append(domains, types.StringValue(v))

if restInfo.Domains != nil {
data.Domains = make([]types.String, len(restInfo.Domains))
for index, domain := range restInfo.Domains {
data.Domains[index] = types.StringValue(domain)
}
}
data.Domains = domains

// Write logs using the tflog package
// Documentation: https://terraform.io/plugin/log
Expand All @@ -168,6 +182,7 @@ func (r *NameServicesDNSResource) Create(ctx context.Context, req resource.Creat

body.SVM.Name = data.SVMName.ValueString()
body.SVM.UUID = data.ID.ValueString()

var servers, domains []string
for _, v := range data.NameServers {
servers = append(servers, v.ValueString())
Expand All @@ -177,7 +192,7 @@ func (r *NameServicesDNSResource) Create(ctx context.Context, req resource.Creat
}
body.Servers = servers
body.Domains = domains

body.SkipConfigValidation = data.SkipConfigValidation.ValueBool()
client, err := connection.GetRestClient(errorHandler, r.config, data.CxProfileName)
if err != nil {
// error reporting done inside NewClient
Expand Down
12 changes: 10 additions & 2 deletions internal/provider/name_services/name_services_dns_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package name_services_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 TestAccNameServicesDNSResource(t *testing.T) {
Expand All @@ -21,6 +22,12 @@ func TestAccNameServicesDNSResource(t *testing.T) {
Config: testAccNameServicesDNSResourceConfig("non-existant"),
ExpectError: regexp.MustCompile("2621462"),
},
{
Config: testAccNameServicesDNSResourceConfig("svm5"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("netapp-ontap_name_services_dns.name_services_dns", "svm_name", "svm5"),
),
},
// Test importing a resource
{
ResourceName: "netapp-ontap_name_services_dns.name_services_dns",
Expand Down Expand Up @@ -62,6 +69,7 @@ resource "netapp-ontap_name_services_dns" "name_services_dns" {
svm_name = "%s"
name_servers = ["1.1.1.1", "2.2.2.2"]
dns_domains = ["foo.bar.com", "boo.bar.com"]
skip_config_validation = true
}
`, host, admin, password, svmName)
}

0 comments on commit f36d4c1

Please sign in to comment.