Skip to content

Commit b9255a4

Browse files
Terraform Team AutomationjiaqchenO
authored andcommitted
Added - Support subscriptionId attribute for Autonomous Recovery Service (ZRCV)
1 parent 2140a02 commit b9255a4

14 files changed

+111
-5
lines changed

examples/recovery/protected_database/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ variable "protection_policy_id" {
6363
default = "ocid1.recoveryservicepolicy.region1..aaaaaaaam22xkw32t524xvst7dbxz4qsxtwetmfnnxfsgslbq664vya5jbkq"
6464
}
6565

66+
variable "subscription_id" {
67+
default = null
68+
}
69+
6670
resource "oci_recovery_protected_database" "test_protected_database" {
6771
#Required
6872
compartment_id = var.compartment_id
@@ -79,8 +83,9 @@ resource "oci_recovery_protected_database" "test_protected_database" {
7983
database_id = var.database_id
8084
deletion_schedule = "DELETE_AFTER_72_HOURS"
8185
database_size = var.protected_database_database_size
82-
freeform_tags = var.protected_database_freeform_tags
8386
is_redo_logs_shipped = var.protected_database_is_redo_logs_shipped
87+
subscription_id = var.subscription_id
88+
freeform_tags = var.protected_database_freeform_tags
8489
}
8590

8691
data "oci_recovery_protected_databases" "test_protected_databases" {

examples/recovery/protection_policy/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ variable "protection_policy_policy_locked_date_time" {
4040
default = "2025-01-01T00:00:00.000Z"
4141
}
4242

43+
variable "must_enforce_cloud_locality" {
44+
default = false
45+
}
4346

4447
resource "oci_recovery_protection_policy" "test_protection_policy" {
4548
#Required
@@ -49,6 +52,7 @@ resource "oci_recovery_protection_policy" "test_protection_policy" {
4952

5053
#Optional
5154
policy_locked_date_time = var.protection_policy_policy_locked_date_time
55+
must_enforce_cloud_locality = var.must_enforce_cloud_locality
5256
freeform_tags = var.protection_policy_freeform_tags
5357
}
5458

internal/integrationtest/recovery_protected_database_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ var (
6161
"deletion_schedule": acctest.Representation{RepType: acctest.Optional, Create: `DELETE_AFTER_72_HOURS`},
6262
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
6363
"is_redo_logs_shipped": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
64+
"subscription_id": acctest.Representation{RepType: acctest.Optional, Create: `ocid1.organizationssubscription.oc1..amaaaaaa6jqx4paaa2rxk42owtrtvwkhauvoqb2equbymlvdrlv5tclvvvta`, Update: `ocid1.organizationssubscription.oc1..amaaaaaa6jqx4paaa2rxk42owtrtvwkhauvoqb2equbymlvdrlv5tclvvita`},
6465
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: recoveryIgnoreDefinedTagsRepresentation},
6566
}
66-
recoveryIgnoreDefinedTagsRepresentation = map[string]interface{}{
67-
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{`defined_tags`}},
68-
}
69-
7067
RecoveryProtectedDatabaseRecoveryServiceSubnetsRepresentation = map[string]interface{}{
7168
"recovery_service_subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_recovery_recovery_service_subnet.test_recovery_service_subnet.id}`},
7269
}
@@ -96,6 +93,10 @@ var (
9693
recoveryProtectionPolicyDependency +
9794
AvailabilityDomainConfig +
9895
DefinedTagsDependencies
96+
97+
recoveryIgnoreDefinedTagsRepresentation = map[string]interface{}{
98+
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{`defined_tags`}},
99+
}
99100
)
100101

101102
// issue-routing-tag: recovery/default
@@ -163,6 +164,7 @@ func TestRecoveryProtectedDatabaseResource_basic(t *testing.T) {
163164
resource.TestCheckResourceAttrSet(resourceName, "protection_policy_id"),
164165
resource.TestCheckResourceAttr(resourceName, "recovery_service_subnets.#", "1"),
165166
resource.TestCheckResourceAttrSet(resourceName, "recovery_service_subnets.0.recovery_service_subnet_id"),
167+
resource.TestCheckResourceAttrSet(resourceName, "subscription_id"),
166168
resource.TestCheckResourceAttrSet(resourceName, "vpc_user_name"),
167169

168170
func(s *terraform.State) (err error) {
@@ -198,6 +200,7 @@ func TestRecoveryProtectedDatabaseResource_basic(t *testing.T) {
198200
resource.TestCheckResourceAttrSet(resourceName, "protection_policy_id"),
199201
resource.TestCheckResourceAttr(resourceName, "recovery_service_subnets.#", "1"),
200202
resource.TestCheckResourceAttrSet(resourceName, "recovery_service_subnets.0.recovery_service_subnet_id"),
203+
resource.TestCheckResourceAttrSet(resourceName, "subscription_id"),
201204
resource.TestCheckResourceAttrSet(resourceName, "vpc_user_name"),
202205

203206
func(s *terraform.State) (err error) {
@@ -228,6 +231,7 @@ func TestRecoveryProtectedDatabaseResource_basic(t *testing.T) {
228231
resource.TestCheckResourceAttrSet(resourceName, "protection_policy_id"),
229232
resource.TestCheckResourceAttr(resourceName, "recovery_service_subnets.#", "1"),
230233
resource.TestCheckResourceAttrSet(resourceName, "recovery_service_subnets.0.recovery_service_subnet_id"),
234+
resource.TestCheckResourceAttrSet(resourceName, "subscription_id"),
231235
resource.TestCheckResourceAttrSet(resourceName, "vpc_user_name"),
232236

233237
func(s *terraform.State) (err error) {

internal/integrationtest/recovery_protection_policy_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
"display_name": acctest.Representation{RepType: acctest.Required, Create: `displayName`, Update: `displayName2`},
5858
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
5959
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},
60+
"must_enforce_cloud_locality": acctest.Representation{RepType: acctest.Optional, Create: `false`},
6061
"policy_locked_date_time": acctest.Representation{RepType: acctest.Optional, Create: recoveryProtectionPolicyRepresentationPolicyLockedDateTimeCreate, Update: recoveryProtectionPolicyRepresentationPolicyLockedDateTimeUpdate},
6162
"lifecycle": acctest.RepresentationGroup{RepType: acctest.Required, Group: recoveryIgnoreDefinedTagsRepresentation},
6263
}
@@ -118,6 +119,7 @@ func TestRecoveryProtectionPolicyResource_basic(t *testing.T) {
118119
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
119120
resource.TestCheckResourceAttrSet(resourceName, "id"),
120121
resource.TestCheckResourceAttrSet(resourceName, "is_predefined_policy"),
122+
resource.TestCheckResourceAttr(resourceName, "must_enforce_cloud_locality", "false"),
121123
resource.TestCheckResourceAttr(resourceName, "policy_locked_date_time", recoveryProtectionPolicyRepresentationPolicyLockedDateTimeCreate),
122124

123125
func(s *terraform.State) (err error) {
@@ -146,6 +148,7 @@ func TestRecoveryProtectionPolicyResource_basic(t *testing.T) {
146148
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
147149
resource.TestCheckResourceAttrSet(resourceName, "id"),
148150
resource.TestCheckResourceAttrSet(resourceName, "is_predefined_policy"),
151+
resource.TestCheckResourceAttr(resourceName, "must_enforce_cloud_locality", "false"),
149152
resource.TestCheckResourceAttr(resourceName, "policy_locked_date_time", recoveryProtectionPolicyRepresentationPolicyLockedDateTimeCreate),
150153

151154
func(s *terraform.State) (err error) {
@@ -169,6 +172,7 @@ func TestRecoveryProtectionPolicyResource_basic(t *testing.T) {
169172
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
170173
resource.TestCheckResourceAttrSet(resourceName, "id"),
171174
resource.TestCheckResourceAttrSet(resourceName, "is_predefined_policy"),
175+
resource.TestCheckResourceAttr(resourceName, "must_enforce_cloud_locality", "false"),
172176
resource.TestCheckResourceAttr(resourceName, "policy_locked_date_time", recoveryProtectionPolicyRepresentationPolicyLockedDateTimeUpdate),
173177

174178
func(s *terraform.State) (err error) {
@@ -211,6 +215,7 @@ func TestRecoveryProtectionPolicyResource_basic(t *testing.T) {
211215
resource.TestCheckResourceAttr(singularDatasourceName, "freeform_tags.%", "1"),
212216
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
213217
resource.TestCheckResourceAttrSet(singularDatasourceName, "is_predefined_policy"),
218+
resource.TestCheckResourceAttr(singularDatasourceName, "must_enforce_cloud_locality", "false"),
214219
resource.TestCheckResourceAttr(singularDatasourceName, "policy_locked_date_time", recoveryProtectionPolicyRepresentationPolicyLockedDateTimeUpdate),
215220
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
216221
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),

internal/service/recovery/recovery_protected_database_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ func (s *RecoveryProtectedDatabaseDataSourceCrud) SetData() error {
130130

131131
s.D.Set("state", s.Res.LifecycleState)
132132

133+
if s.Res.SubscriptionId != nil {
134+
s.D.Set("subscription_id", *s.Res.SubscriptionId)
135+
}
136+
133137
if s.Res.SystemTags != nil {
134138
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
135139
}

internal/service/recovery/recovery_protected_database_resource.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func RecoveryProtectedDatabaseResource() *schema.Resource {
115115
Optional: true,
116116
Computed: true,
117117
},
118+
"subscription_id": {
119+
Type: schema.TypeString,
120+
Optional: true,
121+
Computed: true,
122+
},
118123

119124
// Computed
120125
"health": {
@@ -347,6 +352,11 @@ func (s *RecoveryProtectedDatabaseResourceCrud) Create() error {
347352
}
348353
}
349354

355+
if subscriptionId, ok := s.D.GetOkExists("subscription_id"); ok {
356+
tmp := subscriptionId.(string)
357+
request.SubscriptionId = &tmp
358+
}
359+
350360
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "recovery")
351361

352362
response, err := s.Client.CreateProtectedDatabase(context.Background(), request)
@@ -505,6 +515,14 @@ func (s *RecoveryProtectedDatabaseResourceCrud) Update() error {
505515
}
506516
}
507517
}
518+
519+
if subscription, ok := s.D.GetOkExists("subscription_id"); ok && s.D.HasChange("subscription_id") {
520+
err := s.updateSubscription(subscription.(string))
521+
if err != nil {
522+
return err
523+
}
524+
}
525+
508526
request := oci_recovery.UpdateProtectedDatabaseRequest{}
509527

510528
if databaseSize, ok := s.D.GetOkExists("database_size"); ok {
@@ -655,6 +673,12 @@ func (s *RecoveryProtectedDatabaseResourceCrud) SetData() error {
655673

656674
s.D.Set("state", s.Res.LifecycleState)
657675

676+
if s.Res.SubscriptionId != nil {
677+
s.D.Set("subscription_id", *s.Res.SubscriptionId)
678+
} else {
679+
s.D.Set("subscription_id", nil)
680+
}
681+
658682
if s.Res.SystemTags != nil {
659683
s.D.Set("system_tags", tfresource.SystemTagsToMap(s.Res.SystemTags))
660684
}
@@ -815,6 +839,10 @@ func ProtectedDatabaseSummaryToMap(obj oci_recovery.ProtectedDatabaseSummary) ma
815839

816840
result["state"] = string(obj.LifecycleState)
817841

842+
if obj.SubscriptionId != nil {
843+
result["subscription_id"] = string(*obj.SubscriptionId)
844+
}
845+
818846
if obj.SystemTags != nil {
819847
result["system_tags"] = tfresource.SystemTagsToMap(obj.SystemTags)
820848
}
@@ -876,3 +904,26 @@ func (s *RecoveryProtectedDatabaseResourceCrud) updateCompartment(compartment in
876904
workId := response.OpcWorkRequestId
877905
return s.getProtectedDatabaseFromWorkRequest(workId, tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "recovery"), oci_recovery.ActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate))
878906
}
907+
908+
func (s *RecoveryProtectedDatabaseResourceCrud) updateSubscription(subscriptionId string) error {
909+
changeSubscriptionRequest := oci_recovery.ChangeProtectedDatabaseSubscriptionRequest{}
910+
911+
idTmp := s.D.Id()
912+
changeSubscriptionRequest.ProtectedDatabaseId = &idTmp
913+
914+
subscriptionIdTmp := subscriptionId
915+
changeSubscriptionRequest.SubscriptionId = &subscriptionIdTmp
916+
917+
isDefaultTmp := false
918+
changeSubscriptionRequest.IsDefault = &isDefaultTmp
919+
920+
changeSubscriptionRequest.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "recovery")
921+
922+
response, err := s.Client.ChangeProtectedDatabaseSubscription(context.Background(), changeSubscriptionRequest)
923+
if err != nil {
924+
return err
925+
}
926+
927+
workId := response.OpcWorkRequestId
928+
return s.getProtectedDatabaseFromWorkRequest(workId, tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "recovery"), oci_recovery.ActionTypeUpdated, s.D.Timeout(schema.TimeoutUpdate))
929+
}

internal/service/recovery/recovery_protection_policy_data_source.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func (s *RecoveryProtectionPolicyDataSourceCrud) SetData() error {
9292
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
9393
}
9494

95+
if s.Res.MustEnforceCloudLocality != nil {
96+
s.D.Set("must_enforce_cloud_locality", *s.Res.MustEnforceCloudLocality)
97+
}
98+
9599
if s.Res.PolicyLockedDateTime != nil {
96100
s.D.Set("policy_locked_date_time", *s.Res.PolicyLockedDateTime)
97101
}

internal/service/recovery/recovery_protection_policy_resource.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func RecoveryProtectionPolicyResource() *schema.Resource {
5858
Computed: true,
5959
Elem: schema.TypeString,
6060
},
61+
"must_enforce_cloud_locality": {
62+
Type: schema.TypeBool,
63+
Optional: true,
64+
Computed: true,
65+
ForceNew: true,
66+
},
6167
"policy_locked_date_time": {
6268
Type: schema.TypeString,
6369
Optional: true,
@@ -192,6 +198,11 @@ func (s *RecoveryProtectionPolicyResourceCrud) Create() error {
192198
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
193199
}
194200

201+
if mustEnforceCloudLocality, ok := s.D.GetOkExists("must_enforce_cloud_locality"); ok {
202+
tmp := mustEnforceCloudLocality.(bool)
203+
request.MustEnforceCloudLocality = &tmp
204+
}
205+
195206
if policyLockedDateTime, ok := s.D.GetOkExists("policy_locked_date_time"); ok {
196207
tmp := policyLockedDateTime.(string)
197208
request.PolicyLockedDateTime = &tmp
@@ -445,6 +456,10 @@ func (s *RecoveryProtectionPolicyResourceCrud) SetData() error {
445456
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
446457
}
447458

459+
if s.Res.MustEnforceCloudLocality != nil {
460+
s.D.Set("must_enforce_cloud_locality", *s.Res.MustEnforceCloudLocality)
461+
}
462+
448463
if s.Res.PolicyLockedDateTime != nil {
449464
s.D.Set("policy_locked_date_time", *s.Res.PolicyLockedDateTime)
450465
}
@@ -499,6 +514,10 @@ func ProtectionPolicySummaryToMap(obj oci_recovery.ProtectionPolicySummary) map[
499514
result["lifecycle_details"] = string(*obj.LifecycleDetails)
500515
}
501516

517+
if obj.MustEnforceCloudLocality != nil {
518+
result["must_enforce_cloud_locality"] = bool(*obj.MustEnforceCloudLocality)
519+
}
520+
502521
if obj.PolicyLockedDateTime != nil {
503522
result["policy_locked_date_time"] = string(*obj.PolicyLockedDateTime)
504523
}

website/docs/d/recovery_protected_database.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ The following attributes are exported:
7272
* `recovery_service_subnet_id` - Recovery Service Subnet Identifier.
7373
* `state` - The current state of the Recovery Service Subnet.
7474
* `state` - The current state of the Protected Database.
75+
* `subscription_id` - The OCID of the cloud service subscription to which the protected database is linked.
7576
* `system_tags` - Usage of system tag keys. These predefined keys are scoped to namespaces. Example: `{"orcl-cloud.free-tier-retained": "true"}`. For more information, see [Resource Tags](https://docs.oracle.com/en-us/iaas/Content/General/Concepts/resourcetags.htm)
7677
* `time_created` - An RFC3339 formatted datetime string that indicates the created time for a protected database. For example: '2020-05-22T21:10:29.600Z'
7778
* `time_updated` - An RFC3339 formatted datetime string that indicates the last updated time for a protected database. For example: '2020-05-22T21:10:29.600Z'

website/docs/d/recovery_protected_databases.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The following attributes are exported:
9191
* `recovery_service_subnet_id` - Recovery Service Subnet Identifier.
9292
* `state` - The current state of the Recovery Service Subnet.
9393
* `state` - The current state of the Protected Database.
94+
* `subscription_id` - The OCID of the cloud service subscription to which the protected database is linked.
9495
* `system_tags` - Usage of system tag keys. These predefined keys are scoped to namespaces. Example: `{"orcl-cloud.free-tier-retained": "true"}`. For more information, see [Resource Tags](https://docs.oracle.com/en-us/iaas/Content/General/Concepts/resourcetags.htm)
9596
* `time_created` - An RFC3339 formatted datetime string that indicates the created time for a protected database. For example: '2020-05-22T21:10:29.600Z'
9697
* `time_updated` - An RFC3339 formatted datetime string that indicates the last updated time for a protected database. For example: '2020-05-22T21:10:29.600Z'

0 commit comments

Comments
 (0)