Skip to content

Commit 857b327

Browse files
ikuzevanMaxrovr
authored andcommitted
Added - Support for ADB-S: Customer Managed Keys via Azure Key Vault and AWS KMS
1 parent 46b76f7 commit 857b327

13 files changed

+933
-16
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "user_ocid" {
8+
}
9+
10+
variable "fingerprint" {
11+
}
12+
13+
variable "private_key_path" {
14+
}
15+
16+
variable "region" {
17+
}
18+
19+
variable "compartment_ocid" {
20+
}
21+
22+
provider "oci" {
23+
tenancy_ocid = var.tenancy_ocid
24+
user_ocid = var.user_ocid
25+
fingerprint = var.fingerprint
26+
private_key_path = var.private_key_path
27+
region = var.region
28+
}
29+
30+
resource "oci_database_autonomous_database" "test_autonomous_database" {
31+
admin_password = "BEstrO0ng_#11"
32+
compartment_id = var.compartment_ocid
33+
cpu_core_count = "1"
34+
data_storage_size_in_tbs = "1"
35+
db_name = "Xsk5djnfdl23423"
36+
db_version = "19c"
37+
db_workload = "AJD"
38+
license_model = "LICENSE_INCLUDED"
39+
encryption_key {
40+
autonomous_database_provider = "ORACLE_MANAGED"
41+
}
42+
}

internal/integrationtest/database_autonomous_database_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ var (
216216
DatabaseAutonomousDatabaseLongTermBackupDelete = map[string]interface{}{
217217
"is_disabled": acctest.Representation{RepType: acctest.Optional, Create: `true`},
218218
}
219-
219+
DatabaseAutonomousDatabaseEncryptionKeyRepresentation = map[string]interface{}{
220+
"kms_key_id": acctest.Representation{RepType: acctest.Required, Update: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
221+
"vault_id": acctest.Representation{RepType: acctest.Required, Update: kmsVaultId},
222+
"autonomous_database_provider": acctest.Representation{RepType: acctest.Required, Update: `OCI`},
223+
}
220224
DatabaseAutonomousDatabaseResourcePoolSummaryRepresentation = map[string]interface{}{
221225
"is_disabled": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
222226
"pool_size": acctest.Representation{RepType: acctest.Optional, Create: `128`, Update: `256`},
@@ -1623,6 +1627,50 @@ func TestDatabaseAutonomousDatabaseResource_basic(t *testing.T) {
16231627
},
16241628
),
16251629
},
1630+
//36. Remove any previously created resources
1631+
{
1632+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies,
1633+
},
1634+
//37. Create ADB using default Oracle Managed key
1635+
{
1636+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
1637+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Required, acctest.Create, DatabaseAutonomousDatabaseRepresentation),
1638+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
1639+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
1640+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
1641+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
1642+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
1643+
// verify computed field db_workload to be defaulted to OLTP
1644+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
1645+
resource.TestCheckResourceAttr(resourceName, "encryption_key.#", "1"),
1646+
resource.TestCheckResourceAttr(resourceName, "encryption_key.0.autonomous_database_provider", "ORACLE_MANAGED"),
1647+
1648+
func(s *terraform.State) (err error) {
1649+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
1650+
return err
1651+
},
1652+
),
1653+
},
1654+
//38. Update ADB using encryptionKey
1655+
{
1656+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
1657+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Required, acctest.Update,
1658+
acctest.RepresentationCopyWithRemovedProperties(acctest.RepresentationCopyWithNewProperties(DatabaseAutonomousDatabaseRepresentation, map[string]interface{}{
1659+
"encryption_key": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseEncryptionKeyRepresentation},
1660+
}), []string{"admin_password"})),
1661+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
1662+
resource.TestCheckResourceAttr(resourceName, "encryption_key.#", "1"),
1663+
resource.TestCheckResourceAttr(resourceName, "encryption_key.0.autonomous_database_provider", "OCI"),
1664+
resource.TestCheckResourceAttrSet(resourceName, "encryption_key.0.kms_key_id"),
1665+
resource.TestCheckResourceAttrSet(resourceName, "encryption_key.0.vault_id"),
1666+
1667+
func(s *terraform.State) (err error) {
1668+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
1669+
fmt.Println(resId)
1670+
return err
1671+
},
1672+
),
1673+
},
16261674
})
16271675
}
16281676

internal/service/database/database_autonomous_database_data_source.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ func (s *DatabaseAutonomousDatabaseDataSourceCrud) SetData() error {
201201
s.D.Set("display_name", *s.Res.DisplayName)
202202
}
203203

204+
if s.Res.EncryptionKey != nil {
205+
encryptionKeyArray := []interface{}{}
206+
if encryptionKeyMap := AutonomousDatabaseEncryptionKeyDetailsToMap(&s.Res.EncryptionKey); encryptionKeyMap != nil {
207+
encryptionKeyArray = append(encryptionKeyArray, encryptionKeyMap)
208+
}
209+
s.D.Set("encryption_key", encryptionKeyArray)
210+
} else {
211+
s.D.Set("encryption_key", nil)
212+
}
213+
214+
encryptionKeyHistoryEntry := []interface{}{}
215+
for _, item := range s.Res.EncryptionKeyHistoryEntry {
216+
encryptionKeyHistoryEntry = append(encryptionKeyHistoryEntry, AutonomousDatabaseEncryptionKeyHistoryEntryToMap(item))
217+
}
218+
s.D.Set("encryption_key_history_entry", encryptionKeyHistoryEntry)
219+
204220
if s.Res.FailedDataRecoveryInSeconds != nil {
205221
s.D.Set("failed_data_recovery_in_seconds", *s.Res.FailedDataRecoveryInSeconds)
206222
}

0 commit comments

Comments
 (0)