@@ -10,6 +10,8 @@ import (
1010 "github.com/hashicorp/terraform/helper/schema"
1111 "github.com/hashicorp/terraform/helper/validation"
1212
13+ "fmt"
14+
1315 oci_core "github.com/oracle/oci-go-sdk/core"
1416)
1517
@@ -212,7 +214,11 @@ func (s *DhcpOptionsResourceCrud) Create() error {
212214 interfaces := options .([]interface {})
213215 tmp := make ([]oci_core.DhcpOption , len (interfaces ))
214216 for i , toBeConverted := range interfaces {
215- tmp [i ] = mapToDhcpOption (toBeConverted .(map [string ]interface {}))
217+ converted , err := mapToDhcpOption (toBeConverted .(map [string ]interface {}))
218+ if err != nil {
219+ return err
220+ }
221+ tmp [i ] = converted
216222 }
217223 request .Options = tmp
218224 }
@@ -278,7 +284,11 @@ func (s *DhcpOptionsResourceCrud) Update() error {
278284 interfaces := options .([]interface {})
279285 tmp := make ([]oci_core.DhcpOption , len (interfaces ))
280286 for i , toBeConverted := range interfaces {
281- tmp [i ] = mapToDhcpOption (toBeConverted .(map [string ]interface {}))
287+ converted , err := mapToDhcpOption (toBeConverted .(map [string ]interface {}))
288+ if err != nil {
289+ return err
290+ }
291+ tmp [i ] = converted
282292 }
283293 request .Options = tmp
284294 }
@@ -340,7 +350,7 @@ func (s *DhcpOptionsResourceCrud) SetData() error {
340350 return nil
341351}
342352
343- func mapToDhcpOption (raw map [string ]interface {}) oci_core.DhcpOption {
353+ func mapToDhcpOption (raw map [string ]interface {}) ( oci_core.DhcpOption , error ) {
344354 var baseObject oci_core.DhcpOption
345355 //discriminator
346356 typeRaw , ok := raw ["type" ]
@@ -352,6 +362,9 @@ func mapToDhcpOption(raw map[string]interface{}) oci_core.DhcpOption {
352362 }
353363 switch strings .ToLower (type_ ) {
354364 case strings .ToLower ("DomainNameServer" ):
365+ if searchDomainNames , ok := raw ["search_domain_names" ]; ok && len (searchDomainNames .([]interface {})) > 0 {
366+ return nil , fmt .Errorf ("'search_domain_names' should not be specified for type DomainNameServer" )
367+ }
355368 details := oci_core.DhcpDnsOption {}
356369 details .CustomDnsServers = []string {}
357370 if customDnsServers , ok := raw ["custom_dns_servers" ]; ok {
@@ -367,6 +380,14 @@ func mapToDhcpOption(raw map[string]interface{}) oci_core.DhcpOption {
367380 }
368381 baseObject = details
369382 case strings .ToLower ("SearchDomain" ):
383+ if customDnsServers , ok := raw ["custom_dns_servers" ]; ok && len (customDnsServers .([]interface {})) > 0 {
384+ return nil , fmt .Errorf ("'custom_dns_servers' should not be specified for type SearchDomain" )
385+ }
386+
387+ if serverType , ok := raw ["server_type" ]; ok && len (serverType .(string )) > 0 {
388+ return nil , fmt .Errorf ("'server_type' should not be specified for type SearchDomain" )
389+ }
390+
370391 details := oci_core.DhcpSearchDomainOption {}
371392 details .SearchDomainNames = []string {}
372393 if searchDomainNames , ok := raw ["search_domain_names" ]; ok {
@@ -380,8 +401,9 @@ func mapToDhcpOption(raw map[string]interface{}) oci_core.DhcpOption {
380401 baseObject = details
381402 default :
382403 log .Printf ("[WARN] Unknown type '%v' was specified" , type_ )
404+ return baseObject , fmt .Errorf ("unknown type '%v' was specified" , type_ )
383405 }
384- return baseObject
406+ return baseObject , nil
385407}
386408
387409func DhcpOptionToMap (obj oci_core.DhcpOption ) map [string ]interface {} {
0 commit comments