From 65bca041906e45ef3c3da21efae81a9ecc926b0b Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Fri, 22 Sep 2023 15:56:05 +0530 Subject: [PATCH] list to set --- ibm/service/vpc/resource_ibm_is_vpc.go | 17 ++++++++++++++--- ibm/service/vpc/resource_ibm_is_vpc_test.go | 2 -- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ibm/service/vpc/resource_ibm_is_vpc.go b/ibm/service/vpc/resource_ibm_is_vpc.go index 416284b616..c3df4dcceb 100644 --- a/ibm/service/vpc/resource_ibm_is_vpc.go +++ b/ibm/service/vpc/resource_ibm_is_vpc.go @@ -4,6 +4,7 @@ package vpc import ( + "bytes" "context" "fmt" "log" @@ -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" ) @@ -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{ @@ -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 @@ -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{} @@ -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 diff --git a/ibm/service/vpc/resource_ibm_is_vpc_test.go b/ibm/service/vpc/resource_ibm_is_vpc_test.go index cb84d99271..6f9cc88a66 100644 --- a/ibm/service/vpc/resource_ibm_is_vpc_test.go +++ b/ibm/service/vpc/resource_ibm_is_vpc_test.go @@ -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), ), }, {