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

Add Gateway to Datasource ipv4_network and ipv6_network #426

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/data-sources/infoblox_ipv4_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The data source for the network object allows you to get the following parameter
* `cidr`: the network block which corresponds to the network, in CIDR notation. Example: `192.0.17.0/24`
* `comment`: a description of the network. This is a regular comment. Example: `Untrusted network`.
* `ext_attrs`: The set of extensible attributes, if any. The content is formatted as string of JSON map. Example: `"{\"Owner\":\"State Library\",\"Administrator\":\"unknown\"}"`.
* `gateway`: the gateway IP defined in network options (routers'). Example: `192.0.17.1`


For usage of filters, add the fields as keys and appropriate values to be passed to the keys like `name`, `view` corresponding to object.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/infoblox_ipv6_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The data source for the network object allows you to get the following parameter
* `cidr`: the network block which corresponds to the network, in CIDR notation. Example: `2002:1f93:0:4::/96`
* `comment`: a description of the network. This is a regular comment. Example: `Untrusted network`.
* `ext_attrs`: The set of extensible attributes, if any. The content is formatted as string of JSON map. Example: `"{\"Owner\":\"State Library\",\"Administrator\":\"unknown\"}"`.
* `gateway`: the gateway IP defined in network options (routers'). Example: `192.0.17.1`


To retrieve information about IPv6 network that match the specified filters, use the `filters` argument and specify the parameters mentioned in the below table. These are the searchable parameters of the corresponding object in Infoblox NIOS WAPI. If you do not specify any parameter, the data source retrieves information about all host records in the NIOS Grid.
Expand Down
25 changes: 25 additions & 0 deletions infoblox/datasource_infoblox_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func dataSourceNetwork() *schema.Resource {
Computed: true,
Description: "The Extensible attributes for network datasource, as a map in JSON format",
},
"gateway": {
Type: schema.TypeString,
Optional: true,
Description: "The Gateway IP Address (identified using Options routers)",
},
},
},
},
Expand All @@ -63,6 +68,7 @@ func dataSourceIPv4NetworkRead(ctx context.Context, d *schema.ResourceData, m in

n := &ibclient.Ipv4Network{}
n.SetReturnFields(append(n.ReturnFields(), "extattrs"))
n.SetReturnFields(append(n.ReturnFields(), "options"))

filters := filterFromMap(d.Get("filters").(map[string]interface{}))
qp := ibclient.NewQueryParams(false, filters)
Expand Down Expand Up @@ -125,6 +131,15 @@ func flattenIpv4Network(network ibclient.Ipv4Network) (map[string]interface{}, e
res["comment"] = *network.Comment
}

if network.Options != nil {
for _, opt := range network.Options {
if opt.Name == "routers" {
res["gateway"] = opt.Value
break
}
}
}

return res, nil
}

Expand Down Expand Up @@ -154,6 +169,15 @@ func flattenIpv6Network(network ibclient.Ipv6Network) (map[string]interface{}, e
res["comment"] = *network.Comment
}

if network.Options != nil {
for _, opt := range network.Options {
if opt.Name == "routers" {
res["gateway"] = opt.Value
break
}
}
}

return res, nil
}

Expand All @@ -164,6 +188,7 @@ func dataSourceIPv6NetworkRead(ctx context.Context, d *schema.ResourceData, m in

n := &ibclient.Ipv6Network{}
n.SetReturnFields(append(n.ReturnFields(), "extattrs"))
n.SetReturnFields(append(n.ReturnFields(), "options"))

filters := filterFromMap(d.Get("filters").(map[string]interface{}))
qp := ibclient.NewQueryParams(false, filters)
Expand Down