@@ -12,17 +12,9 @@ import (
1212 "github.com/hashicorp/terraform/helper/resource"
1313 "github.com/hashicorp/terraform/terraform"
1414
15- core "github.com/oracle/oci-go-sdk/core"
16- "github.com/stretchr/testify/suite"
15+ "github.com/oracle/oci-go-sdk/core"
1716)
1817
19- type ResourceCoreDHCPOptionsTestSuite struct {
20- suite.Suite
21- Providers map [string ]terraform.ResourceProvider
22- Config string
23- ResourceName string
24- }
25-
2618var defaultDhcpOpts = `
2719resource "oci_core_default_dhcp_options" "default" {
2820 manage_default_resource_id = "${oci_core_virtual_network.t.default_dhcp_options_id}"
@@ -54,10 +46,61 @@ var additionalDhcpOption4 = `
5446 }
5547 }`
5648
57- func (s * ResourceCoreDHCPOptionsTestSuite ) SetupTest () {
58- s .Providers = testAccProviders
59- testAccPreCheck (s .T ())
60- s .Config = legacyTestProviderConfig () + `
49+ //If you set DhcpDnsOption to `VcnLocalPlusInternet`, and you assign a DNS label to the VCN during creation, the search domain name in the VCN's default set of DHCP options is automatically set to the VCN domain
50+ //To avoid multiple applies we perform an apply after the create in order have the options match what the user has in the config
51+ //This test makes sure we handle that case correctly and that there is a non empty plan after the apply
52+ func TestResourceCoreDHCPOptions_avoidServiceDefault (t * testing.T ) {
53+ httpreplay .SetScenario ("TestAccResourceCoreDHCPOptions_avoidServiceDefault" )
54+ defer httpreplay .SaveScenario ()
55+
56+ provider := testAccProvider
57+
58+ resource .Test (t , resource.TestCase {
59+ PreCheck : func () { testAccPreCheck (t ) },
60+ Providers : map [string ]terraform.ResourceProvider {
61+ "oci" : provider ,
62+ },
63+ Steps : []resource.TestStep {
64+ {
65+ Config : legacyTestProviderConfig () + defaultDhcpOpts + `
66+ resource "oci_core_virtual_network" "t" {
67+ cidr_block = "10.1.0.0/16"
68+ compartment_id = "${var.compartment_id}"
69+ display_name = "testVcn"
70+ dns_label = "tftestvcn"
71+ }
72+
73+ resource "oci_core_dhcp_options" "opt" {
74+ compartment_id = "${var.compartment_id}"
75+ vcn_id = "${oci_core_virtual_network.t.id}"
76+ display_name = "testDhcpOptions"
77+
78+ // required
79+ options {
80+ type = "DomainNameServer"
81+ server_type = "VcnLocalPlusInternet"
82+ }
83+ }` ,
84+ Check : resource .ComposeAggregateTestCheckFunc (
85+ resource .TestCheckResourceAttr ("oci_core_dhcp_options.opt" , "display_name" , "testDhcpOptions" ),
86+ resource .TestCheckResourceAttr ("oci_core_dhcp_options.opt" , "options.#" , "1" ),
87+ resource .TestCheckResourceAttr ("oci_core_dhcp_options.opt" , "options.0.type" , "DomainNameServer" ),
88+ resource .TestCheckResourceAttr ("oci_core_dhcp_options.opt" , "options.0.server_type" , "VcnLocalPlusInternet" ),
89+ ),
90+ },
91+ },
92+ })
93+ }
94+
95+ func TestResourceCoreDHCPOptions_basic (t * testing.T ) {
96+ httpreplay .SetScenario ("TestAccResourceCoreDHCPOptions_basic" )
97+ defer httpreplay .SaveScenario ()
98+
99+ var resDefaultId , resOpt4Id , resId2 string
100+
101+ provider := testAccProvider
102+
103+ config := legacyTestProviderConfig () + `
61104 resource "oci_core_virtual_network" "t" {
62105 cidr_block = "10.0.0.0/16"
63106 compartment_id = "${var.compartment_id}"
@@ -104,13 +147,12 @@ func (s *ResourceCoreDHCPOptionsTestSuite) SetupTest() {
104147 custom_dns_servers = [ "8.8.4.4", "8.8.8.8" ]
105148 }
106149 }`
107- }
108-
109- func (s * ResourceCoreDHCPOptionsTestSuite ) TestAccResourceCoreDHCPOptions_basic () {
110- var resDefaultId , resOpt4Id , resId2 string
111150
112- resource .Test (s .T (), resource.TestCase {
113- Providers : s .Providers ,
151+ resource .Test (t , resource.TestCase {
152+ PreCheck : func () { testAccPreCheck (t ) },
153+ Providers : map [string ]terraform.ResourceProvider {
154+ "oci" : provider ,
155+ },
114156 Steps : []resource.TestStep {
115157 // Test invalid options type
116158 {
@@ -156,7 +198,7 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
156198 },
157199 // Verify result of strange polymorphic options
158200 {
159- Config : s . Config ,
201+ Config : config ,
160202 Check : nil ,
161203 },
162204 {
@@ -181,7 +223,7 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
181223 ExpectError : regexp .MustCompile ("InvalidParameter.*JSON input" ),
182224 },
183225 {
184- Config : s . Config + additionalDhcpOption4 + defaultDhcpOpts ,
226+ Config : config + additionalDhcpOption4 + defaultDhcpOpts ,
185227 Check : resource .ComposeAggregateTestCheckFunc (
186228
187229 resource .TestCheckResourceAttr ("oci_core_dhcp_options.opt1" , "display_name" , "display_name1" ),
@@ -259,12 +301,12 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
259301 },
260302 // Verify removing default DHCP options
261303 {
262- Config : s . Config + additionalDhcpOption4 ,
304+ Config : config + additionalDhcpOption4 ,
263305 Check : nil ,
264306 },
265307 // Verify adding default DHCP options again
266308 {
267- Config : s . Config + additionalDhcpOption4 + defaultDhcpOpts ,
309+ Config : config + additionalDhcpOption4 + defaultDhcpOpts ,
268310 Check : resource .ComposeAggregateTestCheckFunc (
269311 resource .TestCheckResourceAttr ("oci_core_default_dhcp_options.default" , "options.0.type" , "DomainNameServer" ),
270312 resource .TestCheckResourceAttr ("oci_core_default_dhcp_options.default" , "options.0.server_type" , "CustomDnsServer" ),
@@ -290,7 +332,7 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
290332 },
291333 // ensure that changing the case for options.?.type (polymorphic discriminator) is a no-op.
292334 {
293- Config : s . Config + `
335+ Config : config + `
294336 resource "oci_core_dhcp_options" "opt4" { # Same as additionalDhcpOption4 but with diff casing for 'type'.
295337 compartment_id = "${var.compartment_id}"
296338 vcn_id = "${oci_core_virtual_network.t.id}"
@@ -309,7 +351,7 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
309351 },
310352 // Changing to a different vcn should be a ForceNew
311353 {
312- Config : s . Config + `
354+ Config : config + `
313355 resource "oci_core_dhcp_options" "opt4" { # Same as alternate additionalDhcpOption4 above, but with diff vcn.
314356 compartment_id = "${var.compartment_id}"
315357 vcn_id = "${oci_core_virtual_network.t2.id}"
@@ -337,9 +379,3 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestAccResourceCoreDHCPOptions_basic(
337379 },
338380 })
339381}
340-
341- func TestResourceCoreDHCPOptionsTestSuite (t * testing.T ) {
342- httpreplay .SetScenario ("TestResourceCoreDHCPOptionsTestSuite" )
343- defer httpreplay .SaveScenario ()
344- suite .Run (t , new (ResourceCoreDHCPOptionsTestSuite ))
345- }
0 commit comments