@@ -4,8 +4,11 @@ package provider
44
55import (
66 "context"
7+ "fmt"
8+ "strings"
79
810 "github.com/hashicorp/terraform/helper/schema"
11+ "github.com/hashicorp/terraform/helper/validation"
912
1013 oci_database "github.com/oracle/oci-go-sdk/database"
1114)
@@ -47,6 +50,12 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
4750 },
4851
4952 // Optional
53+ "clone_type" : {
54+ Type : schema .TypeString ,
55+ Optional : true ,
56+ Computed : true ,
57+ ForceNew : true ,
58+ },
5059 "db_workload" : {
5160 Type : schema .TypeString ,
5261 Optional : true ,
@@ -77,6 +86,23 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
7786 Computed : true ,
7887 ForceNew : true ,
7988 },
89+ "source" : {
90+ Type : schema .TypeString ,
91+ Optional : true ,
92+ Computed : true ,
93+ ForceNew : true ,
94+ DiffSuppressFunc : EqualIgnoreCaseSuppressDiff ,
95+ ValidateFunc : validation .StringInSlice ([]string {
96+ "DATABASE" ,
97+ "NONE" ,
98+ }, true ),
99+ },
100+ "source_id" : {
101+ Type : schema .TypeString ,
102+ Optional : true ,
103+ Computed : true ,
104+ ForceNew : true ,
105+ },
80106
81107 // Computed
82108 "connection_strings" : {
@@ -131,6 +157,10 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
131157 Type : schema .TypeString ,
132158 Computed : true ,
133159 },
160+ "used_data_storage_size_in_tbs" : {
161+ Type : schema .TypeInt ,
162+ Computed : true ,
163+ },
134164 },
135165 }
136166}
@@ -221,55 +251,9 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) UpdatedTarget() []string {
221251
222252func (s * DatabaseAutonomousDatabaseResourceCrud ) Create () error {
223253 request := oci_database.CreateAutonomousDatabaseRequest {}
224-
225- if adminPassword , ok := s .D .GetOkExists ("admin_password" ); ok {
226- tmp := adminPassword .(string )
227- request .AdminPassword = & tmp
228- }
229-
230- if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
231- tmp := compartmentId .(string )
232- request .CompartmentId = & tmp
233- }
234-
235- if cpuCoreCount , ok := s .D .GetOkExists ("cpu_core_count" ); ok {
236- tmp := cpuCoreCount .(int )
237- request .CpuCoreCount = & tmp
238- }
239-
240- if dataStorageSizeInTBs , ok := s .D .GetOkExists ("data_storage_size_in_tbs" ); ok {
241- tmp := dataStorageSizeInTBs .(int )
242- request .DataStorageSizeInTBs = & tmp
243- }
244-
245- if dbName , ok := s .D .GetOkExists ("db_name" ); ok {
246- tmp := dbName .(string )
247- request .DbName = & tmp
248- }
249-
250- if dbWorkload , ok := s .D .GetOkExists ("db_workload" ); ok {
251- request .DbWorkload = oci_database .CreateAutonomousDatabaseDetailsDbWorkloadEnum (dbWorkload .(string ))
252- }
253-
254- if definedTags , ok := s .D .GetOkExists ("defined_tags" ); ok {
255- convertedDefinedTags , err := mapToDefinedTags (definedTags .(map [string ]interface {}))
256- if err != nil {
257- return err
258- }
259- request .DefinedTags = convertedDefinedTags
260- }
261-
262- if displayName , ok := s .D .GetOkExists ("display_name" ); ok {
263- tmp := displayName .(string )
264- request .DisplayName = & tmp
265- }
266-
267- if freeformTags , ok := s .D .GetOkExists ("freeform_tags" ); ok {
268- request .FreeformTags = objectMapToStringMap (freeformTags .(map [string ]interface {}))
269- }
270-
271- if licenseModel , ok := s .D .GetOkExists ("license_model" ); ok {
272- request .LicenseModel = oci_database .CreateAutonomousDatabaseDetailsLicenseModelEnum (licenseModel .(string ))
254+ err := s .populateTopLevelPolymorphicCreateAutonomousDatabaseRequest (& request )
255+ if err != nil {
256+ return err
273257 }
274258
275259 request .RequestMetadata .RetryPolicy = getRetryPolicy (s .DisableNotFoundRetries , "database" )
@@ -417,6 +401,10 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) SetData() error {
417401 s .D .Set ("time_created" , s .Res .TimeCreated .String ())
418402 }
419403
404+ if s .Res .UsedDataStorageSizeInTBs != nil {
405+ s .D .Set ("used_data_storage_size_in_tbs" , * s .Res .UsedDataStorageSizeInTBs )
406+ }
407+
420408 return nil
421409}
422410
@@ -439,3 +427,112 @@ func AutonomousDatabaseConnectionStringsToMap(obj *oci_database.AutonomousDataba
439427
440428 return result
441429}
430+
431+ func (s * DatabaseAutonomousDatabaseResourceCrud ) populateTopLevelPolymorphicCreateAutonomousDatabaseRequest (request * oci_database.CreateAutonomousDatabaseRequest ) error {
432+ //discriminator
433+ sourceRaw , ok := s .D .GetOkExists ("source" )
434+ var source string
435+ if ok {
436+ source = sourceRaw .(string )
437+ } else {
438+ source = "NONE" // default value
439+ }
440+ switch strings .ToLower (source ) {
441+ case strings .ToLower ("DATABASE" ):
442+ details := oci_database.CreateAutonomousDatabaseCloneDetails {}
443+ if cloneType , ok := s .D .GetOkExists ("clone_type" ); ok {
444+ details .CloneType = oci_database .CreateAutonomousDatabaseCloneDetailsCloneTypeEnum (cloneType .(string ))
445+ }
446+ if sourceId , ok := s .D .GetOkExists ("source_id" ); ok {
447+ tmp := sourceId .(string )
448+ details .SourceId = & tmp
449+ }
450+ if adminPassword , ok := s .D .GetOkExists ("admin_password" ); ok {
451+ tmp := adminPassword .(string )
452+ details .AdminPassword = & tmp
453+ }
454+ if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
455+ tmp := compartmentId .(string )
456+ details .CompartmentId = & tmp
457+ }
458+ if cpuCoreCount , ok := s .D .GetOkExists ("cpu_core_count" ); ok {
459+ tmp := cpuCoreCount .(int )
460+ details .CpuCoreCount = & tmp
461+ }
462+ if dataStorageSizeInTBs , ok := s .D .GetOkExists ("data_storage_size_in_tbs" ); ok {
463+ tmp := dataStorageSizeInTBs .(int )
464+ details .DataStorageSizeInTBs = & tmp
465+ }
466+ if dbName , ok := s .D .GetOkExists ("db_name" ); ok {
467+ tmp := dbName .(string )
468+ details .DbName = & tmp
469+ }
470+ if dbWorkload , ok := s .D .GetOkExists ("db_workload" ); ok {
471+ details .DbWorkload = oci_database .CreateAutonomousDatabaseBaseDbWorkloadEnum (dbWorkload .(string ))
472+ }
473+ if definedTags , ok := s .D .GetOkExists ("defined_tags" ); ok {
474+ convertedDefinedTags , err := mapToDefinedTags (definedTags .(map [string ]interface {}))
475+ if err != nil {
476+ return err
477+ }
478+ details .DefinedTags = convertedDefinedTags
479+ }
480+ if displayName , ok := s .D .GetOkExists ("display_name" ); ok {
481+ tmp := displayName .(string )
482+ details .DisplayName = & tmp
483+ }
484+ if freeformTags , ok := s .D .GetOkExists ("freeform_tags" ); ok {
485+ details .FreeformTags = objectMapToStringMap (freeformTags .(map [string ]interface {}))
486+ }
487+ if licenseModel , ok := s .D .GetOkExists ("license_model" ); ok {
488+ details .LicenseModel = oci_database .CreateAutonomousDatabaseBaseLicenseModelEnum (licenseModel .(string ))
489+ }
490+ request .CreateAutonomousDatabaseDetails = details
491+ case strings .ToLower ("NONE" ):
492+ details := oci_database.CreateAutonomousDatabaseDetails {}
493+ if adminPassword , ok := s .D .GetOkExists ("admin_password" ); ok {
494+ tmp := adminPassword .(string )
495+ details .AdminPassword = & tmp
496+ }
497+ if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
498+ tmp := compartmentId .(string )
499+ details .CompartmentId = & tmp
500+ }
501+ if cpuCoreCount , ok := s .D .GetOkExists ("cpu_core_count" ); ok {
502+ tmp := cpuCoreCount .(int )
503+ details .CpuCoreCount = & tmp
504+ }
505+ if dataStorageSizeInTBs , ok := s .D .GetOkExists ("data_storage_size_in_tbs" ); ok {
506+ tmp := dataStorageSizeInTBs .(int )
507+ details .DataStorageSizeInTBs = & tmp
508+ }
509+ if dbName , ok := s .D .GetOkExists ("db_name" ); ok {
510+ tmp := dbName .(string )
511+ details .DbName = & tmp
512+ }
513+ if dbWorkload , ok := s .D .GetOkExists ("db_workload" ); ok {
514+ details .DbWorkload = oci_database .CreateAutonomousDatabaseBaseDbWorkloadEnum (dbWorkload .(string ))
515+ }
516+ if definedTags , ok := s .D .GetOkExists ("defined_tags" ); ok {
517+ convertedDefinedTags , err := mapToDefinedTags (definedTags .(map [string ]interface {}))
518+ if err != nil {
519+ return err
520+ }
521+ details .DefinedTags = convertedDefinedTags
522+ }
523+ if displayName , ok := s .D .GetOkExists ("display_name" ); ok {
524+ tmp := displayName .(string )
525+ details .DisplayName = & tmp
526+ }
527+ if freeformTags , ok := s .D .GetOkExists ("freeform_tags" ); ok {
528+ details .FreeformTags = objectMapToStringMap (freeformTags .(map [string ]interface {}))
529+ }
530+ if licenseModel , ok := s .D .GetOkExists ("license_model" ); ok {
531+ details .LicenseModel = oci_database .CreateAutonomousDatabaseBaseLicenseModelEnum (licenseModel .(string ))
532+ }
533+ request .CreateAutonomousDatabaseDetails = details
534+ default :
535+ return fmt .Errorf ("unknown source '%v' was specified" , source )
536+ }
537+ return nil
538+ }
0 commit comments