From c83b86918ecb2af2391d5e2dfb13cde40306744b Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Mon, 5 Feb 2024 10:44:17 +0530 Subject: [PATCH 01/11] DHCP option support for subnet --- .../service/ipam/api_subnet_resource_test.go | 73 +++++++++++++++++++ internal/service/ipam/model_ipamsvc_subnet.go | 4 + 2 files changed, 77 insertions(+) diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index c1779478..b90d1755 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -403,6 +403,40 @@ func TestAccSubnetResource_DdnsGeneratedPrefix(t *testing.T) { }) } +func TestAccSubnetResource_DhcpOptions(t *testing.T) { + var resourceName = "bloxone_ipam_subnet.test_dhcp_options" + var v1, v2 ipam.IpamsvcSubnet + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read + { + Config: testAccSubnetDhcpOptionsOption("10.0.0.0", 24, "option_group_test", "option", "true"), + Check: resource.ComposeTestCheckFunc( + testAccCheckSubnetExists(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: testAccSubnetDhcpOptionsGroup("10.0.0.0", 24, "option_group_test", "group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckSubnetDestroy(context.Background(), &v1), + testAccCheckSubnetExists(context.Background(), resourceName, &v2), + resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), + //resource.TestCheckResourceAttr(resourceName, "dhcp_options.0.option_value", "false"), + //resource.TestCheckResourceAttrPair(resourceName, "dhcp_options.0.option_code", "bloxone_dhcp_option_code.test", "id"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + func TestAccSubnetResource_DdnsSendUpdates(t *testing.T) { var resourceName = "bloxone_ipam_subnet.test_ddns_send_updates" var v ipam.IpamsvcSubnet @@ -1059,6 +1093,45 @@ resource "bloxone_ipam_subnet" "test_ddns_conflict_resolution_mode" { return strings.Join([]string{testAccBaseWithIPSpace(), config}, "") } +func testAccSubnetDhcpOptionsOption(address string, cidr int, name, type_, optValue string) string { + config := fmt.Sprintf(` +resource "bloxone_ipam_subnet" "test_dhcp_options" { + address = %q + cidr = %d + space = bloxone_ipam_ip_space.test.id + name = %q + dhcp_options = [ + { + type = %q + option_code = bloxone_dhcp_option_code.test.id + option_value = %q + } + ] +} +`, address, cidr, name, type_, optValue) + + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") +} + +func testAccSubnetDhcpOptionsGroup(address string, cidr int, name, type_ string) string { + config := fmt.Sprintf(` +resource "bloxone_ipam_subnet" "test_dhcp_options" { + address = %q + cidr = %d + space = bloxone_ipam_ip_space.test.id + name = %q + dhcp_options = [ + { + type = %q + group = bloxone_dhcp_option_group.test.id + } + ] +} +`, address, cidr, name, type_) + + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") +} + func testAccSubnetDdnsDomain(address string, cidr int, ddnsDomain string) string { config := fmt.Sprintf(` resource "bloxone_ipam_subnet" "test_ddns_domain" { diff --git a/internal/service/ipam/model_ipamsvc_subnet.go b/internal/service/ipam/model_ipamsvc_subnet.go index c9e84a37..8b7345b6 100644 --- a/internal/service/ipam/model_ipamsvc_subnet.go +++ b/internal/service/ipam/model_ipamsvc_subnet.go @@ -2,6 +2,7 @@ package ipam import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" @@ -257,6 +258,9 @@ var IpamsvcSubnetResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The DHCP options of the subnet. This can either be a specific option or a group of options.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "dhcp_utilization": schema.SingleNestedAttribute{ Attributes: IpamsvcDHCPUtilizationResourceSchemaAttributes, From f8e5bd80ef9db57eefb1d0719d68a1cdc9cc5d4a Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Mon, 5 Feb 2024 12:39:11 +0530 Subject: [PATCH 02/11] DHCP option support for range --- .../service/ipam/api_range_resource_test.go | 72 +++++++++++++++++++ .../service/ipam/api_subnet_resource_test.go | 2 - internal/service/ipam/model_ipamsvc_range.go | 4 ++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/internal/service/ipam/api_range_resource_test.go b/internal/service/ipam/api_range_resource_test.go index f9f7fabd..7da18c55 100644 --- a/internal/service/ipam/api_range_resource_test.go +++ b/internal/service/ipam/api_range_resource_test.go @@ -132,6 +132,37 @@ func TestAccRangeResource_DisableDhcp(t *testing.T) { }) } +func TestAccRangeResource_DhcpOptions(t *testing.T) { + var resourceName = "bloxone_ipam_range.test_dhcp_options" + var v ipam.IpamsvcRange + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read + { + Config: testAccRangeDhcpOptionsOption("10.0.0.10", "10.0.0.20", "option", "true"), + Check: resource.ComposeTestCheckFunc( + testAccCheckRangeExists(context.Background(), resourceName, &v), + 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: testAccRangeDhcpOptionsGroup("10.0.0.10", "10.0.0.20", "group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckRangeExists(context.Background(), resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + func TestAccRangeResource_End(t *testing.T) { var resourceName = "bloxone_ipam_range.test_end" var v ipam.IpamsvcRange @@ -435,6 +466,47 @@ resource "bloxone_ipam_range" "test_disable_dhcp" { return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), config}, "") } +func testAccRangeDhcpOptionsOption(start string, end string, type_, optValue string) string { + config := fmt.Sprintf(` +resource "bloxone_ipam_range" "test_dhcp_options" { + space = bloxone_ipam_ip_space.test.id + start = %q + end = %q + dhcp_options = [ + { + type = %q + option_code = bloxone_dhcp_option_code.test.id + option_value = %q + } + ] + depends_on = [bloxone_ipam_subnet.test] +} +`, start, end, type_, optValue) + + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + +} + +func testAccRangeDhcpOptionsGroup(start string, end string, type_ string) string { + config := fmt.Sprintf(` +resource "bloxone_ipam_range" "test_dhcp_options" { + space = bloxone_ipam_ip_space.test.id + start = %q + end = %q + dhcp_options = [ + { + type = %q + group = bloxone_dhcp_option_group.test.id + } + ] + depends_on = [bloxone_ipam_subnet.test] +} +`, start, end, type_) + + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + +} + func testAccRangeEnd(start, end string) string { config := fmt.Sprintf(` resource "bloxone_ipam_range" "test_end" { diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index b90d1755..be65c33d 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -428,8 +428,6 @@ func TestAccSubnetResource_DhcpOptions(t *testing.T) { testAccCheckSubnetDestroy(context.Background(), &v1), testAccCheckSubnetExists(context.Background(), resourceName, &v2), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), - //resource.TestCheckResourceAttr(resourceName, "dhcp_options.0.option_value", "false"), - //resource.TestCheckResourceAttrPair(resourceName, "dhcp_options.0.option_code", "bloxone_dhcp_option_code.test", "id"), ), }, // Delete testing automatically occurs in TestCase diff --git a/internal/service/ipam/model_ipamsvc_range.go b/internal/service/ipam/model_ipamsvc_range.go index dac96e85..df79aeff 100644 --- a/internal/service/ipam/model_ipamsvc_range.go +++ b/internal/service/ipam/model_ipamsvc_range.go @@ -2,6 +2,7 @@ package ipam import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -95,6 +96,9 @@ var IpamsvcRangeResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options. May be either a specific option or a group of options.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "disable_dhcp": schema.BoolAttribute{ Optional: true, From e36fd325c6ab754fb9a0e02b87795157ad04a3f6 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Mon, 5 Feb 2024 22:03:30 +0530 Subject: [PATCH 03/11] DHCP option support for ipspace --- .../ipam/api_ip_space_resource_test.go | 125 ++++++++++++++++++ .../service/ipam/api_range_resource_test.go | 7 +- .../service/ipam/api_server_resource_test.go | 3 - .../service/ipam/model_ipamsvc_ip_space.go | 4 + 4 files changed, 133 insertions(+), 6 deletions(-) diff --git a/internal/service/ipam/api_ip_space_resource_test.go b/internal/service/ipam/api_ip_space_resource_test.go index 87f48580..db9c8ac4 100644 --- a/internal/service/ipam/api_ip_space_resource_test.go +++ b/internal/service/ipam/api_ip_space_resource_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strings" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -312,6 +313,67 @@ 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: testAccIpSpaceDhcpOptionsGroups("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 v ipam.IpamsvcIPSpace +// +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { acctest.PreCheck(t) }, +// ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, +// Steps: []resource.TestStep{ +// // Create and Read +// { +// Config: testAccIpSpaceDhcpOptionsV6("NAME_REPLACE_ME", "DHCP_OPTIONS_V6_REPLACE_ME"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIpSpaceExists(context.Background(), resourceName, &v), +// resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6", "DHCP_OPTIONS_V6_REPLACE_ME"), +// ), +// }, +// // Update and Read +// { +// Config: testAccIpSpaceDhcpOptionsV6("NAME_REPLACE_ME", "DHCP_OPTIONS_V6_UPDATE_REPLACE_ME"), +// Check: resource.ComposeTestCheckFunc( +// testAccCheckIpSpaceExists(context.Background(), resourceName, &v), +// resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6", "DHCP_OPTIONS_V6_UPDATE_REPLACE_ME"), +// ), +// }, +// // 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 @@ -909,6 +971,69 @@ 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 testAccIpSpaceDhcpOptionsGroups(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, dhcpOptionsV6 string) string { +// config := fmt.Sprintf(` +//resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { +// name = %q +// dhcp_options = [ +// { +// type = %q +// option_code = bloxone_dhcp_option_code.test.id +// option_value = %q +// } +// ] +//} +//`, name, dhcpOptionsV6) +// return strings.Join([]string{testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") +//} +// +//func testAccIpSpaceDhcpOptionsGroupsV6(name string, dhcpOptionsV6 string) string { +// return fmt.Sprintf(` +//resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { +// name = %q +// dhcp_options = [ +// { +// type = %q +// group = bloxone_dhcp_option_group.test.id +// } +// ] +//} +//`, name, dhcpOptionsV6) +//} + func testAccIpSpaceHeaderOptionFilename(name, headerOptionFilename string) string { return fmt.Sprintf(` resource "bloxone_ipam_ip_space" "test_header_option_filename" { diff --git a/internal/service/ipam/api_range_resource_test.go b/internal/service/ipam/api_range_resource_test.go index 7da18c55..e6338fef 100644 --- a/internal/service/ipam/api_range_resource_test.go +++ b/internal/service/ipam/api_range_resource_test.go @@ -134,7 +134,7 @@ func TestAccRangeResource_DisableDhcp(t *testing.T) { func TestAccRangeResource_DhcpOptions(t *testing.T) { var resourceName = "bloxone_ipam_range.test_dhcp_options" - var v ipam.IpamsvcRange + var v1, v2 ipam.IpamsvcRange resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -144,7 +144,7 @@ func TestAccRangeResource_DhcpOptions(t *testing.T) { { Config: testAccRangeDhcpOptionsOption("10.0.0.10", "10.0.0.20", "option", "true"), Check: resource.ComposeTestCheckFunc( - testAccCheckRangeExists(context.Background(), resourceName, &v), + testAccCheckRangeExists(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"), @@ -154,7 +154,8 @@ func TestAccRangeResource_DhcpOptions(t *testing.T) { { Config: testAccRangeDhcpOptionsGroup("10.0.0.10", "10.0.0.20", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckRangeExists(context.Background(), resourceName, &v), + testAccCheckRangeDestroy(context.Background(), &v1), + testAccCheckRangeExists(context.Background(), resourceName, &v2), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, diff --git a/internal/service/ipam/api_server_resource_test.go b/internal/service/ipam/api_server_resource_test.go index 36f55bff..8579651c 100644 --- a/internal/service/ipam/api_server_resource_test.go +++ b/internal/service/ipam/api_server_resource_test.go @@ -148,7 +148,6 @@ func TestAccServerResource_DdnsClientUpdate(t *testing.T) { }) } -// issue func TestAccServerResource_DdnsConflictResolutionMode(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_ddns_conflict_resolution_mode" var v ipam.IpamsvcServer @@ -391,7 +390,6 @@ func TestAccServerResource_DdnsUpdateOnRenew(t *testing.T) { }) } -// issue func TestAccServerResource_DdnsUseConflictResolution(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_ddns_use_conflict_resolution" var v ipam.IpamsvcServer @@ -424,7 +422,6 @@ func TestAccServerResource_DdnsUseConflictResolution(t *testing.T) { }) } -// list func TestAccServerResource_DdnsZones(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_ddns_zones" var v ipam.IpamsvcServer diff --git a/internal/service/ipam/model_ipamsvc_ip_space.go b/internal/service/ipam/model_ipamsvc_ip_space.go index 9e57f9fc..8d1d40ad 100644 --- a/internal/service/ipam/model_ipamsvc_ip_space.go +++ b/internal/service/ipam/model_ipamsvc_ip_space.go @@ -2,6 +2,7 @@ package ipam import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -213,6 +214,9 @@ var IpamsvcIPSpaceResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: `The list of IPv4 DHCP options for IP space. May be either a specific option or a group of options.`, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "dhcp_options_v6": schema.ListNestedAttribute{ NestedObject: schema.NestedAttributeObject{ From 6b27d94256190a7258e8760263ed33c934090c2a Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Tue, 6 Feb 2024 10:26:16 +0530 Subject: [PATCH 04/11] DHCP option support for AB & FA --- .../ipam/api_address_block_resource_test.go | 67 +++++++++++++++++ .../ipam/api_fixed_address_resource_test.go | 73 +++++++++++++++++++ .../ipam/model_ipamsvc_address_block.go | 4 + .../ipam/model_ipamsvc_fixed_address.go | 4 + 4 files changed, 148 insertions(+) diff --git a/internal/service/ipam/api_address_block_resource_test.go b/internal/service/ipam/api_address_block_resource_test.go index edb93b4e..86e4103e 100644 --- a/internal/service/ipam/api_address_block_resource_test.go +++ b/internal/service/ipam/api_address_block_resource_test.go @@ -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: testAccAddressBlockDhcpOptionOptions("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: testAccAddressBlockDhcpOptionsGroups("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 @@ -949,6 +981,41 @@ resource "bloxone_ipam_address_block" "test_ddns_domain" { return strings.Join([]string{testAccBaseWithIPSpace(), config}, "") } +func testAccAddressBlockDhcpOptionOptions(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 testAccAddressBlockDhcpOptionsGroups(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" { diff --git a/internal/service/ipam/api_fixed_address_resource_test.go b/internal/service/ipam/api_fixed_address_resource_test.go index 3ef3e940..d078520f 100644 --- a/internal/service/ipam/api_fixed_address_resource_test.go +++ b/internal/service/ipam/api_fixed_address_resource_test.go @@ -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: testAccFixedAddressDhcpOptionsOptions("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: testAccFixedAddressDhcpOptionsGroups("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 @@ -631,6 +663,47 @@ resource "bloxone_dhcp_fixed_address" "test_disable_dhcp" { return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), config}, "") } +func testAccFixedAddressDhcpOptionsOptions(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 testAccFixedAddressDhcpOptionsGroups(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" { diff --git a/internal/service/ipam/model_ipamsvc_address_block.go b/internal/service/ipam/model_ipamsvc_address_block.go index 0b44d838..493d762e 100644 --- a/internal/service/ipam/model_ipamsvc_address_block.go +++ b/internal/service/ipam/model_ipamsvc_address_block.go @@ -2,6 +2,7 @@ package ipam import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -228,6 +229,9 @@ var IpamsvcAddressBlockResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options for the address block. May be either a specific option or a group of options.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "dhcp_utilization": schema.SingleNestedAttribute{ Attributes: IpamsvcDHCPUtilizationResourceSchemaAttributes, diff --git a/internal/service/ipam/model_ipamsvc_fixed_address.go b/internal/service/ipam/model_ipamsvc_fixed_address.go index 4bf895f8..ab81263a 100644 --- a/internal/service/ipam/model_ipamsvc_fixed_address.go +++ b/internal/service/ipam/model_ipamsvc_fixed_address.go @@ -2,6 +2,7 @@ package ipam import ( "context" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" @@ -97,6 +98,9 @@ var IpamsvcFixedAddressResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options. May be either a specific option or a group of options.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "disable_dhcp": schema.BoolAttribute{ Optional: true, From fd3caab3cb9ef39a28a6c4c8c27b5c87056d1638 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Wed, 7 Feb 2024 12:11:17 +0530 Subject: [PATCH 05/11] DHCP option support extension fix --- docs/resources/dhcp_fixed_address.md | 8 ++ docs/resources/ipam_subnet.md | 9 ++ .../bloxone_dhcp_fixed_address/resource.tf | 8 ++ .../resources/bloxone_ipam_subnet/resource.tf | 9 ++ .../ipam/api_address_block_resource_test.go | 8 +- .../ipam/api_fixed_address_resource_test.go | 8 +- .../ipam/api_ip_space_resource_test.go | 122 +++++++++-------- .../ipam/api_option_code_resource_test.go | 13 ++ .../service/ipam/api_server_resource_test.go | 127 ++++++++++++++++++ .../service/ipam/model_ipamsvc_ip_space.go | 3 + internal/service/ipam/model_ipamsvc_server.go | 6 + 11 files changed, 254 insertions(+), 67 deletions(-) diff --git a/docs/resources/dhcp_fixed_address.md b/docs/resources/dhcp_fixed_address.md index 3cd331ce..498c501d 100644 --- a/docs/resources/dhcp_fixed_address.md +++ b/docs/resources/dhcp_fixed_address.md @@ -66,6 +66,14 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location : "site1" } + dhcp_options = [ + { + description = "Option 1" + option_code = "234" + option_value = "true" + type = "boolean" + } + ] depends_on = [bloxone_ipam_subnet.example] } ``` diff --git a/docs/resources/ipam_subnet.md b/docs/resources/ipam_subnet.md index 251b2218..ee1e0892 100644 --- a/docs/resources/ipam_subnet.md +++ b/docs/resources/ipam_subnet.md @@ -49,6 +49,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" + } + ] } ``` diff --git a/examples/resources/bloxone_dhcp_fixed_address/resource.tf b/examples/resources/bloxone_dhcp_fixed_address/resource.tf index e629e7ab..f9a904df 100644 --- a/examples/resources/bloxone_dhcp_fixed_address/resource.tf +++ b/examples/resources/bloxone_dhcp_fixed_address/resource.tf @@ -51,5 +51,13 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location : "site1" } + dhcp_options = [ + { + description = "Option 1" + option_code = "234" + option_value = "true" + type = "boolean" + } + ] depends_on = [bloxone_ipam_subnet.example] } diff --git a/examples/resources/bloxone_ipam_subnet/resource.tf b/examples/resources/bloxone_ipam_subnet/resource.tf index ced2c5fa..60f08540 100644 --- a/examples/resources/bloxone_ipam_subnet/resource.tf +++ b/examples/resources/bloxone_ipam_subnet/resource.tf @@ -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" + } + ] } diff --git a/internal/service/ipam/api_address_block_resource_test.go b/internal/service/ipam/api_address_block_resource_test.go index 86e4103e..10570d4a 100644 --- a/internal/service/ipam/api_address_block_resource_test.go +++ b/internal/service/ipam/api_address_block_resource_test.go @@ -495,7 +495,7 @@ func TestAccAddressBlockResource_DhcpOptions(t *testing.T) { Steps: []resource.TestStep{ // Create and Read { - Config: testAccAddressBlockDhcpOptionOptions("192.168.0.0", "16", "option", "true"), + Config: testAccAddressBlockDhcpOptionOption("192.168.0.0", "16", "option", "true"), Check: resource.ComposeTestCheckFunc( testAccCheckAddressBlockExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), @@ -505,7 +505,7 @@ func TestAccAddressBlockResource_DhcpOptions(t *testing.T) { }, // Update and Read { - Config: testAccAddressBlockDhcpOptionsGroups("192.168.0.0", "16", "group"), + Config: testAccAddressBlockDhcpOptionsGroup("192.168.0.0", "16", "group"), Check: resource.ComposeTestCheckFunc( testAccCheckAddressBlockDestroy(context.Background(), &v1), testAccCheckAddressBlockExists(context.Background(), resourceName, &v2), @@ -981,7 +981,7 @@ resource "bloxone_ipam_address_block" "test_ddns_domain" { return strings.Join([]string{testAccBaseWithIPSpace(), config}, "") } -func testAccAddressBlockDhcpOptionOptions(name string, cidr string, type_, optValue string) string { +func testAccAddressBlockDhcpOptionOption(name string, cidr string, type_, optValue string) string { config := fmt.Sprintf(` resource "bloxone_ipam_address_block" "test_dhcp_options" { address = %q @@ -999,7 +999,7 @@ resource "bloxone_ipam_address_block" "test_dhcp_options" { return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") } -func testAccAddressBlockDhcpOptionsGroups(name string, cidr string, type_ string) string { +func testAccAddressBlockDhcpOptionsGroup(name string, cidr string, type_ string) string { config := fmt.Sprintf(` resource "bloxone_ipam_address_block" "test_dhcp_options" { address = %q diff --git a/internal/service/ipam/api_fixed_address_resource_test.go b/internal/service/ipam/api_fixed_address_resource_test.go index d078520f..bcdd07ec 100644 --- a/internal/service/ipam/api_fixed_address_resource_test.go +++ b/internal/service/ipam/api_fixed_address_resource_test.go @@ -175,7 +175,7 @@ func TestAccFixedAddressResource_DhcpOptions(t *testing.T) { Steps: []resource.TestStep{ // Create and Read { - Config: testAccFixedAddressDhcpOptionsOptions("10.0.0.10", "mac", "aa:aa:aa:aa:aa:aa", "Fixed_address_dhcp_option", "option", "true"), + 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"), @@ -185,7 +185,7 @@ func TestAccFixedAddressResource_DhcpOptions(t *testing.T) { }, // Update and Read { - Config: testAccFixedAddressDhcpOptionsGroups("10.0.0.10", "mac", "aa:aa:aa:aa:aa:aa", "Fixed_address_dhcp_option", "group"), + 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), @@ -663,7 +663,7 @@ resource "bloxone_dhcp_fixed_address" "test_disable_dhcp" { return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), config}, "") } -func testAccFixedAddressDhcpOptionsOptions(address string, matchType string, matchValue string, name, type_, optValue string) string { +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 @@ -684,7 +684,7 @@ resource "bloxone_dhcp_fixed_address" "test_dhcp_options" { return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") } -func testAccFixedAddressDhcpOptionsGroups(address string, matchType string, matchValue string, name, type_ string) string { +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 diff --git a/internal/service/ipam/api_ip_space_resource_test.go b/internal/service/ipam/api_ip_space_resource_test.go index db9c8ac4..05708fab 100644 --- a/internal/service/ipam/api_ip_space_resource_test.go +++ b/internal/service/ipam/api_ip_space_resource_test.go @@ -333,7 +333,7 @@ func TestAccIpSpaceResource_DhcpOptions(t *testing.T) { }, // Update and Read { - Config: testAccIpSpaceDhcpOptionsGroups("ipspace_dhcp_options_test", "group"), + Config: testAccIpSpaceDhcpOptionsGroup("ipspace_dhcp_options_test", "group"), Check: resource.ComposeTestCheckFunc( testAccCheckIpSpaceDestroy(context.Background(), &v1), testAccCheckIpSpaceExists(context.Background(), resourceName, &v2), @@ -345,34 +345,37 @@ func TestAccIpSpaceResource_DhcpOptions(t *testing.T) { }) } -//func TestAccIpSpaceResource_DhcpOptionsV6(t *testing.T) { -// var resourceName = "bloxone_ipam_ip_space.test_dhcp_options_v6" -// var v ipam.IpamsvcIPSpace -// -// resource.Test(t, resource.TestCase{ -// PreCheck: func() { acctest.PreCheck(t) }, -// ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, -// Steps: []resource.TestStep{ -// // Create and Read -// { -// Config: testAccIpSpaceDhcpOptionsV6("NAME_REPLACE_ME", "DHCP_OPTIONS_V6_REPLACE_ME"), -// Check: resource.ComposeTestCheckFunc( -// testAccCheckIpSpaceExists(context.Background(), resourceName, &v), -// resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6", "DHCP_OPTIONS_V6_REPLACE_ME"), -// ), -// }, -// // Update and Read -// { -// Config: testAccIpSpaceDhcpOptionsV6("NAME_REPLACE_ME", "DHCP_OPTIONS_V6_UPDATE_REPLACE_ME"), -// Check: resource.ComposeTestCheckFunc( -// testAccCheckIpSpaceExists(context.Background(), resourceName, &v), -// resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6", "DHCP_OPTIONS_V6_UPDATE_REPLACE_ME"), -// ), -// }, -// // 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" @@ -988,7 +991,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { } -func testAccIpSpaceDhcpOptionsGroups(name string, type_ string) string { +func testAccIpSpaceDhcpOptionsGroup(name string, type_ string) string { config := fmt.Sprintf(` resource "bloxone_ipam_ip_space" "test_dhcp_options" { name = %q @@ -1004,35 +1007,36 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { } -//func testAccIpSpaceDhcpOptionsOptionV6(name string, dhcpOptionsV6 string) string { -// config := fmt.Sprintf(` -//resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { -// name = %q -// dhcp_options = [ -// { -// type = %q -// option_code = bloxone_dhcp_option_code.test.id -// option_value = %q -// } -// ] -//} -//`, name, dhcpOptionsV6) -// return strings.Join([]string{testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") -//} -// -//func testAccIpSpaceDhcpOptionsGroupsV6(name string, dhcpOptionsV6 string) string { -// return fmt.Sprintf(` -//resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { -// name = %q -// dhcp_options = [ -// { -// type = %q -// group = bloxone_dhcp_option_group.test.id -// } -// ] -//} -//`, name, dhcpOptionsV6) -//} +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(` diff --git a/internal/service/ipam/api_option_code_resource_test.go b/internal/service/ipam/api_option_code_resource_test.go index b672583e..8cd81f54 100644 --- a/internal/service/ipam/api_option_code_resource_test.go +++ b/internal/service/ipam/api_option_code_resource_test.go @@ -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" { diff --git a/internal/service/ipam/api_server_resource_test.go b/internal/service/ipam/api_server_resource_test.go index 8579651c..2b28df7b 100644 --- a/internal/service/ipam/api_server_resource_test.go +++ b/internal/service/ipam/api_server_resource_test.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "strings" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -210,6 +211,70 @@ func TestAccServerResource_DdnsDomain(t *testing.T) { }) } +func TestAccServerResource_DhcpOptions(t *testing.T) { + var resourceName = "bloxone_dhcp_server.test_dhcp_options" + var v1, v2 ipam.IpamsvcServer + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read + { + Config: testAccServerDhcpOptionsOption("server_dhcp_options", "option", "true"), + Check: resource.ComposeTestCheckFunc( + testAccCheckServerExists(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: testAccServerDhcpOptionsGroup("server_dhcp_options", "group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckServerDestroy(context.Background(), &v1), + testAccCheckServerExists(context.Background(), resourceName, &v2), + resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + +func TestAccServerResource_DhcpOptionsV6(t *testing.T) { + var resourceName = "bloxone_dhcp_server.test_dhcp_options" + var v1, v2 ipam.IpamsvcServer + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read + { + Config: testAccServerDhcpOptionsOptionV6("server_dhcp_options", "option", "true"), + Check: resource.ComposeTestCheckFunc( + testAccCheckServerExists(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: testAccServerDhcpOptionsGroupV6("server_dhcp_options", "group"), + Check: resource.ComposeTestCheckFunc( + testAccCheckServerDestroy(context.Background(), &v1), + testAccCheckServerExists(context.Background(), resourceName, &v2), + resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.#", "1"), + ), + }, + // Delete testing automatically occurs in TestCase + }, + }) +} + func TestAccServerResource_DdnsEnabled(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_ddns_enabled" var v ipam.IpamsvcServer @@ -966,6 +1031,68 @@ resource "bloxone_dhcp_server" "test_ddns_domain" { `, name, ddnsDomain) } +func testAccServerDhcpOptionsOption(name string, type_, optValue string) string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_server" "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 testAccServerDhcpOptionsGroup(name string, type_ string) string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_server" "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 testAccServerDhcpOptionsOptionV6(name string, type_, optValue string) string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_server" "test_dhcp_options" { + 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 testAccServerDhcpOptionsGroupV6(name string, type_ string) string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_server" "test_dhcp_options" { + 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 testAccServerDdnsEnabled(name string, ddnsEnabled string) string { return fmt.Sprintf(` resource "bloxone_dhcp_server" "test_ddns_enabled" { diff --git a/internal/service/ipam/model_ipamsvc_ip_space.go b/internal/service/ipam/model_ipamsvc_ip_space.go index 8d1d40ad..ba20e560 100644 --- a/internal/service/ipam/model_ipamsvc_ip_space.go +++ b/internal/service/ipam/model_ipamsvc_ip_space.go @@ -224,6 +224,9 @@ var IpamsvcIPSpaceResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: `The list of IPv6 DHCP options for IP space. May be either a specific option or a group of options.`, + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "header_option_filename": schema.StringAttribute{ Optional: true, diff --git a/internal/service/ipam/model_ipamsvc_server.go b/internal/service/ipam/model_ipamsvc_server.go index 9950432c..b4bb9b4d 100644 --- a/internal/service/ipam/model_ipamsvc_server.go +++ b/internal/service/ipam/model_ipamsvc_server.go @@ -224,6 +224,9 @@ var IpamsvcServerResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options or group of options for IPv4. An option list is ordered and may include both option groups and specific options. Multiple occurrences of the same option or group is not an error. The last occurrence of an option in the list will be used. Error if the graph of referenced groups contains cycles. Defaults to empty list.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "dhcp_options_v6": schema.ListNestedAttribute{ NestedObject: schema.NestedAttributeObject{ @@ -231,6 +234,9 @@ var IpamsvcServerResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options or group of options for IPv6. An option list is ordered and may include both option groups and specific options. Multiple occurrences of the same option or group is not an error. The last occurrence of an option in the list will be used. Error if the graph of referenced groups contains cycles. Defaults to empty list.", + PlanModifiers: []planmodifier.List{ + listplanmodifier.RequiresReplaceIfConfigured(), + }, }, "gss_tsig_fallback": schema.BoolAttribute{ Optional: true, From 2cc5fb995de304394ff2a11d2d5a59ebe1c8af78 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Wed, 7 Feb 2024 15:05:40 +0530 Subject: [PATCH 06/11] fix imports --- internal/service/ipam/model_ipamsvc_address_block.go | 2 +- internal/service/ipam/model_ipamsvc_fixed_address.go | 3 ++- internal/service/ipam/model_ipamsvc_ip_space.go | 2 +- internal/service/ipam/model_ipamsvc_range.go | 2 +- internal/service/ipam/model_ipamsvc_subnet.go | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/service/ipam/model_ipamsvc_address_block.go b/internal/service/ipam/model_ipamsvc_address_block.go index 493d762e..04b54cd2 100644 --- a/internal/service/ipam/model_ipamsvc_address_block.go +++ b/internal/service/ipam/model_ipamsvc_address_block.go @@ -2,13 +2,13 @@ package ipam import ( "context" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" diff --git a/internal/service/ipam/model_ipamsvc_fixed_address.go b/internal/service/ipam/model_ipamsvc_fixed_address.go index ab81263a..f8ee9746 100644 --- a/internal/service/ipam/model_ipamsvc_fixed_address.go +++ b/internal/service/ipam/model_ipamsvc_fixed_address.go @@ -2,7 +2,7 @@ package ipam import ( "context" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" + "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" diff --git a/internal/service/ipam/model_ipamsvc_ip_space.go b/internal/service/ipam/model_ipamsvc_ip_space.go index ba20e560..ddf3aa8c 100644 --- a/internal/service/ipam/model_ipamsvc_ip_space.go +++ b/internal/service/ipam/model_ipamsvc_ip_space.go @@ -2,7 +2,6 @@ package ipam import ( "context" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -10,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" diff --git a/internal/service/ipam/model_ipamsvc_range.go b/internal/service/ipam/model_ipamsvc_range.go index df79aeff..25f6291e 100644 --- a/internal/service/ipam/model_ipamsvc_range.go +++ b/internal/service/ipam/model_ipamsvc_range.go @@ -2,7 +2,6 @@ package ipam import ( "context" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -10,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" diff --git a/internal/service/ipam/model_ipamsvc_subnet.go b/internal/service/ipam/model_ipamsvc_subnet.go index 8b7345b6..28f5ba8e 100644 --- a/internal/service/ipam/model_ipamsvc_subnet.go +++ b/internal/service/ipam/model_ipamsvc_subnet.go @@ -2,7 +2,7 @@ package ipam import ( "context" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" + "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" From 7216e489133bcd3b5eaea63a5f861440bc69445a Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Sat, 10 Feb 2024 16:51:50 +0530 Subject: [PATCH 07/11] added optioncode function, removed plan modifier --- docs/resources/dhcp_fixed_address.md | 13 ++++-- docs/resources/ipam_subnet.md | 12 ++++-- .../bloxone_dhcp_fixed_address/resource.tf | 13 ++++-- .../resources/bloxone_ipam_subnet/resource.tf | 12 ++++-- .../ipam/api_address_block_resource_test.go | 9 ++-- .../ipam/api_fixed_address_resource_test.go | 9 ++-- .../ipam/api_ip_space_resource_test.go | 18 ++++---- .../ipam/api_option_code_resource_test.go | 13 ------ .../service/ipam/api_range_resource_test.go | 14 +++--- .../service/ipam/api_server_resource_test.go | 18 ++++---- .../service/ipam/api_subnet_resource_test.go | 43 ++++++++++++++++--- .../ipam/model_ipamsvc_fixed_address.go | 4 -- .../service/ipam/model_ipamsvc_ip_space.go | 7 --- internal/service/ipam/model_ipamsvc_range.go | 4 -- internal/service/ipam/model_ipamsvc_server.go | 6 --- internal/service/ipam/model_ipamsvc_subnet.go | 4 -- 16 files changed, 106 insertions(+), 93 deletions(-) diff --git a/docs/resources/dhcp_fixed_address.md b/docs/resources/dhcp_fixed_address.md index 498c501d..8709037c 100644 --- a/docs/resources/dhcp_fixed_address.md +++ b/docs/resources/dhcp_fixed_address.md @@ -55,6 +55,13 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { depends_on = [bloxone_ipam_subnet.example] } +resource "bloxone_dhcp_option_code" "option_code" { + code = 250 + name = "example_option_code" + option_space = bloxone_dhcp_option_space.option_space.id + type = "int32" +} + // Address using Next available IP resource "bloxone_dhcp_fixed_address" "example_fixed_address" { name = "example_fixed_address" @@ -66,12 +73,12 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location : "site1" } + //dhcp options dhcp_options = [ { - description = "Option 1" - option_code = "234" + option_code = bloxone_dhcp_option_code.option_code.id option_value = "true" - type = "boolean" + type = "option" } ] depends_on = [bloxone_ipam_subnet.example] diff --git a/docs/resources/ipam_subnet.md b/docs/resources/ipam_subnet.md index ee1e0892..0cb46721 100644 --- a/docs/resources/ipam_subnet.md +++ b/docs/resources/ipam_subnet.md @@ -37,6 +37,13 @@ resource "bloxone_ipam_subnet" "example" { } } +resource "bloxone_dhcp_option_code" "option_code" { + code = 250 + name = "example_option_code" + option_space = bloxone_dhcp_option_space.option_space.id + type = "int32" +} + # Next available subnet resource "bloxone_ipam_subnet" "example_na_s" { next_available_id = bloxone_ipam_address_block.example.id @@ -52,10 +59,9 @@ resource "bloxone_ipam_subnet" "example_na_s" { #dhcp options dhcp_options = [ { - description = "Option 1" - option_code = "234" + option_code = bloxone_dhcp_option_code.option_code.id option_value = "true" - type = "boolean" + type = "option" } ] } diff --git a/examples/resources/bloxone_dhcp_fixed_address/resource.tf b/examples/resources/bloxone_dhcp_fixed_address/resource.tf index f9a904df..5aac582d 100644 --- a/examples/resources/bloxone_dhcp_fixed_address/resource.tf +++ b/examples/resources/bloxone_dhcp_fixed_address/resource.tf @@ -40,6 +40,13 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { depends_on = [bloxone_ipam_subnet.example] } +resource "bloxone_dhcp_option_code" "option_code" { + code = 250 + name = "example_option_code" + option_space = bloxone_dhcp_option_space.option_space.id + type = "int32" +} + // Address using Next available IP resource "bloxone_dhcp_fixed_address" "example_fixed_address" { name = "example_fixed_address" @@ -51,12 +58,12 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location : "site1" } + //dhcp options dhcp_options = [ { - description = "Option 1" - option_code = "234" + option_code = bloxone_dhcp_option_code.option_code.id option_value = "true" - type = "boolean" + type = "option" } ] depends_on = [bloxone_ipam_subnet.example] diff --git a/examples/resources/bloxone_ipam_subnet/resource.tf b/examples/resources/bloxone_ipam_subnet/resource.tf index 60f08540..c569f58a 100644 --- a/examples/resources/bloxone_ipam_subnet/resource.tf +++ b/examples/resources/bloxone_ipam_subnet/resource.tf @@ -22,6 +22,13 @@ resource "bloxone_ipam_subnet" "example" { } } +resource "bloxone_dhcp_option_code" "option_code" { + code = 250 + name = "example_option_code" + option_space = bloxone_dhcp_option_space.option_space.id + type = "int32" +} + # Next available subnet resource "bloxone_ipam_subnet" "example_na_s" { next_available_id = bloxone_ipam_address_block.example.id @@ -37,10 +44,9 @@ resource "bloxone_ipam_subnet" "example_na_s" { #dhcp options dhcp_options = [ { - description = "Option 1" - option_code = "234" + option_code = bloxone_dhcp_option_code.option_code.id option_value = "true" - type = "boolean" + type = "option" } ] } diff --git a/internal/service/ipam/api_address_block_resource_test.go b/internal/service/ipam/api_address_block_resource_test.go index 10570d4a..b219bb7b 100644 --- a/internal/service/ipam/api_address_block_resource_test.go +++ b/internal/service/ipam/api_address_block_resource_test.go @@ -487,7 +487,7 @@ 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 + var v1 ipam.IpamsvcAddressBlock resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -507,8 +507,7 @@ func TestAccAddressBlockResource_DhcpOptions(t *testing.T) { { Config: testAccAddressBlockDhcpOptionsGroup("192.168.0.0", "16", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckAddressBlockDestroy(context.Background(), &v1), - testAccCheckAddressBlockExists(context.Background(), resourceName, &v2), + testAccCheckAddressBlockExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -996,7 +995,7 @@ resource "bloxone_ipam_address_block" "test_dhcp_options" { ] } `, name, cidr, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") } func testAccAddressBlockDhcpOptionsGroup(name string, cidr string, type_ string) string { @@ -1013,7 +1012,7 @@ resource "bloxone_ipam_address_block" "test_dhcp_options" { ] } `, name, cidr, type_) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") } func testAccAddressBlockDdnsGenerateName(address string, cidr string, ddnsGenerateName string) string { diff --git a/internal/service/ipam/api_fixed_address_resource_test.go b/internal/service/ipam/api_fixed_address_resource_test.go index bcdd07ec..9f2f5bb3 100644 --- a/internal/service/ipam/api_fixed_address_resource_test.go +++ b/internal/service/ipam/api_fixed_address_resource_test.go @@ -167,7 +167,7 @@ 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 + var v1 ipam.IpamsvcFixedAddress resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -187,8 +187,7 @@ func TestAccFixedAddressResource_DhcpOptions(t *testing.T) { { 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), + testAccCheckFixedAddressExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -681,7 +680,7 @@ resource "bloxone_dhcp_fixed_address" "test_dhcp_options" { ] } `, address, matchType, matchValue, name, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") } func testAccFixedAddressDhcpOptionsGroup(address string, matchType string, matchValue string, name, type_ string) string { @@ -701,7 +700,7 @@ resource "bloxone_dhcp_fixed_address" "test_dhcp_options" { ] } `, address, matchType, matchValue, name, type_) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") } func testAccFixedAddressHeaderOptionFilename(address string, matchType string, matchValue string, headerOptionFilename string) string { diff --git a/internal/service/ipam/api_ip_space_resource_test.go b/internal/service/ipam/api_ip_space_resource_test.go index 05708fab..cc58b202 100644 --- a/internal/service/ipam/api_ip_space_resource_test.go +++ b/internal/service/ipam/api_ip_space_resource_test.go @@ -315,7 +315,7 @@ 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 + var v1 ipam.IpamsvcIPSpace resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -335,8 +335,7 @@ func TestAccIpSpaceResource_DhcpOptions(t *testing.T) { { Config: testAccIpSpaceDhcpOptionsGroup("ipspace_dhcp_options_test", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckIpSpaceDestroy(context.Background(), &v1), - testAccCheckIpSpaceExists(context.Background(), resourceName, &v2), + testAccCheckIpSpaceExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -347,7 +346,7 @@ func TestAccIpSpaceResource_DhcpOptions(t *testing.T) { func TestAccIpSpaceResource_DhcpOptionsV6(t *testing.T) { var resourceName = "bloxone_ipam_ip_space.test_dhcp_options_v6" - var v1, v2 ipam.IpamsvcIPSpace + var v1 ipam.IpamsvcIPSpace resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -367,8 +366,7 @@ func TestAccIpSpaceResource_DhcpOptionsV6(t *testing.T) { { Config: testAccIpSpaceDhcpOptionsGroupV6("ipspace_dhcp_options_test", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckIpSpaceDestroy(context.Background(), &v1), - testAccCheckIpSpaceExists(context.Background(), resourceName, &v2), + testAccCheckIpSpaceExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.#", "1"), ), }, @@ -987,7 +985,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccOptionBasicConfig(), config}, "") } @@ -1003,7 +1001,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccOptionBasicConfig(), config}, "") } @@ -1020,7 +1018,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionCodeBasicConfigV6("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") } func testAccIpSpaceDhcpOptionsGroupV6(name string, type_ string) string { @@ -1035,7 +1033,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { ] } `, name, type_) - return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip6"), config}, "") + return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") } func testAccIpSpaceHeaderOptionFilename(name, headerOptionFilename string) string { diff --git a/internal/service/ipam/api_option_code_resource_test.go b/internal/service/ipam/api_option_code_resource_test.go index 8cd81f54..b672583e 100644 --- a/internal/service/ipam/api_option_code_resource_test.go +++ b/internal/service/ipam/api_option_code_resource_test.go @@ -311,19 +311,6 @@ 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" { diff --git a/internal/service/ipam/api_range_resource_test.go b/internal/service/ipam/api_range_resource_test.go index e6338fef..322e0780 100644 --- a/internal/service/ipam/api_range_resource_test.go +++ b/internal/service/ipam/api_range_resource_test.go @@ -134,7 +134,7 @@ func TestAccRangeResource_DisableDhcp(t *testing.T) { func TestAccRangeResource_DhcpOptions(t *testing.T) { var resourceName = "bloxone_ipam_range.test_dhcp_options" - var v1, v2 ipam.IpamsvcRange + var v1 ipam.IpamsvcRange resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -154,8 +154,7 @@ func TestAccRangeResource_DhcpOptions(t *testing.T) { { Config: testAccRangeDhcpOptionsGroup("10.0.0.10", "10.0.0.20", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckRangeDestroy(context.Background(), &v1), - testAccCheckRangeExists(context.Background(), resourceName, &v2), + testAccCheckRangeExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -284,7 +283,7 @@ func TestAccRangeResource_Name(t *testing.T) { func TestAccRangeResource_Space(t *testing.T) { var resourceName = "bloxone_ipam_range.test_space" - var v1, v2 ipam.IpamsvcRange + var v1 ipam.IpamsvcRange resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -302,8 +301,7 @@ func TestAccRangeResource_Space(t *testing.T) { { Config: testAccRangeSpace("10.0.0.8", "10.0.0.20", "bloxone_ipam_ip_space.one"), Check: resource.ComposeTestCheckFunc( - testAccCheckRangeDestroy(context.Background(), &v1), - testAccCheckRangeExists(context.Background(), resourceName, &v2), + testAccCheckRangeExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttrPair(resourceName, "space", "bloxone_ipam_ip_space.one", "id"), ), }, @@ -484,7 +482,7 @@ resource "bloxone_ipam_range" "test_dhcp_options" { } `, start, end, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") } @@ -504,7 +502,7 @@ resource "bloxone_ipam_range" "test_dhcp_options" { } `, start, end, type_) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") } diff --git a/internal/service/ipam/api_server_resource_test.go b/internal/service/ipam/api_server_resource_test.go index 2b28df7b..18f1d923 100644 --- a/internal/service/ipam/api_server_resource_test.go +++ b/internal/service/ipam/api_server_resource_test.go @@ -213,7 +213,7 @@ func TestAccServerResource_DdnsDomain(t *testing.T) { func TestAccServerResource_DhcpOptions(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_dhcp_options" - var v1, v2 ipam.IpamsvcServer + var v1 ipam.IpamsvcServer resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -233,8 +233,7 @@ func TestAccServerResource_DhcpOptions(t *testing.T) { { Config: testAccServerDhcpOptionsGroup("server_dhcp_options", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckServerDestroy(context.Background(), &v1), - testAccCheckServerExists(context.Background(), resourceName, &v2), + testAccCheckServerExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -245,7 +244,7 @@ func TestAccServerResource_DhcpOptions(t *testing.T) { func TestAccServerResource_DhcpOptionsV6(t *testing.T) { var resourceName = "bloxone_dhcp_server.test_dhcp_options" - var v1, v2 ipam.IpamsvcServer + var v1 ipam.IpamsvcServer resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -265,8 +264,7 @@ func TestAccServerResource_DhcpOptionsV6(t *testing.T) { { Config: testAccServerDhcpOptionsGroupV6("server_dhcp_options", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckServerDestroy(context.Background(), &v1), - testAccCheckServerExists(context.Background(), resourceName, &v2), + testAccCheckServerExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options_v6.#", "1"), ), }, @@ -1044,7 +1042,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccOptionBasicConfig(), config}, "") } func testAccServerDhcpOptionsGroup(name string, type_ string) string { @@ -1059,7 +1057,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccOptionBasicConfig(), config}, "") } func testAccServerDhcpOptionsOptionV6(name string, type_, optValue string) string { @@ -1075,7 +1073,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionCodeBasicConfigV6("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") } func testAccServerDhcpOptionsGroupV6(name string, type_ string) string { @@ -1090,7 +1088,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionGroupBasicConfig("option_group_test", "ip6"), config}, "") + return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") } func testAccServerDdnsEnabled(name string, ddnsEnabled string) string { diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index be65c33d..9de12d34 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -405,7 +405,7 @@ func TestAccSubnetResource_DdnsGeneratedPrefix(t *testing.T) { func TestAccSubnetResource_DhcpOptions(t *testing.T) { var resourceName = "bloxone_ipam_subnet.test_dhcp_options" - var v1, v2 ipam.IpamsvcSubnet + var v1 ipam.IpamsvcSubnet resource.Test(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -425,8 +425,7 @@ func TestAccSubnetResource_DhcpOptions(t *testing.T) { { Config: testAccSubnetDhcpOptionsGroup("10.0.0.0", 24, "option_group_test", "group"), Check: resource.ComposeTestCheckFunc( - testAccCheckSubnetDestroy(context.Background(), &v1), - testAccCheckSubnetExists(context.Background(), resourceName, &v2), + testAccCheckSubnetExists(context.Background(), resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "dhcp_options.#", "1"), ), }, @@ -1108,7 +1107,7 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } `, address, cidr, name, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionCodeBasicConfig("234", "test_dhcp_option_code", "boolean"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") } func testAccSubnetDhcpOptionsGroup(address string, cidr int, name, type_ string) string { @@ -1127,7 +1126,41 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } `, address, cidr, name, type_) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionGroupBasicConfig("option_group_test", "ip4"), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") +} + +func testAccOptionBasicConfig() string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_option_group" "test" { + name = "option_group_test" + protocol = "ip4" +} +resource "bloxone_dhcp_option_code" "test" { + code = "234" + name = "test_dhcp_option_code" + option_space = bloxone_dhcp_option_space.test.id + type = "boolean" +} +`) + + return strings.Join([]string{testAccOptionSpace("test_option_space", "ip4"), config}, "") +} + +func testAccOptionBasicConfigV6() string { + config := fmt.Sprintf(` +resource "bloxone_dhcp_option_group" "test" { + name = "option_group_test" + protocol = "ip6" +} +resource "bloxone_dhcp_option_code" "test" { + code = "59" + name = "test_dhcp_option_code" + option_space = bloxone_dhcp_option_space.test.id + type = "text" +} +`) + + return strings.Join([]string{testAccOptionSpace("test_option_space", "ip6"), config}, "") } func testAccSubnetDdnsDomain(address string, cidr int, ddnsDomain string) string { diff --git a/internal/service/ipam/model_ipamsvc_fixed_address.go b/internal/service/ipam/model_ipamsvc_fixed_address.go index f8ee9746..8a6c86ab 100644 --- a/internal/service/ipam/model_ipamsvc_fixed_address.go +++ b/internal/service/ipam/model_ipamsvc_fixed_address.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" @@ -99,9 +98,6 @@ var IpamsvcFixedAddressResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options. May be either a specific option or a group of options.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "disable_dhcp": schema.BoolAttribute{ Optional: true, diff --git a/internal/service/ipam/model_ipamsvc_ip_space.go b/internal/service/ipam/model_ipamsvc_ip_space.go index ddf3aa8c..9e57f9fc 100644 --- a/internal/service/ipam/model_ipamsvc_ip_space.go +++ b/internal/service/ipam/model_ipamsvc_ip_space.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -214,9 +213,6 @@ var IpamsvcIPSpaceResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: `The list of IPv4 DHCP options for IP space. May be either a specific option or a group of options.`, - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "dhcp_options_v6": schema.ListNestedAttribute{ NestedObject: schema.NestedAttributeObject{ @@ -224,9 +220,6 @@ var IpamsvcIPSpaceResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: `The list of IPv6 DHCP options for IP space. May be either a specific option or a group of options.`, - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "header_option_filename": schema.StringAttribute{ Optional: true, diff --git a/internal/service/ipam/model_ipamsvc_range.go b/internal/service/ipam/model_ipamsvc_range.go index 25f6291e..dac96e85 100644 --- a/internal/service/ipam/model_ipamsvc_range.go +++ b/internal/service/ipam/model_ipamsvc_range.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" @@ -96,9 +95,6 @@ var IpamsvcRangeResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options. May be either a specific option or a group of options.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "disable_dhcp": schema.BoolAttribute{ Optional: true, diff --git a/internal/service/ipam/model_ipamsvc_server.go b/internal/service/ipam/model_ipamsvc_server.go index b4bb9b4d..9950432c 100644 --- a/internal/service/ipam/model_ipamsvc_server.go +++ b/internal/service/ipam/model_ipamsvc_server.go @@ -224,9 +224,6 @@ var IpamsvcServerResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options or group of options for IPv4. An option list is ordered and may include both option groups and specific options. Multiple occurrences of the same option or group is not an error. The last occurrence of an option in the list will be used. Error if the graph of referenced groups contains cycles. Defaults to empty list.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "dhcp_options_v6": schema.ListNestedAttribute{ NestedObject: schema.NestedAttributeObject{ @@ -234,9 +231,6 @@ var IpamsvcServerResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options or group of options for IPv6. An option list is ordered and may include both option groups and specific options. Multiple occurrences of the same option or group is not an error. The last occurrence of an option in the list will be used. Error if the graph of referenced groups contains cycles. Defaults to empty list.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "gss_tsig_fallback": schema.BoolAttribute{ Optional: true, diff --git a/internal/service/ipam/model_ipamsvc_subnet.go b/internal/service/ipam/model_ipamsvc_subnet.go index 28f5ba8e..9a0a1e7f 100644 --- a/internal/service/ipam/model_ipamsvc_subnet.go +++ b/internal/service/ipam/model_ipamsvc_subnet.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -259,9 +258,6 @@ var IpamsvcSubnetResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The DHCP options of the subnet. This can either be a specific option or a group of options.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "dhcp_utilization": schema.SingleNestedAttribute{ Attributes: IpamsvcDHCPUtilizationResourceSchemaAttributes, From 41f02f9b3f0bd1f53a4dbc711ecbb60e2fe59605 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Sat, 10 Feb 2024 18:01:17 +0530 Subject: [PATCH 08/11] fix fo linter --- internal/service/ipam/api_subnet_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index 9de12d34..ac51858e 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -1130,7 +1130,7 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } func testAccOptionBasicConfig() string { - config := fmt.Sprintf(` + config := fmt.Sprint(` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" protocol = "ip4" @@ -1147,7 +1147,7 @@ resource "bloxone_dhcp_option_code" "test" { } func testAccOptionBasicConfigV6() string { - config := fmt.Sprintf(` + config := fmt.Sprint(` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" protocol = "ip6" From 948ff04f867a60c77e6c601052664dea93c8c454 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Sun, 11 Feb 2024 11:54:13 +0530 Subject: [PATCH 09/11] fix fo linter, removed sprintf --- internal/service/ipam/api_subnet_resource_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index ac51858e..45569383 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -1130,7 +1130,7 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } func testAccOptionBasicConfig() string { - config := fmt.Sprint(` + config := ` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" protocol = "ip4" @@ -1141,13 +1141,12 @@ resource "bloxone_dhcp_option_code" "test" { option_space = bloxone_dhcp_option_space.test.id type = "boolean" } -`) - +` return strings.Join([]string{testAccOptionSpace("test_option_space", "ip4"), config}, "") } func testAccOptionBasicConfigV6() string { - config := fmt.Sprint(` + config := ` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" protocol = "ip6" @@ -1158,8 +1157,7 @@ resource "bloxone_dhcp_option_code" "test" { option_space = bloxone_dhcp_option_space.test.id type = "text" } -`) - +` return strings.Join([]string{testAccOptionSpace("test_option_space", "ip6"), config}, "") } From 332145747942d63c3b2d0849f0f1724bf7166207 Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Wed, 14 Feb 2024 12:40:09 +0530 Subject: [PATCH 10/11] PR comments fix --- docs/resources/dhcp_fixed_address.md | 30 +++++++++---------- docs/resources/dns_server.md | 14 +++++++++ docs/resources/ipam_address_block.md | 15 ++++++++++ docs/resources/ipam_ip_space.md | 15 ++++++++++ docs/resources/ipam_range.md | 15 ++++++++++ docs/resources/ipam_subnet.md | 29 +++++++++--------- .../bloxone_dhcp_fixed_address/resource.tf | 30 +++++++++---------- .../resources/bloxone_dns_server/resource.tf | 14 +++++++++ .../bloxone_ipam_address_block/resource.tf | 15 ++++++++++ .../bloxone_ipam_ip_space/resource.tf | 15 ++++++++++ .../resources/bloxone_ipam_range/resource.tf | 15 ++++++++++ .../resources/bloxone_ipam_subnet/resource.tf | 29 +++++++++--------- .../ipam/api_address_block_resource_test.go | 4 +-- .../ipam/api_fixed_address_resource_test.go | 4 +-- .../ipam/api_ip_space_resource_test.go | 8 ++--- .../service/ipam/api_range_resource_test.go | 4 +-- .../service/ipam/api_server_resource_test.go | 8 ++--- .../service/ipam/api_subnet_resource_test.go | 8 ++--- 18 files changed, 194 insertions(+), 78 deletions(-) diff --git a/docs/resources/dhcp_fixed_address.md b/docs/resources/dhcp_fixed_address.md index 28b5e103..eac3b6f1 100644 --- a/docs/resources/dhcp_fixed_address.md +++ b/docs/resources/dhcp_fixed_address.md @@ -45,6 +45,13 @@ resource "bloxone_ipam_subnet" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + + resource "bloxone_dhcp_fixed_address" "example_fixed_address" { name = "example_fixed_address" address = "192.168.1.1" @@ -55,16 +62,17 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location = "site1" } + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] depends_on = [bloxone_ipam_subnet.example] } -resource "bloxone_dhcp_option_code" "option_code" { - code = 250 - name = "example_option_code" - option_space = bloxone_dhcp_option_space.option_space.id - type = "int32" -} - // Address using Next available IP resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" { name = "example_fixed_address" @@ -76,14 +84,6 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" { tags = { location : "site1" } - //dhcp options - dhcp_options = [ - { - option_code = bloxone_dhcp_option_code.option_code.id - option_value = "true" - type = "option" - } - ] depends_on = [bloxone_ipam_subnet.example] } ``` diff --git a/docs/resources/dns_server.md b/docs/resources/dns_server.md index be59a878..6fd5780d 100644 --- a/docs/resources/dns_server.md +++ b/docs/resources/dns_server.md @@ -16,6 +16,12 @@ A Server (DNS Config Profile) is a named configuration profile that can be share ## Example Usage ```terraform +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_dns_server" "example_server" { name = "example_dns_server" @@ -24,6 +30,14 @@ resource "bloxone_dns_server" "example_server" { tags = { site = "Site A" } + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } ``` diff --git a/docs/resources/ipam_address_block.md b/docs/resources/ipam_address_block.md index 9b57db11..077bab52 100644 --- a/docs/resources/ipam_address_block.md +++ b/docs/resources/ipam_address_block.md @@ -23,11 +23,26 @@ resource "bloxone_ipam_ip_space" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_address_block" "example" { address = "192.168.1.0" cidr = 24 name = "example_address_block" space = bloxone_ipam_ip_space.example.id + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } resource "bloxone_ipam_address_block" "example_tags" { diff --git a/docs/resources/ipam_ip_space.md b/docs/resources/ipam_ip_space.md index 271a8f26..c8458f90 100644 --- a/docs/resources/ipam_ip_space.md +++ b/docs/resources/ipam_ip_space.md @@ -20,12 +20,27 @@ resource "bloxone_ipam_ip_space" "example" { name = "example_ip_space" } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_ip_space" "example_tags" { name = "example_ip_space_tags" comment = "Example IP space with tags created by the terraform provider" tags = { location = "site1" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } ``` diff --git a/docs/resources/ipam_range.md b/docs/resources/ipam_range.md index adaac7e9..5d6b4e31 100644 --- a/docs/resources/ipam_range.md +++ b/docs/resources/ipam_range.md @@ -24,6 +24,12 @@ resource "bloxone_ipam_ip_space" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_subnet" "example" { name = "example" space = bloxone_ipam_ip_space.example.id @@ -33,6 +39,15 @@ resource "bloxone_ipam_subnet" "example" { tags = { location = "site1" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } resource "bloxone_ipam_range" "example" { diff --git a/docs/resources/ipam_subnet.md b/docs/resources/ipam_subnet.md index ab5e19f5..9d682916 100644 --- a/docs/resources/ipam_subnet.md +++ b/docs/resources/ipam_subnet.md @@ -26,6 +26,12 @@ resource "bloxone_ipam_address_block" "example" { space = bloxone_ipam_ip_space.example.id } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + # Static address resource "bloxone_ipam_subnet" "example" { address = "10.0.0.0" @@ -38,13 +44,14 @@ resource "bloxone_ipam_subnet" "example" { tags = { site = "Site A" } -} - -resource "bloxone_dhcp_option_code" "option_code" { - code = 250 - name = "example_option_code" - option_space = bloxone_dhcp_option_space.option_space.id - type = "int32" + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } # Next available subnet @@ -59,14 +66,6 @@ resource "bloxone_ipam_subnet" "example_na_s" { tags = { site = "Site A" } - #dhcp options - dhcp_options = [ - { - option_code = bloxone_dhcp_option_code.option_code.id - option_value = "true" - type = "option" - } - ] } ``` diff --git a/examples/resources/bloxone_dhcp_fixed_address/resource.tf b/examples/resources/bloxone_dhcp_fixed_address/resource.tf index f47837ec..7430b34c 100644 --- a/examples/resources/bloxone_dhcp_fixed_address/resource.tf +++ b/examples/resources/bloxone_dhcp_fixed_address/resource.tf @@ -27,6 +27,13 @@ resource "bloxone_ipam_subnet" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + + resource "bloxone_dhcp_fixed_address" "example_fixed_address" { name = "example_fixed_address" address = "192.168.1.1" @@ -37,16 +44,17 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { tags = { location = "site1" } + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] depends_on = [bloxone_ipam_subnet.example] } -resource "bloxone_dhcp_option_code" "option_code" { - code = 250 - name = "example_option_code" - option_space = bloxone_dhcp_option_space.option_space.id - type = "int32" -} - // Address using Next available IP resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" { name = "example_fixed_address" @@ -58,13 +66,5 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address_na" { tags = { location : "site1" } - //dhcp options - dhcp_options = [ - { - option_code = bloxone_dhcp_option_code.option_code.id - option_value = "true" - type = "option" - } - ] depends_on = [bloxone_ipam_subnet.example] } diff --git a/examples/resources/bloxone_dns_server/resource.tf b/examples/resources/bloxone_dns_server/resource.tf index 4743ae53..06567233 100644 --- a/examples/resources/bloxone_dns_server/resource.tf +++ b/examples/resources/bloxone_dns_server/resource.tf @@ -1,4 +1,10 @@ +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_dns_server" "example_server" { name = "example_dns_server" @@ -7,4 +13,12 @@ resource "bloxone_dns_server" "example_server" { tags = { site = "Site A" } + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } diff --git a/examples/resources/bloxone_ipam_address_block/resource.tf b/examples/resources/bloxone_ipam_address_block/resource.tf index ac5557e0..a024c374 100644 --- a/examples/resources/bloxone_ipam_address_block/resource.tf +++ b/examples/resources/bloxone_ipam_address_block/resource.tf @@ -5,11 +5,26 @@ resource "bloxone_ipam_ip_space" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_address_block" "example" { address = "192.168.1.0" cidr = 24 name = "example_address_block" space = bloxone_ipam_ip_space.example.id + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } resource "bloxone_ipam_address_block" "example_tags" { diff --git a/examples/resources/bloxone_ipam_ip_space/resource.tf b/examples/resources/bloxone_ipam_ip_space/resource.tf index ff82961a..060ed03a 100644 --- a/examples/resources/bloxone_ipam_ip_space/resource.tf +++ b/examples/resources/bloxone_ipam_ip_space/resource.tf @@ -2,10 +2,25 @@ resource "bloxone_ipam_ip_space" "example" { name = "example_ip_space" } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_ip_space" "example_tags" { name = "example_ip_space_tags" comment = "Example IP space with tags created by the terraform provider" tags = { location = "site1" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } diff --git a/examples/resources/bloxone_ipam_range/resource.tf b/examples/resources/bloxone_ipam_range/resource.tf index ce49d2a1..85815e93 100644 --- a/examples/resources/bloxone_ipam_range/resource.tf +++ b/examples/resources/bloxone_ipam_range/resource.tf @@ -6,6 +6,12 @@ resource "bloxone_ipam_ip_space" "example" { } } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_ipam_subnet" "example" { name = "example" space = bloxone_ipam_ip_space.example.id @@ -15,6 +21,15 @@ resource "bloxone_ipam_subnet" "example" { tags = { location = "site1" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } resource "bloxone_ipam_range" "example" { diff --git a/examples/resources/bloxone_ipam_subnet/resource.tf b/examples/resources/bloxone_ipam_subnet/resource.tf index c569f58a..1d8d8b68 100644 --- a/examples/resources/bloxone_ipam_subnet/resource.tf +++ b/examples/resources/bloxone_ipam_subnet/resource.tf @@ -8,6 +8,12 @@ resource "bloxone_ipam_address_block" "example" { space = bloxone_ipam_ip_space.example.id } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + # Static address resource "bloxone_ipam_subnet" "example" { address = "10.0.0.0" @@ -20,13 +26,14 @@ resource "bloxone_ipam_subnet" "example" { tags = { site = "Site A" } -} - -resource "bloxone_dhcp_option_code" "option_code" { - code = 250 - name = "example_option_code" - option_space = bloxone_dhcp_option_space.option_space.id - type = "int32" + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "1.1.1.1" + type = "option" + } + ] } # Next available subnet @@ -41,12 +48,4 @@ resource "bloxone_ipam_subnet" "example_na_s" { tags = { site = "Site A" } - #dhcp options - dhcp_options = [ - { - option_code = bloxone_dhcp_option_code.option_code.id - option_value = "true" - type = "option" - } - ] } diff --git a/internal/service/ipam/api_address_block_resource_test.go b/internal/service/ipam/api_address_block_resource_test.go index ae7cc973..667d1dd4 100644 --- a/internal/service/ipam/api_address_block_resource_test.go +++ b/internal/service/ipam/api_address_block_resource_test.go @@ -1033,7 +1033,7 @@ resource "bloxone_ipam_address_block" "test_dhcp_options" { ] } `, name, cidr, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccAddressBlockDhcpOptionsGroup(name string, cidr string, type_ string) string { @@ -1050,7 +1050,7 @@ resource "bloxone_ipam_address_block" "test_dhcp_options" { ] } `, name, cidr, type_) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccAddressBlockDdnsGenerateName(address string, cidr string, ddnsGenerateName string) string { diff --git a/internal/service/ipam/api_fixed_address_resource_test.go b/internal/service/ipam/api_fixed_address_resource_test.go index 9f2f5bb3..28e8a340 100644 --- a/internal/service/ipam/api_fixed_address_resource_test.go +++ b/internal/service/ipam/api_fixed_address_resource_test.go @@ -680,7 +680,7 @@ resource "bloxone_dhcp_fixed_address" "test_dhcp_options" { ] } `, address, matchType, matchValue, name, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccFixedAddressDhcpOptionsGroup(address string, matchType string, matchValue string, name, type_ string) string { @@ -700,7 +700,7 @@ resource "bloxone_dhcp_fixed_address" "test_dhcp_options" { ] } `, address, matchType, matchValue, name, type_) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccFixedAddressHeaderOptionFilename(address string, matchType string, matchValue string, headerOptionFilename string) string { diff --git a/internal/service/ipam/api_ip_space_resource_test.go b/internal/service/ipam/api_ip_space_resource_test.go index cc58b202..6625a47c 100644 --- a/internal/service/ipam/api_ip_space_resource_test.go +++ b/internal/service/ipam/api_ip_space_resource_test.go @@ -985,7 +985,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithOptionSpaceAndCode(), config}, "") } @@ -1001,7 +1001,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithOptionSpaceAndCode(), config}, "") } @@ -1018,7 +1018,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") + return strings.Join([]string{testAccBaseWithV6OptionSpaceAndCode(), config}, "") } func testAccIpSpaceDhcpOptionsGroupV6(name string, type_ string) string { @@ -1033,7 +1033,7 @@ resource "bloxone_ipam_ip_space" "test_dhcp_options_v6" { ] } `, name, type_) - return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") + return strings.Join([]string{testAccBaseWithV6OptionSpaceAndCode(), config}, "") } func testAccIpSpaceHeaderOptionFilename(name, headerOptionFilename string) string { diff --git a/internal/service/ipam/api_range_resource_test.go b/internal/service/ipam/api_range_resource_test.go index 322e0780..d32a2055 100644 --- a/internal/service/ipam/api_range_resource_test.go +++ b/internal/service/ipam/api_range_resource_test.go @@ -482,7 +482,7 @@ resource "bloxone_ipam_range" "test_dhcp_options" { } `, start, end, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccBaseWithOptionSpaceAndCode(), config}, "") } @@ -502,7 +502,7 @@ resource "bloxone_ipam_range" "test_dhcp_options" { } `, start, end, type_) - return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpaceAndSubnet(), testAccBaseWithOptionSpaceAndCode(), config}, "") } diff --git a/internal/service/ipam/api_server_resource_test.go b/internal/service/ipam/api_server_resource_test.go index 18f1d923..cd997786 100644 --- a/internal/service/ipam/api_server_resource_test.go +++ b/internal/service/ipam/api_server_resource_test.go @@ -1042,7 +1042,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccServerDhcpOptionsGroup(name string, type_ string) string { @@ -1057,7 +1057,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccServerDhcpOptionsOptionV6(name string, type_, optValue string) string { @@ -1073,7 +1073,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_, optValue) - return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") + return strings.Join([]string{testAccBaseWithV6OptionSpaceAndCode(), config}, "") } func testAccServerDhcpOptionsGroupV6(name string, type_ string) string { @@ -1088,7 +1088,7 @@ resource "bloxone_dhcp_server" "test_dhcp_options" { ] } `, name, type_) - return strings.Join([]string{testAccOptionBasicConfigV6(), config}, "") + return strings.Join([]string{testAccBaseWithV6OptionSpaceAndCode(), config}, "") } func testAccServerDdnsEnabled(name string, ddnsEnabled string) string { diff --git a/internal/service/ipam/api_subnet_resource_test.go b/internal/service/ipam/api_subnet_resource_test.go index 45569383..87020031 100644 --- a/internal/service/ipam/api_subnet_resource_test.go +++ b/internal/service/ipam/api_subnet_resource_test.go @@ -1107,7 +1107,7 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } `, address, cidr, name, type_, optValue) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccBaseWithOptionSpaceAndCode(), config}, "") } func testAccSubnetDhcpOptionsGroup(address string, cidr int, name, type_ string) string { @@ -1126,10 +1126,10 @@ resource "bloxone_ipam_subnet" "test_dhcp_options" { } `, address, cidr, name, type_) - return strings.Join([]string{testAccBaseWithIPSpace(), testAccOptionBasicConfig(), config}, "") + return strings.Join([]string{testAccBaseWithIPSpace(), testAccBaseWithOptionSpaceAndCode(), config}, "") } -func testAccOptionBasicConfig() string { +func testAccBaseWithOptionSpaceAndCode() string { config := ` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" @@ -1145,7 +1145,7 @@ resource "bloxone_dhcp_option_code" "test" { return strings.Join([]string{testAccOptionSpace("test_option_space", "ip4"), config}, "") } -func testAccOptionBasicConfigV6() string { +func testAccBaseWithV6OptionSpaceAndCode() string { config := ` resource "bloxone_dhcp_option_group" "test" { name = "option_group_test" From af2c0a1dde28abf9ca4f9f931c76ebc264456edc Mon Sep 17 00:00:00 2001 From: Anil Gadiyar Date: Thu, 15 Feb 2024 11:00:51 +0530 Subject: [PATCH 11/11] PR comments fix --- docs/resources/dhcp_fixed_address.md | 2 +- docs/resources/dhcp_server.md | 15 +++++++++++++++ docs/resources/dns_server.md | 14 -------------- docs/resources/ipam_address_block.md | 2 +- docs/resources/ipam_ip_space.md | 2 +- docs/resources/ipam_range.md | 2 +- docs/resources/ipam_subnet.md | 2 +- .../bloxone_dhcp_fixed_address/resource.tf | 2 +- .../resources/bloxone_dhcp_server/resource.tf | 15 +++++++++++++++ examples/resources/bloxone_dns_server/resource.tf | 14 -------------- .../bloxone_ipam_address_block/resource.tf | 2 +- .../resources/bloxone_ipam_ip_space/resource.tf | 2 +- examples/resources/bloxone_ipam_range/resource.tf | 2 +- .../resources/bloxone_ipam_subnet/resource.tf | 2 +- .../service/ipam/model_ipamsvc_address_block.go | 4 ---- .../service/ipam/model_ipamsvc_fixed_address.go | 1 - internal/service/ipam/model_ipamsvc_subnet.go | 1 - 17 files changed, 40 insertions(+), 44 deletions(-) diff --git a/docs/resources/dhcp_fixed_address.md b/docs/resources/dhcp_fixed_address.md index eac3b6f1..2a926fc7 100644 --- a/docs/resources/dhcp_fixed_address.md +++ b/docs/resources/dhcp_fixed_address.md @@ -66,7 +66,7 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/docs/resources/dhcp_server.md b/docs/resources/dhcp_server.md index de0fa844..cee65d32 100644 --- a/docs/resources/dhcp_server.md +++ b/docs/resources/dhcp_server.md @@ -20,6 +20,12 @@ resource "bloxone_dhcp_server" "example" { name = "example_dhcp_server" } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_dhcp_server" "example_with_options" { name = "example_dhcp_server_with_options" @@ -28,6 +34,15 @@ resource "bloxone_dhcp_server" "example_with_options" { tags = { site = "Site A" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "10.0.0.1" + type = "option" + } + ] } ``` diff --git a/docs/resources/dns_server.md b/docs/resources/dns_server.md index 6fd5780d..be59a878 100644 --- a/docs/resources/dns_server.md +++ b/docs/resources/dns_server.md @@ -16,12 +16,6 @@ A Server (DNS Config Profile) is a named configuration profile that can be share ## Example Usage ```terraform -data "bloxone_dhcp_option_codes" "option_code" { - filters = { - name = "domain-name-servers" - } -} - resource "bloxone_dns_server" "example_server" { name = "example_dns_server" @@ -30,14 +24,6 @@ resource "bloxone_dns_server" "example_server" { tags = { site = "Site A" } - //dhcp options - dhcp_options = [ - { - option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" - type = "option" - } - ] } ``` diff --git a/docs/resources/ipam_address_block.md b/docs/resources/ipam_address_block.md index 077bab52..8a977021 100644 --- a/docs/resources/ipam_address_block.md +++ b/docs/resources/ipam_address_block.md @@ -39,7 +39,7 @@ resource "bloxone_ipam_address_block" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/docs/resources/ipam_ip_space.md b/docs/resources/ipam_ip_space.md index c8458f90..c1651d7c 100644 --- a/docs/resources/ipam_ip_space.md +++ b/docs/resources/ipam_ip_space.md @@ -37,7 +37,7 @@ resource "bloxone_ipam_ip_space" "example_tags" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/docs/resources/ipam_range.md b/docs/resources/ipam_range.md index 5d6b4e31..38849cb6 100644 --- a/docs/resources/ipam_range.md +++ b/docs/resources/ipam_range.md @@ -44,7 +44,7 @@ resource "bloxone_ipam_subnet" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/docs/resources/ipam_subnet.md b/docs/resources/ipam_subnet.md index 9d682916..cd739588 100644 --- a/docs/resources/ipam_subnet.md +++ b/docs/resources/ipam_subnet.md @@ -48,7 +48,7 @@ resource "bloxone_ipam_subnet" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/examples/resources/bloxone_dhcp_fixed_address/resource.tf b/examples/resources/bloxone_dhcp_fixed_address/resource.tf index 7430b34c..7af91d27 100644 --- a/examples/resources/bloxone_dhcp_fixed_address/resource.tf +++ b/examples/resources/bloxone_dhcp_fixed_address/resource.tf @@ -48,7 +48,7 @@ resource "bloxone_dhcp_fixed_address" "example_fixed_address" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/examples/resources/bloxone_dhcp_server/resource.tf b/examples/resources/bloxone_dhcp_server/resource.tf index fdfd7cf0..cb093087 100644 --- a/examples/resources/bloxone_dhcp_server/resource.tf +++ b/examples/resources/bloxone_dhcp_server/resource.tf @@ -2,6 +2,12 @@ resource "bloxone_dhcp_server" "example" { name = "example_dhcp_server" } +data "bloxone_dhcp_option_codes" "option_code" { + filters = { + name = "domain-name-servers" + } +} + resource "bloxone_dhcp_server" "example_with_options" { name = "example_dhcp_server_with_options" @@ -10,4 +16,13 @@ resource "bloxone_dhcp_server" "example_with_options" { tags = { site = "Site A" } + + //dhcp options + dhcp_options = [ + { + option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id + option_value = "10.0.0.1" + type = "option" + } + ] } diff --git a/examples/resources/bloxone_dns_server/resource.tf b/examples/resources/bloxone_dns_server/resource.tf index 06567233..4743ae53 100644 --- a/examples/resources/bloxone_dns_server/resource.tf +++ b/examples/resources/bloxone_dns_server/resource.tf @@ -1,10 +1,4 @@ -data "bloxone_dhcp_option_codes" "option_code" { - filters = { - name = "domain-name-servers" - } -} - resource "bloxone_dns_server" "example_server" { name = "example_dns_server" @@ -13,12 +7,4 @@ resource "bloxone_dns_server" "example_server" { tags = { site = "Site A" } - //dhcp options - dhcp_options = [ - { - option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" - type = "option" - } - ] } diff --git a/examples/resources/bloxone_ipam_address_block/resource.tf b/examples/resources/bloxone_ipam_address_block/resource.tf index a024c374..cd530bd7 100644 --- a/examples/resources/bloxone_ipam_address_block/resource.tf +++ b/examples/resources/bloxone_ipam_address_block/resource.tf @@ -21,7 +21,7 @@ resource "bloxone_ipam_address_block" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/examples/resources/bloxone_ipam_ip_space/resource.tf b/examples/resources/bloxone_ipam_ip_space/resource.tf index 060ed03a..209cf5bb 100644 --- a/examples/resources/bloxone_ipam_ip_space/resource.tf +++ b/examples/resources/bloxone_ipam_ip_space/resource.tf @@ -19,7 +19,7 @@ resource "bloxone_ipam_ip_space" "example_tags" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/examples/resources/bloxone_ipam_range/resource.tf b/examples/resources/bloxone_ipam_range/resource.tf index 85815e93..225593ba 100644 --- a/examples/resources/bloxone_ipam_range/resource.tf +++ b/examples/resources/bloxone_ipam_range/resource.tf @@ -26,7 +26,7 @@ resource "bloxone_ipam_subnet" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/examples/resources/bloxone_ipam_subnet/resource.tf b/examples/resources/bloxone_ipam_subnet/resource.tf index 1d8d8b68..4d9351f6 100644 --- a/examples/resources/bloxone_ipam_subnet/resource.tf +++ b/examples/resources/bloxone_ipam_subnet/resource.tf @@ -30,7 +30,7 @@ resource "bloxone_ipam_subnet" "example" { dhcp_options = [ { option_code = data.bloxone_dhcp_option_codes.option_code.results.0.id - option_value = "1.1.1.1" + option_value = "10.0.0.1" type = "option" } ] diff --git a/internal/service/ipam/model_ipamsvc_address_block.go b/internal/service/ipam/model_ipamsvc_address_block.go index 55a51839..dda8b8c3 100644 --- a/internal/service/ipam/model_ipamsvc_address_block.go +++ b/internal/service/ipam/model_ipamsvc_address_block.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" schema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -239,9 +238,6 @@ var IpamsvcAddressBlockResourceSchemaAttributes = map[string]schema.Attribute{ }, Optional: true, MarkdownDescription: "The list of DHCP options for the address block. May be either a specific option or a group of options.", - PlanModifiers: []planmodifier.List{ - listplanmodifier.RequiresReplaceIfConfigured(), - }, }, "dhcp_utilization": schema.SingleNestedAttribute{ Attributes: IpamsvcDHCPUtilizationResourceSchemaAttributes, diff --git a/internal/service/ipam/model_ipamsvc_fixed_address.go b/internal/service/ipam/model_ipamsvc_fixed_address.go index 8a6c86ab..4bf895f8 100644 --- a/internal/service/ipam/model_ipamsvc_fixed_address.go +++ b/internal/service/ipam/model_ipamsvc_fixed_address.go @@ -2,7 +2,6 @@ package ipam import ( "context" - "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" diff --git a/internal/service/ipam/model_ipamsvc_subnet.go b/internal/service/ipam/model_ipamsvc_subnet.go index 9a0a1e7f..c9e84a37 100644 --- a/internal/service/ipam/model_ipamsvc_subnet.go +++ b/internal/service/ipam/model_ipamsvc_subnet.go @@ -2,7 +2,6 @@ package ipam import ( "context" - "regexp" "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"