Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not setting ip_address_type and object fields when filter_params is not used. #413

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions infoblox/resource_infoblox_ip_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ func resourceIPAllocation() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "The type of IP address to allocate. This filed is used only when 'filter_params' field is used. Valid values are: IPV4, IPV6, Both. Default value is IPV4",
DefaultFunc: func() (interface{}, error) {
if filterParams, ok := resourceIPAllocation().Schema["filter_params"]; ok && filterParams.Default == nil {
return "IPV4", nil
}
return "IPV4", nil
},
ValidateFunc: validation.StringInSlice([]string{
"IPV4", "IPV6", "Both",
}, false),
Expand Down Expand Up @@ -252,6 +246,9 @@ func resourceAllocationRequest(d *schema.ResourceData, m interface{}) error {
ipv6Addr := d.Get("ipv6_addr").(string)
nextAvailableFilter := d.Get("filter_params").(string)
ipAdressType := d.Get("ip_address_type").(string)
if nextAvailableFilter != "" && ipAdressType == "" {
ipAdressType = "IPV4"
}
if (ipv4Cidr == "" && ipv6Cidr == "" && ipv4Addr == "" && ipv6Addr == "") && nextAvailableFilter == "" {
return fmt.Errorf("allocation through host address record creation needs an IPv4/IPv6 address" +
" or IPv4/IPv6 cidr or filter_params")
Expand Down Expand Up @@ -313,6 +310,7 @@ func resourceAllocationRequest(d *schema.ResourceData, m interface{}) error {
}
newRecordHost, err = objMgr.AllocateNextAvailableIp(fqdn, "record:host", eaMap, nil, false, extAttrs,
comment, disable, nil, ipAdressType, enableDns, false, "", "", networkView, dnsView, useTtl, ttl, aliasStrs)
d.Set("ip_address_type", ipAdressType)
} else {

// enableDns and enableDhcp flags used to create host record with respective flags.
Expand Down Expand Up @@ -542,6 +540,9 @@ func resourceAllocationUpdate(d *schema.ResourceData, m interface{}) (err error)
if d.HasChange("filter_params") {
return fmt.Errorf("changing the value of 'filter_params' field is not allowed")
}
if d.HasChange("ip_address_type") {
return fmt.Errorf("changing the value of 'ip_address_type' field is not allowed")
}

enableDNS := d.Get("enable_dns").(bool)
dnsView := d.Get("dns_view").(string)
Expand Down
10 changes: 9 additions & 1 deletion infoblox/resource_infoblox_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func resourceNetwork() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Description: "The parent object from which the network will be allocated. Valid values are 'networkcontainer' and 'network'. Default value is 'networkcontainer'.",
Default: "networkcontainer",
ValidateFunc: validation.StringInSlice([]string{
"networkcontainer", "network",
}, false),
Expand Down Expand Up @@ -138,6 +137,9 @@ func resourceNetworkCreate(d *schema.ResourceData, m interface{}, isIPv6 bool) e
parentCidr := d.Get("parent_cidr").(string)
nextAvailableFilter := d.Get("filter_params").(string)
object := d.Get("object").(string)
if nextAvailableFilter != "" && object == "" {
object = "networkcontainer"
}
prefixLen := d.Get("allocate_prefix_len").(int)
cidr := d.Get("cidr").(string)
reserveIPv4 := d.Get("reserve_ip").(int)
Expand Down Expand Up @@ -204,6 +206,7 @@ func resourceNetworkCreate(d *schema.ResourceData, m interface{}, isIPv6 bool) e
return fmt.Errorf("allocation of network block failed in network with extra attributes (%s) : %s", nextAvailableFilter, err)
}
d.Set("cidr", network.Cidr)
d.Set("object", object)

} else if cidr != "" {
network, err = objMgr.CreateNetwork(networkViewName, cidr, isIPv6, comment, extAttrs)
Expand Down Expand Up @@ -362,6 +365,7 @@ func resourceNetworkUpdate(d *schema.ResourceData, m interface{}) (err error) {
prevGW, _ := d.GetChange("gateway")
prevPrefLen, _ := d.GetChange("allocate_prefix_len")
prevNextAvailableFilter, _ := d.GetChange("filter_params")
prevObject, _ := d.GetChange("object")
prevResIPv4, _ := d.GetChange("reserve_ip")
prevResIPv6, _ := d.GetChange("reserve_ipv6")
prevComment, _ := d.GetChange("comment")
Expand All @@ -373,6 +377,7 @@ func resourceNetworkUpdate(d *schema.ResourceData, m interface{}) (err error) {
_ = d.Set("gateway", prevGW.(string))
_ = d.Set("allocate_prefix_len", prevPrefLen.(int))
_ = d.Set("filter_params", prevNextAvailableFilter.(string))
_ = d.Set("object", prevObject.(string))
_ = d.Set("reserve_ip", prevResIPv4.(int))
_ = d.Set("reserve_ipv6", prevResIPv6.(int))
_ = d.Set("comment", prevComment.(string))
Expand Down Expand Up @@ -401,6 +406,9 @@ func resourceNetworkUpdate(d *schema.ResourceData, m interface{}) (err error) {
if d.HasChange("filter_params") {
return fmt.Errorf("changing the value of 'filter_params' field is not allowed")
}
if d.HasChange("object") {
return fmt.Errorf("changing the value of 'object' field is not allowed")
}

networkViewName := d.Get("network_view").(string)
oldExtAttrsJSON, newExtAttrsJSON := d.GetChange("ext_attrs")
Expand Down