diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af0307e..e93c66f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/resources/name_services_dns_resource.md b/docs/resources/name_services_dns_resource.md index 8e3050a1..353b17a0 100644 --- a/docs/resources/name_services_dns_resource.md +++ b/docs/resources/name_services_dns_resource.md @@ -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" { @@ -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 diff --git a/internal/interfaces/name_services_dns.go b/internal/interfaces/name_services_dns.go index b8fbf0a3..fb8d225a 100644 --- a/internal/interfaces/name_services_dns.go +++ b/internal/interfaces/name_services_dns.go @@ -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. @@ -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)) } diff --git a/internal/provider/name_services/name_services_dns_resource.go b/internal/provider/name_services/name_services_dns_resource.go index d8870200..50c86fc9 100644 --- a/internal/provider/name_services/name_services_dns_resource.go +++ b/internal/provider/name_services/name_services_dns_resource.go @@ -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" @@ -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. @@ -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(), + }, + }, }, } } @@ -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 @@ -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()) @@ -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 diff --git a/internal/provider/name_services/name_services_dns_resource_test.go b/internal/provider/name_services/name_services_dns_resource_test.go index 7f8b4985..3f1e3e5c 100644 --- a/internal/provider/name_services/name_services_dns_resource_test.go +++ b/internal/provider/name_services/name_services_dns_resource_test.go @@ -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) { @@ -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", @@ -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) }