From 856ab5499080711a08f1ea85ae800a3f4c62ca16 Mon Sep 17 00:00:00 2001 From: Aish-sp <163982471+Aish-sp@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:18:24 +0530 Subject: [PATCH] bugFix for hostRecord ip_addr_type and disable fields (#396) --- infoblox/resource_infoblox_aaaa_record.go | 2 +- infoblox/resource_infoblox_ip_allocation.go | 18 ++++++++++++------ infoblox/resource_infoblox_ip_association.go | 6 +++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/infoblox/resource_infoblox_aaaa_record.go b/infoblox/resource_infoblox_aaaa_record.go index 6259b466e..1515ae803 100644 --- a/infoblox/resource_infoblox_aaaa_record.go +++ b/infoblox/resource_infoblox_aaaa_record.go @@ -161,7 +161,7 @@ func resourceAAAARecordCreate(d *schema.ResourceData, m interface{}) error { eaMap map[string]string ) - if nextAvailableFilter != "" { + if cidr == "" && ipv6Addr == "" && nextAvailableFilter != "" { err = json.Unmarshal([]byte(nextAvailableFilter), &eaMap) if err != nil { return fmt.Errorf("error unmarshalling extra attributes of network: %s", err) diff --git a/infoblox/resource_infoblox_ip_allocation.go b/infoblox/resource_infoblox_ip_allocation.go index 0a5ecd91c..f0e13acb5 100644 --- a/infoblox/resource_infoblox_ip_allocation.go +++ b/infoblox/resource_infoblox_ip_allocation.go @@ -108,8 +108,13 @@ func resourceIPAllocation() *schema.Resource { "ip_address_type": { Type: schema.TypeString, Optional: true, - Default: "IPV6", Description: "The type of IP address to allocate. Valid values are: IPV4, IPV6, Both", + DefaultFunc: func() (interface{}, error) { + if filterParams, ok := resourceIPAllocation().Schema["filter_params"]; ok && filterParams.Default == nil { + return nil, nil + } + return "IPV4", nil + }, ValidateFunc: validation.StringInSlice([]string{ "IPV4", "IPV6", "Both", }, false), @@ -136,7 +141,7 @@ func resourceIPAllocation() *schema.Resource { Type: schema.TypeBool, Optional: true, Default: false, - Description: "Disables the AAAA-record if set to 'true'.", + Description: "Disables the Host-record if set to 'true'.", }, "internal_id": { Type: schema.TypeString, @@ -277,10 +282,9 @@ func resourceAllocationRequest(d *schema.ResourceData, m interface{}) error { var ( newRecordHost interface{} eaMap map[string]string - //err error ) - if nextAvailableFilter != "" { + if ipv4Addr == "" && ipv4Cidr == "" && ipv6Cidr == "" && ipv6Addr == "" && nextAvailableFilter != "" { err = json.Unmarshal([]byte(nextAvailableFilter), &eaMap) if err != nil { return fmt.Errorf("error unmarshalling extra attributes of network: %s", err) @@ -292,7 +296,7 @@ func resourceAllocationRequest(d *schema.ResourceData, m interface{}) error { // enableDns and enableDhcp flags used to create host record with respective flags. // By default, enableDns is true. newRecordHost, err = objMgr.CreateHostRecord(enableDns, false, fqdn, networkView, dnsView, ipv4Cidr, - ipv6Cidr, ipv4Addr, ipv6Addr, macAddr, "", useTtl, ttl, comment, extAttrs, aliasStrs) + ipv6Cidr, ipv4Addr, ipv6Addr, macAddr, "", useTtl, ttl, comment, extAttrs, aliasStrs, disable) } if err != nil { @@ -574,6 +578,7 @@ func resourceAllocationUpdate(d *schema.ResourceData, m interface{}) (err error) } comment := d.Get("comment").(string) + disable := d.Get("disable").(bool) oldExtAttrsJSON, newExtAttrsJSON := d.GetChange("ext_attrs") @@ -666,7 +671,8 @@ func resourceAllocationUpdate(d *schema.ResourceData, m interface{}) (err error) macAddr, duid, useTtl, ttl, comment, - mergedEAs, aliasStrs) + mergedEAs, + aliasStrs, disable) if err != nil { return fmt.Errorf( "error while updating the host record with ID '%s': %s", d.Id(), err.Error()) diff --git a/infoblox/resource_infoblox_ip_association.go b/infoblox/resource_infoblox_ip_association.go index 930a79c3f..6d0ae6a3e 100644 --- a/infoblox/resource_infoblox_ip_association.go +++ b/infoblox/resource_infoblox_ip_association.go @@ -219,6 +219,7 @@ func resourceIpAssociationCreateUpdateCommon( var ( comment string + disable bool ) if hostRec.Ea != nil { @@ -235,6 +236,9 @@ func resourceIpAssociationCreateUpdateCommon( if hostRec.Comment != nil { comment = *hostRec.Comment } + if hostRec.Disable != nil { + disable = *hostRec.Disable + } alias := hostRec.Aliases @@ -250,7 +254,7 @@ func resourceIpAssociationCreateUpdateCommon( mac, duid, *hostRec.UseTtl, *hostRec.Ttl, comment, - hostRec.Ea, alias) + hostRec.Ea, alias, disable) if err != nil { return fmt.Errorf( "failed to update the resource with ID '%s' (host record with internal ID '%s'): %s",