Skip to content

Commit

Permalink
working example for an import for DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Nov 7, 2023
1 parent b64dbe8 commit a8c0194
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
13 changes: 12 additions & 1 deletion docs/resources/name_services_dns_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ resource "netapp-ontap_name_services_dns_resource" "name_services_dns" {
- `id` (String) UUID of svm

## Import
Import has not been tested, and may not work. We are working on getting this documented for the next release..
### Terrafrom import
terraform import netapp-ontap_name_services_dns_resource.`name` `svm_name`,`cx_profile_name`
* name -- name you want to give the resource in terraform
* svm_name -- name of the svm the resource belongs to
* cx_profile_name -- name of the connection profile to use

For example
```shell
terraform import netapp-ontap_name_services_dns_resource.dns_import ansibleSVM,cluster4
```

!> The terraform import CLI command can only import resources into the state. Importing via the CLI does not generate configuration. If you want to generate the accompanying configuration for imported resources, use the import block instead.


13 changes: 13 additions & 0 deletions internal/interfaces/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package interfaces

import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

// NameDataModel is the standard name/uuid pair that required by most resources
type NameDataModel struct {
Name string
UUID string
}

func StringInSlice(str string, list []types.String) bool {

Check failure on line 13 in internal/interfaces/common.go

View workflow job for this annotation

GitHub Actions / build

exported function StringInSlice should have comment or be unexported
for _, v := range list {
if v.ValueString() == str {
return true
}
}
return false
}
8 changes: 6 additions & 2 deletions internal/provider/name_services_dns_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ func (r *NameServicesDNSResource) Read(ctx context.Context, req resource.ReadReq
data.ID = types.StringValue(restInfo.SVM.UUID)
var servers []types.String
for _, v := range restInfo.Servers {
servers = append(data.NameServers, types.StringValue(v))
if !interfaces.StringInSlice(v, data.NameServers) {
servers = append(data.NameServers, types.StringValue(v))
}
}
data.NameServers = servers
var domains []types.String
for _, v := range restInfo.Domains {
domains = append(data.Domains, types.StringValue(v))
if !interfaces.StringInSlice(v, data.Domains) {
domains = append(data.Domains, types.StringValue(v))
}
}
data.Domains = domains

Expand Down

0 comments on commit a8c0194

Please sign in to comment.