Skip to content

Commit

Permalink
list to set
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Sep 22, 2023
1 parent 3eb0e72 commit 65bca04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 14 additions & 3 deletions ibm/service/vpc/resource_ibm_is_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package vpc

import (
"bytes"
"context"
"fmt"
"log"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
)
Expand Down Expand Up @@ -220,9 +222,10 @@ func ResourceIBMISVPC() *schema.Resource {
},

isVPCDnsResolverManualServers: &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Computed: true,
Set: hashManualServersList,
Description: "The manually specified DNS servers for this VPC.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -1221,7 +1224,7 @@ func vpcUpdate(d *schema.ResourceData, meta interface{}, id, name string, hasCha

if newResolverManualServers != nil {
manualServers := []vpcv1.DnsServerPrototype{}
for _, manualServersItem := range newResolverManualServers.([]interface{}) {
for _, manualServersItem := range newResolverManualServers.(*schema.Set).List() {
manualServersItemModel, err := resourceIBMIsVPCMapToDnsServerPrototype(manualServersItem.(map[string]interface{}))
if err != nil {
return err
Expand Down Expand Up @@ -1513,6 +1516,14 @@ func suppressNullVPC(k, old, new string, d *schema.ResourceData) bool {
return false
}

func hashManualServersList(v interface{}) int {
var buf bytes.Buffer
a := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%s-", a["address"].(string)))
buf.WriteString(fmt.Sprintf("%s-", a["zone_affinity"].(string)))
return conns.String(buf.String())
}

// for create dns
func resourceIBMIsVPCMapToVpcdnsPrototype(modelMap map[string]interface{}) (*vpcv1.VpcdnsPrototype, error) {
model := &vpcv1.VpcdnsPrototype{}
Expand All @@ -1537,7 +1548,7 @@ func resourceIBMIsVPCMapToVpcdnsResolverPrototype(modelMap map[string]interface{
if modelMap["manual_servers"] != nil {
model.Type = core.StringPtr("manual")
manualServers := []vpcv1.DnsServerPrototype{}
for _, manualServersItem := range modelMap["manual_servers"].([]interface{}) {
for _, manualServersItem := range modelMap["manual_servers"].(*schema.Set).List() {
manualServersItemModel, err := resourceIBMIsVPCMapToDnsServerPrototype(manualServersItem.(map[string]interface{}))
if err != nil {
return model, err
Expand Down
2 changes: 0 additions & 2 deletions ibm/service/vpc/resource_ibm_is_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ func TestAccIBMISVPC_dns_manual(t *testing.T) {
"ibm_is_vpc.testacc_vpc1", "dns.0.resolver.0.servers.#"),
resource.TestCheckResourceAttr(
"ibm_is_vpc.testacc_vpc1", "dns.0.resolver.0.servers.#", "1"),
resource.TestCheckResourceAttr(
"ibm_is_vpc.testacc_vpc1", "dns.0.resolver.0.manual_servers.0.address", server1Add),
),
},
{
Expand Down

0 comments on commit 65bca04

Please sign in to comment.