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

Added acceptance test for Dhcp options in various resources that supports it #65

Merged
merged 15 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
8 changes: 8 additions & 0 deletions docs/resources/dhcp_fixed_address.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" {
tags = {
location : "site1"
}
dhcp_options = [
{
description = "Option 1"
option_code = "234"
option_value = "true"
type = "boolean"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work. description is not a field part of dhcp_options. Also option_code is an UUID for the dhcp_option_code object and not just the code. And type here is either option or group.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

]
depends_on = [bloxone_ipam_subnet.example]
}
```
Expand Down
9 changes: 9 additions & 0 deletions docs/resources/ipam_subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ resource "bloxone_ipam_subnet" "example_na_s" {
tags = {
site = "Site A"
}
#dhcp options
dhcp_options = [
{
description = "Option 1"
option_code = "234"
option_value = "true"
type = "boolean"
}
]
}
```

Expand Down
8 changes: 8 additions & 0 deletions examples/resources/bloxone_dhcp_fixed_address/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" {
tags = {
location : "site1"
}
dhcp_options = [
{
description = "Option 1"
option_code = "234"
option_value = "true"
type = "boolean"
}
]
depends_on = [bloxone_ipam_subnet.example]
}
9 changes: 9 additions & 0 deletions examples/resources/bloxone_ipam_subnet/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ resource "bloxone_ipam_subnet" "example_na_s" {
tags = {
site = "Site A"
}
#dhcp options
dhcp_options = [
{
description = "Option 1"
option_code = "234"
option_value = "true"
type = "boolean"
}
]
}
67 changes: 67 additions & 0 deletions internal/service/ipam/api_address_block_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,38 @@ func TestAccAddressBlockResource_DhcpConfig(t *testing.T) {
})
}

func TestAccAddressBlockResource_DhcpOptions(t *testing.T) {
var resourceName = "bloxone_ipam_address_block.test_dhcp_options"
var v1, v2 ipam.IpamsvcAddressBlock

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read
{
Config: testAccAddressBlockDhcpOptionOption("192.168.0.0", "16", "option", "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAddressBlockExists(context.Background(), resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.0.option_value", "true"),
resource.TestCheckResourceAttrPair(resourceName, "dhcp_options.0.option_code", "bloxone_dhcp_option_code.test", "id"),
),
},
// Update and Read
{
Config: testAccAddressBlockDhcpOptionsGroup("192.168.0.0", "16", "group"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAddressBlockDestroy(context.Background(), &v1),
testAccCheckAddressBlockExists(context.Background(), resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func TestAccAddressBlockResource_HeaderOptionFilename(t *testing.T) {
var resourceName = "bloxone_ipam_address_block.test_header_option_filename"
var v ipam.IpamsvcAddressBlock
Expand Down Expand Up @@ -987,6 +1019,41 @@ resource "bloxone_ipam_address_block" "test_ddns_domain" {
return strings.Join([]string{testAccBaseWithIPSpace(), config}, "")
}

func testAccAddressBlockDhcpOptionOption(name string, cidr string, type_, optValue string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_address_block" "test_dhcp_options" {
address = %q
cidr = %q
space = bloxone_ipam_ip_space.test.id
dhcp_options = [
{
type = %q
option_code = bloxone_dhcp_option_code.test.id
option_value = %q
}
]
}
`, name, cidr, type_, optValue)
return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "")
}

func testAccAddressBlockDhcpOptionsGroup(name string, cidr string, type_ string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_address_block" "test_dhcp_options" {
address = %q
cidr = %q
space = bloxone_ipam_ip_space.test.id
dhcp_options = [
{
type = %q
group = bloxone_dhcp_option_group.test.id
}
]
}
`, name, cidr, type_)
return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "")
}

func testAccAddressBlockDdnsGenerateName(address string, cidr string, ddnsGenerateName string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_address_block" "test_ddns_generate_name" {
Expand Down
73 changes: 73 additions & 0 deletions internal/service/ipam/api_fixed_address_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,38 @@ func TestAccFixedAddressResource_DisableDhcp(t *testing.T) {
})
}

func TestAccFixedAddressResource_DhcpOptions(t *testing.T) {
var resourceName = "bloxone_dhcp_fixed_address.test_dhcp_options"
var v1, v2 ipam.IpamsvcFixedAddress

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read
{
Config: testAccFixedAddressDhcpOptionsOption("10.0.0.10", "mac", "aa:aa:aa:aa:aa:aa", "Fixed_address_dhcp_option", "option", "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFixedAddressExists(context.Background(), resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.0.option_value", "true"),
resource.TestCheckResourceAttrPair(resourceName, "dhcp_options.0.option_code", "bloxone_dhcp_option_code.test", "id"),
),
},
// Update and Read
{
Config: testAccFixedAddressDhcpOptionsGroup("10.0.0.10", "mac", "aa:aa:aa:aa:aa:aa", "Fixed_address_dhcp_option", "group"),
Check: resource.ComposeTestCheckFunc(
testAccCheckFixedAddressDestroy(context.Background(), &v1),
testAccCheckFixedAddressExists(context.Background(), resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func TestAccFixedAddressResource_HeaderOptionFilename(t *testing.T) {
var resourceName = "bloxone_dhcp_fixed_address.test_header_option_filename"
var v ipam.IpamsvcFixedAddress
Expand Down Expand Up @@ -631,6 +663,47 @@ resource "bloxone_dhcp_fixed_address" "test_disable_dhcp" {
return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), config}, "")
}

func testAccFixedAddressDhcpOptionsOption(address string, matchType string, matchValue string, name, type_, optValue string) string {
config := fmt.Sprintf(`
resource "bloxone_dhcp_fixed_address" "test_dhcp_options" {
ip_space = bloxone_ipam_ip_space.test.id
address = %q
match_type = %q
match_value = %q
name = %q
depends_on = [bloxone_ipam_subnet.test]
dhcp_options = [
{
type = %q
option_code = bloxone_dhcp_option_code.test.id
option_value = %q
}
]
}
`, address, matchType, matchValue, name, type_, optValue)
return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "")
}

func testAccFixedAddressDhcpOptionsGroup(address string, matchType string, matchValue string, name, type_ string) string {
config := fmt.Sprintf(`
resource "bloxone_dhcp_fixed_address" "test_dhcp_options" {
ip_space = bloxone_ipam_ip_space.test.id
address = %q
match_type = %q
match_value = %q
name = %q
depends_on = [bloxone_ipam_subnet.test]
dhcp_options = [
{
type = %q
group = bloxone_dhcp_option_group.test.id
}
]
}
`, address, matchType, matchValue, name, type_)
return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "")
}

func testAccFixedAddressHeaderOptionFilename(address string, matchType string, matchValue string, headerOptionFilename string) string {
config := fmt.Sprintf(`
resource "bloxone_dhcp_fixed_address" "test_header_option_filename" {
Expand Down
129 changes: 129 additions & 0 deletions internal/service/ipam/api_ip_space_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -312,6 +313,70 @@ func TestAccIpSpaceResource_DdnsGeneratedPrefix(t *testing.T) {
})
}

func TestAccIpSpaceResource_DhcpOptions(t *testing.T) {
var resourceName = "bloxone_ipam_ip_space.test_dhcp_options"
var v1, v2 ipam.IpamsvcIPSpace

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read
{
Config: testAccIpSpaceDhcpOptionsOption("ipspace_dhcp_options_test", "option", "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIpSpaceExists(context.Background(), resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.0.option_value", "true"),
resource.TestCheckResourceAttrPair(resourceName, "dhcp_options.0.option_code", "bloxone_dhcp_option_code.test", "id"),
),
},
// Update and Read
{
Config: testAccIpSpaceDhcpOptionsGroup("ipspace_dhcp_options_test", "group"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIpSpaceDestroy(context.Background(), &v1),
testAccCheckIpSpaceExists(context.Background(), resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func TestAccIpSpaceResource_DhcpOptionsV6(t *testing.T) {
var resourceName = "bloxone_ipam_ip_space.test_dhcp_options_v6"
var v1, v2 ipam.IpamsvcIPSpace

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read
{
Config: testAccIpSpaceDhcpOptionsOptionV6("ipspace_dhcp_options_test", "option", "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIpSpaceExists(context.Background(), resourceName, &v1),
resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.#", "1"),
resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.0.option_value", "true"),
resource.TestCheckResourceAttrPair(resourceName, "dhcp_options_v6.0.option_code", "bloxone_dhcp_option_code.test", "id"),
),
},
// Update and Read
{
Config: testAccIpSpaceDhcpOptionsGroupV6("ipspace_dhcp_options_test", "group"),
Check: resource.ComposeTestCheckFunc(
testAccCheckIpSpaceDestroy(context.Background(), &v1),
testAccCheckIpSpaceExists(context.Background(), resourceName, &v2),
resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.#", "1"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func TestAccIpSpaceResource_DdnsSendUpdates(t *testing.T) {
var resourceName = "bloxone_ipam_ip_space.test_ddns_send_updates"
var v ipam.IpamsvcIPSpace
Expand Down Expand Up @@ -909,6 +974,70 @@ resource "bloxone_ipam_ip_space" "test_dhcp_config" {
`, name, abandonedReclaimTime, abandonedReclaimTimeV6, allowUnknown, allowUnknownV6, ignoreClientUid, leaseTime, leaseTimeV6)
}

func testAccIpSpaceDhcpOptionsOption(name string, type_, optValue string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_ip_space" "test_dhcp_options" {
name = %q
dhcp_options = [
{
type = %q
option_code = bloxone_dhcp_option_code.test.id
option_value = %q
}
]
}
`, name, type_, optValue)
return strings.Join([]string{testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "")

}

func testAccIpSpaceDhcpOptionsGroup(name string, type_ string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_ip_space" "test_dhcp_options" {
name = %q
dhcp_options = [
{
type = %q
group = bloxone_dhcp_option_group.test.id
}
]
}
`, name, type_)
return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "")

}

func testAccIpSpaceDhcpOptionsOptionV6(name string, type_, optValue string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" {
name = %q
dhcp_options_v6 = [
{
type = %q
option_code = bloxone_dhcp_option_code.test.id
option_value = %q
}
]
}
`, name, type_, optValue)
return strings.Join([]string{testAccOptionCodeBasicConfigV6("234", "test_dhcp_option_code", "boolean"), config}, "")
}

func testAccIpSpaceDhcpOptionsGroupV6(name string, type_ string) string {
config := fmt.Sprintf(`
resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" {
name = %q
dhcp_options_v6 = [
{
type = %q
group = bloxone_dhcp_option_group.test.id
}
]
}
`, name, type_)
return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip6"), config}, "")
}

func testAccIpSpaceHeaderOptionFilename(name, headerOptionFilename string) string {
return fmt.Sprintf(`
resource "bloxone_ipam_ip_space" "test_header_option_filename" {
Expand Down
13 changes: 13 additions & 0 deletions internal/service/ipam/api_option_code_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ resource "bloxone_dhcp_option_code" "test" {
return strings.Join([]string{testAccOptionSpace("test_option_space", "ip4"), config}, "")
}

func testAccOptionCodeBasicConfigV6(code, name, type_ string) string {
config := fmt.Sprintf(`
resource "bloxone_dhcp_option_code" "test" {
code = %q
name = %q
option_space = bloxone_dhcp_option_space.test.id
type = %q
}
`, code, name, type_)

return strings.Join([]string{testAccOptionSpace("test_option_space", "ip6"), config}, "")
}

func testAccOptionCodeArray(code, name, type_, array string) string {
config := fmt.Sprintf(`
resource "bloxone_dhcp_option_code" "test_array" {
Expand Down
Loading
Loading