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

test cases for host record and network container for next available IP #398

Merged
merged 2 commits into from
Oct 24, 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
175 changes: 171 additions & 4 deletions infoblox/resource_infoblox_ip_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package infoblox

import (
"fmt"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
"sort"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
"regexp"
"sort"
"testing"
)

type v4addrsType []ibclient.HostRecordIpv4Addr
Expand Down Expand Up @@ -850,3 +850,170 @@ func testAccCheckIPAllocationDestroy(s *terraform.State) error {
}
return nil
}

var testResourceIPAllocationIPV4 = `resource "infoblox_ipv4_network" "ipv4_network12" {
cidr = "189.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv4"{
fqdn = "testhostnameip5.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="IPV4"
depends_on = [infoblox_ipv4_network.ipv4_network12,infoblox_zone_auth.zone]
}`
var testResourceIPAllocationIPV6 = `resource "infoblox_ipv6_network" "ipv6_network12" {
cidr = "2002:1f93:0:4::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv6"{
fqdn = "testhostnameip6.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Bengaluru"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="IPV6"
depends_on = [infoblox_ipv6_network.ipv6_network12,infoblox_zone_auth.zone]
}`
var testResourceIPAllocationIPV6IPV4 = `resource "infoblox_ipv6_network" "ipv6_network12" {
cidr = "2002:1f93:0:4::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_ipv4_network" "ipv4_network12" {
cidr = "189.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Bengaluru"
})
}
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "both"{
fqdn = "testhostnameip7.test.com"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Bengaluru"
})
ext_attrs = jsonencode({
Site = "Europe"
})
ip_address_type="Both"
depends_on = [infoblox_ipv6_network.ipv6_network12,infoblox_zone_auth.zone,infoblox_ipv4_network.ipv4_network12]
}`

func TestAcc_resourceNetwork_AllocateNetworkByEA_IPV4_IP_Allocation(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPAllocationIPV4,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.ipv4",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip5.test.com"),
Ipv4Addrs: []ibclient.HostRecordIpv4Addr{*ibclient.NewHostRecordIpv4Addr("189.11.0.1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
Config: testResourceIPAllocationIPV6,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.ipv6",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip6.test.com"),
Ipv6Addrs: []ibclient.HostRecordIpv6Addr{*ibclient.NewHostRecordIpv6Addr("2002:1f93:0:4::1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
Config: testResourceIPAllocationIPV6IPV4,
Check: resource.ComposeTestCheckFunc(
validateIPAllocation(
"infoblox_ip_allocation.both",
&ibclient.HostRecord{
NetworkView: "default",
View: utils.StringPtr("default"),
EnableDns: utils.BoolPtr(true),
Name: utils.StringPtr("testhostnameip7.test.com"),
Ipv4Addrs: []ibclient.HostRecordIpv4Addr{*ibclient.NewHostRecordIpv4Addr("189.11.0.1", "", false, "")},
Ipv6Addrs: []ibclient.HostRecordIpv6Addr{*ibclient.NewHostRecordIpv6Addr("2002:1f93:0:4::1", "", false, "")},
UseTtl: utils.BoolPtr(false),
Comment: utils.StringPtr("host record created"),
Ea: ibclient.EA{
"Site": "Europe",
},
},
)),
},
{
// Negative testcase
Config: `
resource "infoblox_zone_auth" "zone" {
fqdn = "test.com"
}
resource "infoblox_ip_allocation" "ipv4_1"{
fqdn = "testhostnameip6.test.com"
network_view="default"
comment = "host record created"
filter_params = jsonencode({
"*Site" = "Finland"
})
ext_attrs = jsonencode({
Site = "Europe"
})
}`,
ExpectError: regexp.MustCompile("did not return any result"),
},
},
})
}
123 changes: 122 additions & 1 deletion infoblox/resource_infoblox_network_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func validateNetworkContainer(
"the value of 'cidr' field is empty, but expected some value")
}
}

if nc.Cidr != expCidr {
return fmt.Errorf(
"the value of 'cidr' field is '%s', but expected '%s'",
Expand Down Expand Up @@ -551,6 +550,128 @@ func TestAcc_resourceNetworkContainer_ipv4_ea_inheritance(t *testing.T) {
})
}

var testResourceIPv4NetworkContainer = `resource "infoblox_ipv4_network_container" "ipv4_network12" {
cidr = "25.11.0.0/24"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_ipv4_network_container" "ipv4_network13"{
allocate_prefix_len = 26
comment = "network container created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
depends_on = [infoblox_ipv4_network_container.ipv4_network12]
}`

func TestAcc_resourceNetworkContainer_AllocateNetworkByEA_IPV4(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPv4NetworkContainer,
Check: resource.ComposeTestCheckFunc(
validateNetworkContainer(
"infoblox_ipv4_network_container.ipv4_network13",
&ibclient.NetworkContainer{
NetviewName: "default",
Comment: "network container created",
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
// Negative testcase
Config: `
resource "infoblox_ipv4_network_container" "ipv4_network14"{
network_view="default"
comment = "network created"
allocate_prefix_len = 26
filter_params = jsonencode({
"*Site" = "Finland"
})
ext_attrs = jsonencode({
Site = "Europe"
})
}`,
ExpectError: regexp.MustCompile("did not return any result"),
},
},
})
}

var testResourceIPv6NetworkContainer = `resource "infoblox_ipv6_network_container" "ipv6_network12" {
cidr = "002:1f93:0:2::/96"
network_view = "default"
comment = "small network for testing"
ext_attrs = jsonencode({
"Site" = "Darjeeling"
})
}
resource "infoblox_ipv6_network_container" "ipv6_network13"{
allocate_prefix_len = 97
comment = "network container created"
filter_params = jsonencode({
"*Site" = "Darjeeling"
})
ext_attrs = jsonencode({
Site = "Europe"
})
depends_on = [infoblox_ipv6_network_container.ipv6_network12]
}`

func TestAcc_resourceNetworkContainer_AllocateNetworkByEA_IPV6(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkDestroy,
Steps: []resource.TestStep{
{
Config: testResourceIPv6NetworkContainer,
Check: resource.ComposeTestCheckFunc(
validateNetworkContainer(
"infoblox_ipv6_network_container.ipv6_network13",
&ibclient.NetworkContainer{
NetviewName: "default",
Comment: "network container created",
Ea: ibclient.EA{
"Site": "Europe",
},
},
),
),
},
{
// Negative testcase
Config: `
resource "infoblox_ipv6_network_container" "ipv6_network14"{
network_view="default"
comment = "network created"
allocate_prefix_len = 97
filter_params = jsonencode({
"*Site" = "Finland"
})
ext_attrs = jsonencode({
Site = "Europe"
})
}`,
ExpectError: regexp.MustCompile("did not return any result"),
},
},
})
}

func TestAcc_resourceNetworkContainer_ipv6(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down