Skip to content

Commit 0ce604e

Browse files
vijasankMaxrovr
authored andcommitted
Added - Support for Ability to specify tags when adding a standby database or creating a database from backup | ExaDB-D, ExaDB-XS, ExaDB-CC
1 parent dcbc8e4 commit 0ce604e

File tree

9 files changed

+85
-13
lines changed

9 files changed

+85
-13
lines changed

examples/database/multiple_standby/Db1.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ variable "ssh_public_key" {
88
}
99

1010
provider "oci" {
11-
version = "0.0.0"
11+
# version = "0.0.0"
1212
}
1313

1414
data "oci_identity_availability_domains" "ADs" {
@@ -176,6 +176,8 @@ resource "oci_database_database" "primary_database" {
176176
character_set = "AL32UTF8"
177177
ncharacter_set = "AL16UTF16"
178178
db_workload = "OLTP"
179+
defined_tags = map("example-tag-namespace-all.example-tag", "databaseDefinedTags1")
180+
freeform_tags = {"databaseFreeformTagsK" = "databaseFreeformTagsV"}
179181
}
180182

181183
db_home_id = oci_database_db_home.test_db_home.id

examples/database/multiple_standby/Db2.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ resource "oci_database_database" "standby_database" {
158158
protection_mode = "MAXIMUM_PERFORMANCE"
159159
transport_type = "ASYNC"
160160
source_tde_wallet_password = "BEstrO0ng_#11"
161+
defined_tags = map("example-tag-namespace-all.example-tag", "databaseDefinedTags1")
162+
freeform_tags = {"databaseFreeformTagsK" = "databaseFreeformTagsV"}
161163
}
162164

163165
db_home_id = oci_database_db_home.test_db_home2.id

internal/integrationtest/database_database_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ var (
403403
"db_unique_name": acctest.Representation{RepType: acctest.Optional, Create: `iDbTest_77`},
404404
"ncharacter_set": acctest.Representation{RepType: acctest.Optional, Create: `AL16UTF16`},
405405
"sid_prefix": acctest.Representation{RepType: acctest.Optional, Create: `myTestDb`},
406+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]map[string]string{"Oracle-Tags": {"CreatedBy": "definedTags"}}},
407+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"freeformTags": "freeformTags"}},
406408
}
407409

408410
databaseMultipleStandbyDb2Representation = map[string]interface{}{
@@ -414,6 +416,8 @@ var (
414416
"source_tde_wallet_password": acctest.Representation{RepType: acctest.Optional, Create: `BEstrO0ng_#11`},
415417
"protection_mode": acctest.Representation{RepType: acctest.Optional, Create: `MAXIMUM_PERFORMANCE`},
416418
"transport_type": acctest.Representation{RepType: acctest.Optional, Create: `ASYNC`},
419+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]map[string]string{"Oracle-Tags": {"CreatedBy": "definedTags"}}},
420+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"freeformTags": "freeformTags"}},
417421
}
418422

419423
dbHomeHsmRepresentation = map[string]interface{}{
@@ -1074,9 +1078,13 @@ func TestDatabaseDatabaseResource_multipleStandby(t *testing.T) {
10741078
resource.TestCheckResourceAttr(primaryDatabase, "database.0.db_name", "myTestDb"),
10751079
resource.TestCheckResourceAttrSet(primaryDatabase, "db_home_id"),
10761080
resource.TestCheckResourceAttr(primaryDatabase, "source", "NONE"),
1081+
resource.TestCheckResourceAttrSet(primaryDatabase, "defined_tags"),
1082+
resource.TestCheckResourceAttrSet(primaryDatabase, "freeform_tags"),
10771083
resource.TestCheckResourceAttr(standbyDatabase, "database.#", "1"),
10781084
resource.TestCheckResourceAttr(standbyDatabase, "database.0.db_name", "myTestDb"),
10791085
resource.TestCheckResourceAttrSet(standbyDatabase, "db_home_id"),
1086+
resource.TestCheckResourceAttrSet(standbyDatabase, "defined_tags"),
1087+
resource.TestCheckResourceAttrSet(standbyDatabase, "freeform_tags"),
10801088
resource.TestCheckResourceAttr(standbyDatabase, "source", "DATAGUARD"),
10811089
resource.TestCheckResourceAttrSet(standbyDatabase, "data_guard_group.#"),
10821090
resource.TestCheckResourceAttr(standbyDatabase, "data_guard_group.0.protection_mode", "MAXIMUM_PERFORMANCE"),

internal/service/database/database_database_resource.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,18 @@ func (s *DatabaseDatabaseResourceCrud) mapToCreateDatabaseFromBackupDetails(fiel
14191419
result.DbUniqueName = &tmp
14201420
}
14211421

1422+
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
1423+
tmp, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
1424+
if err != nil {
1425+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
1426+
}
1427+
result.DefinedTags = tmp
1428+
}
1429+
1430+
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
1431+
result.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
1432+
}
1433+
14221434
if pluggableDatabases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "pluggable_databases")); ok {
14231435
interfaces := pluggableDatabases.([]interface{})
14241436
tmp := make([]string, len(interfaces))
@@ -1464,6 +1476,18 @@ func (s *DatabaseDatabaseResourceCrud) mapToCreateStandbyDetails(fieldKeyFormat
14641476
result.DbUniqueName = &tmp
14651477
}
14661478

1479+
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
1480+
tmp, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
1481+
if err != nil {
1482+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
1483+
}
1484+
result.DefinedTags = tmp
1485+
}
1486+
1487+
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
1488+
result.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
1489+
}
1490+
14671491
if isActiveDataGuardEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_active_data_guard_enabled")); ok {
14681492
tmp := isActiveDataGuardEnabled.(bool)
14691493
result.IsActiveDataGuardEnabled = &tmp
@@ -2498,6 +2522,11 @@ func adgDiffSuppress(k string, old, new string, d *schema.ResourceData) bool {
24982522
item, ok := member.(map[string]interface{})
24992523
if ok {
25002524
if databaseId, exists := item["database_id"]; exists && databaseId.(string) == d.Id() {
2525+
// To suppress diff on the primary database for the field "is_active_data_guard_enabled" because during
2526+
//role change with the standby (failover/switchover), there is a diff in the primary db if the standby db is created with ADG value as true.
2527+
if dgRoleValue, exists := item["role"]; exists && dgRoleValue.(string) == "PRIMARY" {
2528+
return true
2529+
}
25012530
if fieldValue, exists := item["is_active_data_guard_enabled"]; exists {
25022531
return compareBooleanField(fieldValue, new)
25032532
}

internal/service/database/database_db_home_resource.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,18 @@ func (s *DatabaseDbHomeResourceCrud) mapToCreateDatabaseFromBackupDetails(fieldK
13281328
result.DbUniqueName = &tmp
13291329
}
13301330

1331+
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
1332+
tmp, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
1333+
if err != nil {
1334+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
1335+
}
1336+
result.DefinedTags = tmp
1337+
}
1338+
1339+
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
1340+
result.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
1341+
}
1342+
13311343
if pluggableDatabases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "pluggable_databases")); ok {
13321344
interfaces := pluggableDatabases.([]interface{})
13331345
tmp := make([]string, len(interfaces))

internal/service/database/database_db_system_resource.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,18 @@ func (s *DatabaseDbSystemResourceCrud) mapToCreateDatabaseFromBackupDetails(fiel
18511851
result.DbUniqueName = &tmp
18521852
}
18531853

1854+
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
1855+
tmp, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
1856+
if err != nil {
1857+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
1858+
}
1859+
result.DefinedTags = tmp
1860+
}
1861+
1862+
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
1863+
result.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
1864+
}
1865+
18541866
if pluggableDatabases, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "pluggable_databases")); ok {
18551867
interfaces := pluggableDatabases.([]interface{})
18561868
tmp := make([]string, len(interfaces))
@@ -1895,6 +1907,12 @@ func CreateDatabaseFromBackupDetailsToMap(obj *oci_database.CreateDatabaseFromBa
18951907
result["db_unique_name"] = string(*obj.DbUniqueName)
18961908
}
18971909

1910+
if obj.DefinedTags != nil {
1911+
result["defined_tags"] = tfresource.DefinedTagsToMap(obj.DefinedTags)
1912+
}
1913+
1914+
result["freeform_tags"] = obj.FreeformTags
1915+
18981916
result["pluggable_databases"] = obj.PluggableDatabases
18991917

19001918
return result

website/docs/r/database_database.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ The following arguments are supported:
133133
* `db_workload` - (Applicable when source=NONE) **Deprecated.** The dbWorkload field has been deprecated for Exadata Database Service on Dedicated Infrastructure, Exadata Database Service on Cloud@Customer, and Base Database Service. Support for this attribute will end in November 2023. You may choose to update your custom scripts to exclude the dbWorkload attribute. After November 2023 if you pass a value to the dbWorkload attribute, it will be ignored.
134134

135135
The database workload type.
136-
* `defined_tags` - (Applicable when source=NONE) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
136+
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
137137
* `encryption_key_location_details` - (Applicable when source=NONE) Types of providers supported for managing database encryption keys
138138
* `azure_encryption_key_id` - (Required when provider_type=AZURE) Provide the key OCID of a registered Azure key.
139139
* `hsm_password` - (Required when provider_type=EXTERNAL) Provide the HSM password as you would in RDBMS for External HSM.
140-
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrating a database key to an External HSM. Use 'AZURE' for creating a new database or migrating a database key to Azure.
141-
* `freeform_tags` - (Applicable when source=NONE) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
142-
* `freeform_tags` - (Applicable when source=NONE) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
140+
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrating a database key to an External HSM. Use 'AZURE' for creating a new database or migrating a database key to Azure.
141+
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
142+
* `is_active_data_guard_enabled` - (Applicable when source=DATAGUARD) True if active Data Guard is enabled.
143143
* `key_store_id` - (Applicable when source=NONE) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store of Oracle Vault.
144144
* `is_active_data_guard_enabled` - (Applicable when source=DATAGUARD) True if active Data Guard is enabled.
145145
* `kms_key_id` - (Applicable when source=NONE) The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.

website/docs/r/database_db_home.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ The following arguments are supported:
137137
* `db_workload` - (Applicable when source=NONE | VM_CLUSTER_NEW) **Deprecated.** The dbWorkload field has been deprecated for Exadata Database Service on Dedicated Infrastructure, Exadata Database Service on Cloud@Customer, and Base Database Service. Support for this attribute will end in November 2023. You may choose to update your custom scripts to exclude the dbWorkload attribute. After November 2023 if you pass a value to the dbWorkload attribute, it will be ignored.
138138

139139
The database workload type.
140-
* `defined_tags` - (Applicable when source=NONE | VM_CLUSTER_NEW) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
140+
* `defined_tags` - (Applicable when source=DB_BACKUP | NONE | VM_CLUSTER_BACKUP | VM_CLUSTER_NEW) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
141141
* `encryption_key_location_details` - (Applicable when source=NONE | VM_CLUSTER_NEW) Types of providers supported for managing database encryption keys
142142
* `azure_encryption_key_id` - (Required when provider_type=AZURE) Provide the key OCID of a registered Azure key.
143143
* `hsm_password` - (Required when provider_type=EXTERNAL) Provide the HSM password as you would in RDBMS for External HSM.
144-
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrating a database key to an External HSM. Use 'AZURE' for creating a new database or migrating a database key to Azure.
145-
* `enable_database_delete` - (Optional) Defaults to false. If omitted or set to false the provider will not delete databases removed from the Db Home configuration.
146-
* `freeform_tags` - (Applicable when source=NONE | VM_CLUSTER_NEW) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
144+
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrating a database key to an External HSM. Use 'AZURE' for creating a new database or migrating a database key to Azure.
145+
* `freeform_tags` - (Applicable when source=DB_BACKUP | NONE | VM_CLUSTER_BACKUP | VM_CLUSTER_NEW) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
146+
* `enable_database_delete` - (Optional) Defaults to false. If omitted or set to false the provider will not delete databases removed from the Db Home configuration.
147147
* `key_store_id` - (Applicable when source=NONE | VM_CLUSTER_NEW) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store of Oracle Vault.
148148
* `kms_key_id` - (Applicable when source=NONE | VM_CLUSTER_NEW) The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
149149
* `kms_key_version_id` - (Applicable when source=NONE | VM_CLUSTER_NEW) 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.

website/docs/r/database_db_system.html.markdown

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,12 @@ The following arguments are supported:
234234
* `db_workload` - (Applicable when source=NONE) **Deprecated.** The dbWorkload field has been deprecated for Exadata Database Service on Dedicated Infrastructure, Exadata Database Service on Cloud@Customer, and Base Database Service. Support for this attribute will end in November 2023. You may choose to update your custom scripts to exclude the dbWorkload attribute. After November 2023 if you pass a value to the dbWorkload attribute, it will be ignored.
235235

236236
The database workload type.
237-
* `defined_tags` - (Applicable when source=DB_SYSTEM | NONE) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
237+
* `defined_tags` - (Applicable when source=DB_BACKUP | DB_SYSTEM | NONE) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
238238
* `encryption_key_location_details` - (Applicable when source=NONE) Types of providers supported for managing database encryption keys
239-
* `hsm_password` - (Required) Provide the HSM password as you would in RDBMS for External HSM.
240-
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrate database key with External HSM.
241-
* `freeform_tags` - (Applicable when source=DB_SYSTEM | NONE) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
239+
* `azure_encryption_key_id` - (Required when provider_type=AZURE) Provide the key OCID of a registered Azure key.
240+
* `hsm_password` - (Required when provider_type=EXTERNAL) Provide the HSM password as you would in RDBMS for External HSM.
241+
* `provider_type` - (Required) Use 'EXTERNAL' for creating a new database or migrating a database key to an External HSM. Use 'AZURE' for creating a new database or migrating a database key to Azure.
242+
* `freeform_tags` - (Applicable when source=DB_BACKUP | DB_SYSTEM | NONE) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
242243
* `key_store_id` - (Applicable when source=NONE) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the key store of Oracle Vault.
243244
* `kms_key_id` - (Applicable when source=NONE) The OCID of the key container that is used as the master encryption key in database transparent data encryption (TDE) operations.
244245
* `kms_key_version_id` - (Applicable when source=NONE) 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.

0 commit comments

Comments
 (0)