@@ -6,10 +6,12 @@ import (
66 "context"
77 "fmt"
88 "strings"
9+ "time"
910
1011 "github.com/hashicorp/terraform/helper/schema"
1112 "github.com/hashicorp/terraform/helper/validation"
1213
14+ oci_common "github.com/oracle/oci-go-sdk/common"
1315 oci_database "github.com/oracle/oci-go-sdk/database"
1416 oci_work_requests "github.com/oracle/oci-go-sdk/workrequests"
1517)
@@ -60,6 +62,18 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
6062 Computed : true ,
6163 ForceNew : true ,
6264 },
65+ "autonomous_database_backup_id" : {
66+ Type : schema .TypeString ,
67+ Optional : true ,
68+ Computed : true ,
69+ ForceNew : true ,
70+ },
71+ "autonomous_database_id" : {
72+ Type : schema .TypeString ,
73+ Optional : true ,
74+ Computed : true ,
75+ ForceNew : true ,
76+ },
6377 "clone_type" : {
6478 Type : schema .TypeString ,
6579 Optional : true ,
@@ -134,6 +148,8 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
134148 ForceNew : true ,
135149 DiffSuppressFunc : EqualIgnoreCaseSuppressDiff ,
136150 ValidateFunc : validation .StringInSlice ([]string {
151+ "BACKUP_FROM_ID" ,
152+ "BACKUP_FROM_TIMESTAMP" ,
137153 "DATABASE" ,
138154 "NONE" ,
139155 }, true ),
@@ -144,6 +160,13 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
144160 Computed : true ,
145161 ForceNew : true ,
146162 },
163+ "timestamp" : {
164+ Type : schema .TypeString ,
165+ Optional : true ,
166+ Computed : true ,
167+ ForceNew : true ,
168+ DiffSuppressFunc : timeDiffSuppressFunction ,
169+ },
147170 "whitelisted_ips" : {
148171 Type : schema .TypeList ,
149172 Optional : true ,
@@ -687,6 +710,177 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
687710 source = "NONE" // default value
688711 }
689712 switch strings .ToLower (source ) {
713+ case strings .ToLower ("BACKUP_FROM_ID" ):
714+ details := oci_database.CreateAutonomousDatabaseFromBackupDetails {}
715+ if autonomousDatabaseBackupId , ok := s .D .GetOkExists ("autonomous_database_backup_id" ); ok {
716+ tmp := autonomousDatabaseBackupId .(string )
717+ details .AutonomousDatabaseBackupId = & tmp
718+ }
719+ if cloneType , ok := s .D .GetOkExists ("clone_type" ); ok {
720+ details .CloneType = oci_database .CreateAutonomousDatabaseFromBackupDetailsCloneTypeEnum (cloneType .(string ))
721+ }
722+ if adminPassword , ok := s .D .GetOkExists ("admin_password" ); ok {
723+ tmp := adminPassword .(string )
724+ details .AdminPassword = & tmp
725+ }
726+ if autonomousContainerDatabaseId , ok := s .D .GetOkExists ("autonomous_container_database_id" ); ok {
727+ tmp := autonomousContainerDatabaseId .(string )
728+ details .AutonomousContainerDatabaseId = & tmp
729+ }
730+ if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
731+ tmp := compartmentId .(string )
732+ details .CompartmentId = & tmp
733+ }
734+ if cpuCoreCount , ok := s .D .GetOkExists ("cpu_core_count" ); ok {
735+ tmp := cpuCoreCount .(int )
736+ details .CpuCoreCount = & tmp
737+ }
738+ if dataStorageSizeInTBs , ok := s .D .GetOkExists ("data_storage_size_in_tbs" ); ok {
739+ tmp := dataStorageSizeInTBs .(int )
740+ details .DataStorageSizeInTBs = & tmp
741+ }
742+ if dbName , ok := s .D .GetOkExists ("db_name" ); ok {
743+ tmp := dbName .(string )
744+ details .DbName = & tmp
745+ }
746+ if dbWorkload , ok := s .D .GetOkExists ("db_workload" ); ok {
747+ details .DbWorkload = oci_database .CreateAutonomousDatabaseBaseDbWorkloadEnum (dbWorkload .(string ))
748+ }
749+ if definedTags , ok := s .D .GetOkExists ("defined_tags" ); ok {
750+ convertedDefinedTags , err := mapToDefinedTags (definedTags .(map [string ]interface {}))
751+ if err != nil {
752+ return err
753+ }
754+ details .DefinedTags = convertedDefinedTags
755+ }
756+ if displayName , ok := s .D .GetOkExists ("display_name" ); ok {
757+ tmp := displayName .(string )
758+ details .DisplayName = & tmp
759+ }
760+ if freeformTags , ok := s .D .GetOkExists ("freeform_tags" ); ok {
761+ details .FreeformTags = objectMapToStringMap (freeformTags .(map [string ]interface {}))
762+ }
763+ if isAutoScalingEnabled , ok := s .D .GetOkExists ("is_auto_scaling_enabled" ); ok {
764+ tmp := isAutoScalingEnabled .(bool )
765+ details .IsAutoScalingEnabled = & tmp
766+ }
767+ if isDedicated , ok := s .D .GetOkExists ("is_dedicated" ); ok {
768+ tmp := isDedicated .(bool )
769+ details .IsDedicated = & tmp
770+ }
771+ if isFreeTier , ok := s .D .GetOkExists ("is_free_tier" ); ok {
772+ tmp := isFreeTier .(bool )
773+ details .IsFreeTier = & tmp
774+ }
775+ if isPreviewVersionWithServiceTermsAccepted , ok := s .D .GetOkExists ("is_preview_version_with_service_terms_accepted" ); ok {
776+ tmp := isPreviewVersionWithServiceTermsAccepted .(bool )
777+ details .IsPreviewVersionWithServiceTermsAccepted = & tmp
778+ }
779+ if licenseModel , ok := s .D .GetOkExists ("license_model" ); ok {
780+ details .LicenseModel = oci_database .CreateAutonomousDatabaseBaseLicenseModelEnum (licenseModel .(string ))
781+ }
782+ if whitelistedIps , ok := s .D .GetOkExists ("whitelisted_ips" ); ok {
783+ interfaces := whitelistedIps .([]interface {})
784+ tmp := make ([]string , len (interfaces ))
785+ for i := range interfaces {
786+ if interfaces [i ] != nil {
787+ tmp [i ] = interfaces [i ].(string )
788+ }
789+ }
790+ if len (tmp ) != 0 || s .D .HasChange ("whitelisted_ips" ) {
791+ details .WhitelistedIps = tmp
792+ }
793+ }
794+ request .CreateAutonomousDatabaseDetails = details
795+ case strings .ToLower ("BACKUP_FROM_TIMESTAMP" ):
796+ details := oci_database.CreateAutonomousDatabaseFromBackupTimestampDetails {}
797+ if autonomousDatabaseId , ok := s .D .GetOkExists ("autonomous_database_id" ); ok {
798+ tmp := autonomousDatabaseId .(string )
799+ details .AutonomousDatabaseId = & tmp
800+ }
801+ if cloneType , ok := s .D .GetOkExists ("clone_type" ); ok {
802+ details .CloneType = oci_database .CreateAutonomousDatabaseFromBackupTimestampDetailsCloneTypeEnum (cloneType .(string ))
803+ }
804+ if timestamp , ok := s .D .GetOkExists ("timestamp" ); ok {
805+ tmp , err := time .Parse (time .RFC3339 , timestamp .(string ))
806+ if err != nil {
807+ return err
808+ }
809+ details .Timestamp = & oci_common.SDKTime {Time : tmp }
810+ }
811+ if adminPassword , ok := s .D .GetOkExists ("admin_password" ); ok {
812+ tmp := adminPassword .(string )
813+ details .AdminPassword = & tmp
814+ }
815+ if autonomousContainerDatabaseId , ok := s .D .GetOkExists ("autonomous_container_database_id" ); ok {
816+ tmp := autonomousContainerDatabaseId .(string )
817+ details .AutonomousContainerDatabaseId = & tmp
818+ }
819+ if compartmentId , ok := s .D .GetOkExists ("compartment_id" ); ok {
820+ tmp := compartmentId .(string )
821+ details .CompartmentId = & tmp
822+ }
823+ if cpuCoreCount , ok := s .D .GetOkExists ("cpu_core_count" ); ok {
824+ tmp := cpuCoreCount .(int )
825+ details .CpuCoreCount = & tmp
826+ }
827+ if dataStorageSizeInTBs , ok := s .D .GetOkExists ("data_storage_size_in_tbs" ); ok {
828+ tmp := dataStorageSizeInTBs .(int )
829+ details .DataStorageSizeInTBs = & tmp
830+ }
831+ if dbName , ok := s .D .GetOkExists ("db_name" ); ok {
832+ tmp := dbName .(string )
833+ details .DbName = & tmp
834+ }
835+ if dbWorkload , ok := s .D .GetOkExists ("db_workload" ); ok {
836+ details .DbWorkload = oci_database .CreateAutonomousDatabaseBaseDbWorkloadEnum (dbWorkload .(string ))
837+ }
838+ if definedTags , ok := s .D .GetOkExists ("defined_tags" ); ok {
839+ convertedDefinedTags , err := mapToDefinedTags (definedTags .(map [string ]interface {}))
840+ if err != nil {
841+ return err
842+ }
843+ details .DefinedTags = convertedDefinedTags
844+ }
845+ if displayName , ok := s .D .GetOkExists ("display_name" ); ok {
846+ tmp := displayName .(string )
847+ details .DisplayName = & tmp
848+ }
849+ if freeformTags , ok := s .D .GetOkExists ("freeform_tags" ); ok {
850+ details .FreeformTags = objectMapToStringMap (freeformTags .(map [string ]interface {}))
851+ }
852+ if isAutoScalingEnabled , ok := s .D .GetOkExists ("is_auto_scaling_enabled" ); ok {
853+ tmp := isAutoScalingEnabled .(bool )
854+ details .IsAutoScalingEnabled = & tmp
855+ }
856+ if isDedicated , ok := s .D .GetOkExists ("is_dedicated" ); ok {
857+ tmp := isDedicated .(bool )
858+ details .IsDedicated = & tmp
859+ }
860+ if isFreeTier , ok := s .D .GetOkExists ("is_free_tier" ); ok {
861+ tmp := isFreeTier .(bool )
862+ details .IsFreeTier = & tmp
863+ }
864+ if isPreviewVersionWithServiceTermsAccepted , ok := s .D .GetOkExists ("is_preview_version_with_service_terms_accepted" ); ok {
865+ tmp := isPreviewVersionWithServiceTermsAccepted .(bool )
866+ details .IsPreviewVersionWithServiceTermsAccepted = & tmp
867+ }
868+ if licenseModel , ok := s .D .GetOkExists ("license_model" ); ok {
869+ details .LicenseModel = oci_database .CreateAutonomousDatabaseBaseLicenseModelEnum (licenseModel .(string ))
870+ }
871+ if whitelistedIps , ok := s .D .GetOkExists ("whitelisted_ips" ); ok {
872+ interfaces := whitelistedIps .([]interface {})
873+ tmp := make ([]string , len (interfaces ))
874+ for i := range interfaces {
875+ if interfaces [i ] != nil {
876+ tmp [i ] = interfaces [i ].(string )
877+ }
878+ }
879+ if len (tmp ) != 0 || s .D .HasChange ("whitelisted_ips" ) {
880+ details .WhitelistedIps = tmp
881+ }
882+ }
883+ request .CreateAutonomousDatabaseDetails = details
690884 case strings .ToLower ("DATABASE" ):
691885 details := oci_database.CreateAutonomousDatabaseCloneDetails {}
692886 if cloneType , ok := s .D .GetOkExists ("clone_type" ); ok {
0 commit comments