Skip to content

Commit f3b2973

Browse files
committed
- Added - Support for Data Guard Protection Modes
1 parent f4ee1c1 commit f3b2973

File tree

3 files changed

+79
-19
lines changed

3 files changed

+79
-19
lines changed

oci/database_data_guard_association_resource.go

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func DatabaseDataGuardAssociationResource() *schema.Resource {
4949
"database_admin_password": {
5050
Type: schema.TypeString,
5151
Required: true,
52-
ForceNew: true,
5352
Sensitive: true,
5453
},
5554
"database_id": {
@@ -64,12 +63,10 @@ func DatabaseDataGuardAssociationResource() *schema.Resource {
6463
"protection_mode": {
6564
Type: schema.TypeString,
6665
Required: true,
67-
ForceNew: true,
6866
},
6967
"transport_type": {
7068
Type: schema.TypeString,
7169
Required: true,
72-
ForceNew: true,
7370
},
7471

7572
// Optional
@@ -208,6 +205,14 @@ func readDatabaseDataGuardAssociation(d *schema.ResourceData, m interface{}) err
208205
return ReadResource(sync)
209206
}
210207

208+
func updateDatabaseDataGuardAssociation(d *schema.ResourceData, m interface{}) error {
209+
sync := &DatabaseDataGuardAssociationResourceCrud{}
210+
sync.D = d
211+
sync.Client = m.(*OracleClients).databaseClient()
212+
213+
return UpdateResource(d, sync)
214+
}
215+
211216
func deleteDatabaseDataGuardAssociation(d *schema.ResourceData, m interface{}) error {
212217
sync := &DatabaseDataGuardAssociationResourceCrud{}
213218
sync.D = d
@@ -301,6 +306,41 @@ func (s *DatabaseDataGuardAssociationResourceCrud) Get() error {
301306
return nil
302307
}
303308

309+
func (s *DatabaseDataGuardAssociationResourceCrud) Update() error {
310+
request := oci_database.UpdateDataGuardAssociationRequest{}
311+
312+
tmp := s.D.Id()
313+
request.DataGuardAssociationId = &tmp
314+
315+
if databaseAdminPassword, ok := s.D.GetOkExists("database_admin_password"); ok {
316+
tmp := databaseAdminPassword.(string)
317+
request.DatabaseAdminPassword = &tmp
318+
}
319+
320+
if databaseId, ok := s.D.GetOkExists("database_id"); ok {
321+
tmp := databaseId.(string)
322+
request.DatabaseId = &tmp
323+
}
324+
325+
if protectionMode, ok := s.D.GetOkExists("protection_mode"); ok {
326+
request.ProtectionMode = oci_database.UpdateDataGuardAssociationDetailsProtectionModeEnum(protectionMode.(string))
327+
}
328+
329+
if transportType, ok := s.D.GetOkExists("transport_type"); ok {
330+
request.TransportType = oci_database.UpdateDataGuardAssociationDetailsTransportTypeEnum(transportType.(string))
331+
}
332+
333+
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "database")
334+
335+
response, err := s.Client.UpdateDataGuardAssociation(context.Background(), request)
336+
if err != nil {
337+
return err
338+
}
339+
340+
s.Res = &response.DataGuardAssociation
341+
return nil
342+
}
343+
304344
func (s *DatabaseDataGuardAssociationResourceCrud) SetData() error {
305345

306346
if backupNetworkNsgIds, ok := s.D.GetOkExists("backup_network_nsg_ids"); ok {
@@ -505,10 +545,6 @@ func (s *DatabaseDataGuardAssociationResourceCrud) populateTopLevelPolymorphicCr
505545
return nil
506546
}
507547

508-
func (s *DatabaseDataGuardAssociationResourceCrud) Update() error {
509-
return s.Get()
510-
}
511-
512548
func (s *DatabaseDataGuardAssociationResourceCrud) Delete() error {
513549
if deleteStandbyDbHomeOnDelete, ok := s.D.GetOkExists("delete_standby_db_home_on_delete"); ok {
514550
tmp := deleteStandbyDbHomeOnDelete.(string)
@@ -631,14 +667,6 @@ func (s *DatabaseDataGuardAssociationResourceCrud) Delete() error {
631667
return fmt.Errorf("unrecognized creation_type during delete")
632668
}
633669

634-
func updateDatabaseDataGuardAssociation(d *schema.ResourceData, m interface{}) error {
635-
sync := &DatabaseDataGuardAssociationResourceCrud{}
636-
sync.D = d
637-
sync.Client = m.(*OracleClients).databaseClient()
638-
639-
return UpdateResource(d, sync)
640-
}
641-
642670
func (s *DatabaseDataGuardAssociationResourceCrud) ExtraWaitPostCreateDelete() time.Duration {
643671
if httpreplay.ShouldRetryImmediately() {
644672
return 10 * time.Millisecond

oci/database_data_guard_association_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func TestDatabaseDataGuardAssociationResource_basic(t *testing.T) {
212212
datasourceName := "data.oci_database_data_guard_associations.test_data_guard_associations"
213213
singularDatasourceName := "data.oci_database_data_guard_association.test_data_guard_association"
214214

215-
var resId string
215+
var resId, resId2 string
216216
// Save TF content to create resource with optional properties. This has to be exactly the same as the config part in the "create with optionals" step in the test.
217217
saveConfigContent(config+compartmentIdVariableStr+DataGuardAssociationResourceDependencies+
218218
generateResourceFromRepresentationMap("oci_database_data_guard_association", "test_data_guard_association", Optional, Create, dataGuardAssociationRepresentationExistingDbSystem), "database", "dataGuardAssociation", t)
@@ -237,6 +237,11 @@ func TestDatabaseDataGuardAssociationResource_basic(t *testing.T) {
237237
resource.TestCheckResourceAttr(resourceName, "protection_mode", "MAXIMUM_PERFORMANCE"),
238238
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard2.1"),
239239
resource.TestCheckResourceAttr(resourceName, "transport_type", "ASYNC"),
240+
241+
func(s *terraform.State) (err error) {
242+
resId, err = fromInstanceState(s, resourceName, "id")
243+
return err
244+
},
240245
),
241246
},
242247

@@ -273,6 +278,33 @@ func TestDatabaseDataGuardAssociationResource_basic(t *testing.T) {
273278
),
274279
},
275280

281+
// verify updates to updatable parameters
282+
{
283+
Config: config + compartmentIdVariableStr + DataGuardAssociationResourceDependencies +
284+
generateResourceFromRepresentationMap("oci_database_data_guard_association", "test_data_guard_association", Optional, Update, dataGuardAssociationRepresentationExistingDbSystem),
285+
Check: resource.ComposeAggregateTestCheckFunc(
286+
resource.TestCheckResourceAttr(resourceName, "creation_type", "ExistingDbSystem"),
287+
resource.TestCheckResourceAttr(resourceName, "database_admin_password", "BEstrO0ng_#11"),
288+
resource.TestCheckResourceAttrSet(resourceName, "database_id"),
289+
resource.TestCheckResourceAttr(resourceName, "delete_standby_db_home_on_delete", "true"),
290+
resource.TestCheckResourceAttrSet(resourceName, "id"),
291+
resource.TestCheckResourceAttrSet(resourceName, "peer_db_home_id"),
292+
resource.TestCheckResourceAttrSet(resourceName, "peer_db_system_id"),
293+
resource.TestCheckResourceAttrSet(resourceName, "peer_role"),
294+
resource.TestCheckResourceAttr(resourceName, "protection_mode", "MAXIMUM_PERFORMANCE"),
295+
resource.TestCheckResourceAttrSet(resourceName, "role"),
296+
resource.TestCheckResourceAttrSet(resourceName, "state"),
297+
resource.TestCheckResourceAttr(resourceName, "transport_type", "ASYNC"),
298+
299+
func(s *terraform.State) (err error) {
300+
resId2, err = fromInstanceState(s, resourceName, "id")
301+
if resId != resId2 {
302+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
303+
}
304+
return err
305+
},
306+
),
307+
},
276308
// verify datasource
277309
{
278310
Config: config +

website/docs/r/database_data_guard_association.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The following arguments are supported:
5454
* `availability_domain` - (Applicable when creation_type=NewDbSystem) The name of the availability domain that the standby database DB system will be located in. For example- "Uocm:PHX-AD-1".
5555
* `backup_network_nsg_ids` - (Applicable when creation_type=NewDbSystem) A list of the [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the network security groups (NSGs) that the backup network of this DB system belongs to. Setting this to an empty array after the list is created removes the resource from all NSGs. For more information about NSGs, see [Security Rules](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securityrules.htm). Applicable only to Exadata systems.
5656
* `creation_type` - (Required) Specifies whether to create the peer database in an existing DB system or in a new DB system.
57-
* `database_admin_password` - (Required) A strong password for the `SYS`, `SYSTEM`, and `PDB Admin` users to apply during standby creation.
57+
* `database_admin_password` - (Required) (Updatable) A strong password for the `SYS`, `SYSTEM`, and `PDB Admin` users to apply during standby creation.
5858

5959
The password must contain no fewer than nine characters and include:
6060
* At least two uppercase characters.
@@ -73,7 +73,7 @@ The following arguments are supported:
7373
* `peer_db_home_id` - (Applicable when creation_type=ExistingDbSystem | ExistingVmCluster) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the DB home in which to create the standby database. You must supply this value to create standby database with an existing DB home
7474
* `peer_db_system_id` - (Applicable when creation_type=ExistingDbSystem) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the DB system in which to create the standby database. You must supply this value if creationType is `ExistingDbSystem`.
7575
* `peer_vm_cluster_id` - (Applicable when creation_type=ExistingVmCluster) The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the VM Cluster in which to create the standby database. You must supply this value if creationType is `ExistingVmCluster`.
76-
* `protection_mode` - (Required) The protection mode to set up between the primary and standby databases. For more information, see [Oracle Data Guard Protection Modes](http://docs.oracle.com/database/122/SBYDB/oracle-data-guard-protection-modes.htm#SBYDB02000) in the Oracle Data Guard documentation.
76+
* `protection_mode` - (Required) (Updatable) The protection mode to set up between the primary and standby databases. For more information, see [Oracle Data Guard Protection Modes](http://docs.oracle.com/database/122/SBYDB/oracle-data-guard-protection-modes.htm#SBYDB02000) in the Oracle Data Guard documentation.
7777

7878
**IMPORTANT** - The only protection mode currently supported by the Database service is MAXIMUM_PERFORMANCE.
7979
* `shape` - (Applicable when creation_type=NewDbSystem) The virtual machine DB system shape to launch for the standby database in the Data Guard association. The shape determines the number of CPU cores and the amount of memory available for the DB system. Only virtual machine shapes are valid options. If you do not supply this parameter, the default shape is the shape of the primary DB system.
@@ -83,7 +83,7 @@ The following arguments are supported:
8383
* For 1- and 2-node RAC DB systems, do not use a subnet that overlaps with 192.168.16.16/28
8484

8585
These subnets are used by the Oracle Clusterware private interconnect on the database instance. Specifying an overlapping subnet will cause the private interconnect to malfunction. This restriction applies to both the client subnet and backup subnet.
86-
* `transport_type` - (Required) The redo transport type to use for this Data Guard association. Valid values depend on the specified `protectionMode`:
86+
* `transport_type` - (Required) (Updatable) The redo transport type to use for this Data Guard association. Valid values depend on the specified `protectionMode`:
8787
* MAXIMUM_AVAILABILITY - SYNC or FASTSYNC
8888
* MAXIMUM_PERFORMANCE - ASYNC
8989
* MAXIMUM_PROTECTION - SYNC

0 commit comments

Comments
 (0)