Skip to content

Commit 643286b

Browse files
tonglinNagaRajuPasunuri
authored andcommitted
Added - Support for BYOK for ADB-D
1 parent fb99ead commit 643286b

8 files changed

+225
-8
lines changed

internal/integrationtest/database_autonomous_container_database_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,48 @@ func TestDatabaseAutonomousContainerDatabaseResource_basic(t *testing.T) {
365365
},
366366
),
367367
},
368+
//verify rotate key
369+
{
370+
Config: config + compartmentIdVariableStr + ATPDAutonomousContainerDatabaseResourceDependencies +
371+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_container_database", "test_autonomous_container_database", acctest.Optional, acctest.Update,
372+
acctest.RepresentationCopyWithNewProperties(AutonomousContainerDatabaseDedicatedRepresentation, map[string]interface{}{
373+
"rotate_key_trigger": acctest.Representation{RepType: acctest.Optional, Create: `true`},
374+
"key_version_id": acctest.Representation{RepType: acctest.Optional, Create: `1`},
375+
})),
376+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
377+
resource.TestCheckResourceAttrSet(resourceName, "cloud_autonomous_vm_cluster_id"),
378+
resource.TestCheckResourceAttr(resourceName, "backup_config.#", "1"),
379+
resource.TestCheckResourceAttr(resourceName, "backup_config.0.recovery_window_in_days", "11"),
380+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
381+
resource.TestCheckResourceAttr(resourceName, "db_split_threshold", "12"),
382+
resource.TestCheckResourceAttr(resourceName, "distribution_affinity", "MINIMUM_DISTRIBUTION"),
383+
resource.TestCheckResourceAttrSet(resourceName, "db_version"),
384+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
385+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
386+
resource.TestCheckResourceAttrSet(resourceName, "id"),
387+
resource.TestCheckResourceAttr(resourceName, "is_automatic_failover_enabled", "false"),
388+
resource.TestCheckResourceAttr(resourceName, "is_dst_file_update_enabled", "true"),
389+
resource.TestCheckResourceAttrSet(resourceName, "kms_key_id"),
390+
resource.TestCheckResourceAttr(resourceName, "net_services_architecture", "DEDICATED"),
391+
resource.TestCheckResourceAttr(resourceName, "patch_model", "RELEASE_UPDATE_REVISIONS"),
392+
resource.TestCheckResourceAttr(resourceName, "service_level_agreement_type", "STANDARD"),
393+
resource.TestCheckResourceAttrSet(resourceName, "state"),
394+
resource.TestCheckResourceAttrSet(resourceName, "vault_id"),
395+
resource.TestCheckResourceAttr(resourceName, "version_preference", "NEXT_RELEASE_UPDATE"),
396+
resource.TestCheckResourceAttr(resourceName, "vm_failover_reservation", "25"),
397+
resource.TestCheckResourceAttr(resourceName, "db_name", "DBNAME"),
398+
resource.TestCheckResourceAttr(resourceName, "key_version_id", "1"),
399+
400+
func(s *terraform.State) (err error) {
401+
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
402+
if resId != resId2 {
403+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
404+
}
405+
return err
406+
},
407+
),
408+
},
409+
368410
//verify datasource
369411
{
370412
Config: config +
@@ -521,6 +563,7 @@ func TestDatabaseAutonomousContainerDatabaseResource_basic(t *testing.T) {
521563
"database_software_image_id",
522564
"is_automatic_failover_enabled",
523565
"rotate_key_trigger",
566+
"key_version_id",
524567
"maintenance_window_details",
525568
"peer_autonomous_container_database_backup_config",
526569
"peer_autonomous_container_database_compartment_id",

internal/integrationtest/database_autonomous_database_resource_test.go

Lines changed: 146 additions & 8 deletions
Large diffs are not rendered by default.

internal/service/database/database_autonomous_container_database_resource.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ func DatabaseAutonomousContainerDatabaseResource() *schema.Resource {
632632
Type: schema.TypeInt,
633633
Computed: true,
634634
},
635+
"key_version_id": {
636+
Type: schema.TypeString,
637+
Optional: true,
638+
},
635639
"next_maintenance_run_id": {
636640
Type: schema.TypeString,
637641
Computed: true,
@@ -729,6 +733,13 @@ func updateDatabaseAutonomousContainerDatabase(d *schema.ResourceData, m interfa
729733
}
730734
}
731735

736+
if _, ok := sync.D.GetOkExists("key_version_id"); ok && sync.D.HasChange("key_version_id") {
737+
err := sync.RotateContainerDatabaseEncryptionKey()
738+
if err != nil {
739+
return err
740+
}
741+
}
742+
732743
return tfresource.UpdateResource(d, sync)
733744
}
734745

@@ -1631,6 +1642,11 @@ func (s *DatabaseAutonomousContainerDatabaseResourceCrud) RotateContainerDatabas
16311642
return fmt.Errorf("Container database is not dedicated")
16321643
}
16331644

1645+
if keyVersionId, ok := s.D.GetOkExists("key_version_id"); ok {
1646+
tmp := keyVersionId.(string)
1647+
request.KeyVersionId = &tmp
1648+
}
1649+
16341650
tmp := s.D.Id()
16351651
request.AutonomousContainerDatabaseId = &tmp
16361652

internal/service/database/database_autonomous_database_resource.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
702702
Type: schema.TypeString,
703703
Computed: true,
704704
},
705+
"key_version_id": {
706+
Type: schema.TypeString,
707+
Optional: true,
708+
},
705709
"available_upgrade_versions": {
706710
Type: schema.TypeList,
707711
Computed: true,
@@ -1581,6 +1585,13 @@ func updateDatabaseAutonomousDatabase(d *schema.ResourceData, m interface{}) err
15811585
}
15821586
}
15831587

1588+
if _, ok := sync.D.GetOkExists("key_version_id"); ok && sync.D.HasChange("key_version_id") {
1589+
err := sync.RotateAutonomousDatabaseEncryptionKey()
1590+
if err != nil {
1591+
return err
1592+
}
1593+
}
1594+
15841595
if err := tfresource.UpdateResource(d, sync); err != nil {
15851596
return err
15861597
}
@@ -6242,6 +6253,11 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) RotateAutonomousDatabaseEncrypt
62426253
return fmt.Errorf("Autonomous database is not dedicated")
62436254
}
62446255

6256+
if keyVersionId, ok := s.D.GetOkExists("key_version_id"); ok {
6257+
tmp := keyVersionId.(string)
6258+
request.KeyVersionId = &tmp
6259+
}
6260+
62456261
tmp := s.D.Id()
62466262
request.AutonomousDatabaseId = &tmp
62476263

website/docs/d/database_autonomous_container_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ The following attributes are exported:
6767
* `vault_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the Oracle Cloud Infrastructure [vault](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm#concepts). This parameter and `secretId` are required for Customer Managed Keys.
6868
* `key_store_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store of Oracle Vault.
6969
* `key_store_wallet_name` - The wallet name for Oracle Key Vault.
70+
* `key_version_id` - (Optional) The OCID of the key version that is used in rotate key operations.
7071
* `kms_key_id` - The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
7172
* `kms_key_version_id` - The OCID of the key container version that is used in database transparent data encryption (TDE) operations KMS Key can have multiple key versions. If none is specified, the current key version (latest) of the Key Id is used for the operation. Autonomous Database Serverless does not use key versions, hence is not applicable for Autonomous Database Serverless instances.
7273
* `largest_provisionable_autonomous_database_in_cpus` - The largest Autonomous Database (CPU) that can be created in a new Autonomous Container Database.

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ The following attributes are exported:
183183
* `vault_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the Oracle Cloud Infrastructure [vault](https://docs.cloud.oracle.com/iaas/Content/KeyManagement/Concepts/keyoverview.htm#concepts).
184184
* `key_store_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store.
185185
* `key_store_wallet_name` - The wallet name for Oracle Key Vault.
186+
* `key_version_id` - (Optional) The OCID of the key version that is used in rotate key operations.
186187
* `kms_key_id` - The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
187188
* `kms_key_lifecycle_details` - KMS key lifecycle details.
188189
* `kms_key_version_id` - The OCID of the key container version that is used in database transparent data encryption (TDE) operations KMS Key can have multiple key versions. If none is specified, the current key version (latest) of the Key Id is used for the operation.

website/docs/r/database_autonomous_container_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ The following arguments are supported:
139139
* `is_dst_file_update_enabled` - (Optional) (Updatable) Indicates if an automatic DST Time Zone file update is enabled for the Autonomous Container Database. If enabled along with Release Update, patching will be done in a Non-Rolling manner.
140140
* `is_automatic_failover_enabled` - (Optional) Indicates whether Automatic Failover is enabled for Autonomous Container Database Dataguard Association. Input DataType: boolean. Example : is_automatic_failover_enabled = true.
141141
* `key_store_id` - (Optional) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store.
142+
* `key_version_id` - (Optional) The OCID of the key version that is used in rotate key operations.
142143
* `kms_key_id` - (Optional) The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
143144
* `maintenance_window_details` - (Optional) (Updatable) The scheduling details for the quarterly maintenance window. Patching and system updates take place during the maintenance window.
144145
* `custom_action_timeout_in_mins` - (Optional) (Updatable) Determines the amount of time the system will wait before the start of each database server patching operation. Custom action timeout is in minutes and valid value is between 15 to 120 (inclusive).

website/docs/r/database_autonomous_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ The following arguments are supported:
236236
* `is_preview_version_with_service_terms_accepted` - (Optional) If set to `TRUE`, indicates that an Autonomous Database preview version is being provisioned, and that the preview version's terms of service have been accepted. Note that preview version software is only available for Autonomous Database Serverless instances (https://docs.oracle.com/en/cloud/paas/autonomous-database/serverless/).
237237
* `is_replicate_automatic_backups` - (Applicable when source=CROSS_REGION_DISASTER_RECOVERY) If true, 7 days worth of backups are replicated across regions for Cross-Region ADB or Backup-Based DR between Primary and Standby. If false, the backups taken on the Primary are not replicated to the Standby database.
238238
* `kms_key_id` - (Optional) The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
239+
* `key_version_id` - (Optional) The OCID of the key version that is used in rotate key operations.
239240
* `license_model` - (Optional) (Updatable) The Oracle license model that applies to the Oracle Autonomous Database. Bring your own license (BYOL) allows you to apply your current on-premises Oracle software licenses to equivalent, highly automated Oracle services in the cloud. License Included allows you to subscribe to new Oracle Database software licenses and the Oracle Database service. Note that when provisioning an [Autonomous Database on dedicated Exadata infrastructure](https://docs.oracle.com/en/cloud/paas/autonomous-database/index.html), this attribute must be null. It is already set at the Autonomous Exadata Infrastructure level. When provisioning an [Autonomous Database Serverless] (https://docs.oracle.com/en/cloud/paas/autonomous-database/index.html) database, if a value is not specified, the system defaults the value to `BRING_YOUR_OWN_LICENSE`. Bring your own license (BYOL) also allows you to select the DB edition using the optional parameter.
240241
* `is_auto_scaling_for_storage_enabled` - (Optional) (Updatable) Indicates if auto scaling is enabled for the Autonomous Database storage. The default value is `FALSE`.
241242
* `is_dedicated` - (Optional) True if the database is on [dedicated Exadata infrastructure](https://docs.cloud.oracle.com/iaas/Content/Database/Concepts/adbddoverview.htm).

0 commit comments

Comments
 (0)