Skip to content

Commit 1b930cb

Browse files
committed
Add support for moving DNS zones and steering policies across compartments
1 parent ca5bf86 commit 1b930cb

File tree

6 files changed

+170
-13
lines changed

6 files changed

+170
-13
lines changed

CHANGELOG.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@
1313
- Support for moving `core_instance` resources across compartments
1414
- Support for LBaaS Cookie Insertion (Sticky Cookie)
1515
- Support for moving `identity_compartment` resource tree across compartments
16-
17-
## 3.33.0 (July 10, 2019)
18-
19-
### Added
20-
- Support autonomous transaction processing preview mode
21-
- Support load balancer attachment data source for instance pools
22-
- Support moving `core_route_table`, `core_security_list`, `core_subnet`, `core_vcn` resources across compartments
23-
- Support for Granular Security Lists using Network Security Group
24-
- Support for Granular Security Lists in Load Balancer
25-
- Support for Network Security Groups in databases
16+
- Support for moving `dns_zone` and `dns_steering_policy` resources across compartments
2617
- Support in autonomous database and object data sources for encoding downloaded binary content as base64. This works around behavior in Terraform v0.12 that could cause binary content to be corrupted if written directly to state.
2718

2819
### Fixed
@@ -39,6 +30,16 @@ that are maps of string values.
3930
- identity_user
4031
- Removing deprecated field `time_state_modifed` from data source `core_ip_sec_connection_device_status`. `time_state_modified` should be used instead
4132

33+
## 3.33.0 (July 10, 2019)
34+
35+
### Added
36+
- Support autonomous transaction processing preview mode
37+
- Support load balancer attachment data source for instance pools
38+
- Support moving `core_route_table`, `core_security_list`, `core_subnet`, `core_vcn` resources across compartments
39+
- Support for Granular Security Lists using Network Security Group
40+
- Support for Granular Security Lists in Load Balancer
41+
- Support for Network Security Groups in databases
42+
4243
## 3.32.0 (July 03, 2019)
4344

4445
### Added

oci/dns_steering_policy_resource.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func DnsSteeringPolicyResource() *schema.Resource {
2929
"compartment_id": {
3030
Type: schema.TypeString,
3131
Required: true,
32-
ForceNew: true,
3332
},
3433
"display_name": {
3534
Type: schema.TypeString,
@@ -425,6 +424,15 @@ func (s *DnsSteeringPolicyResourceCrud) Get() error {
425424
}
426425

427426
func (s *DnsSteeringPolicyResourceCrud) Update() error {
427+
if compartment, ok := s.D.GetOkExists("compartment_id"); ok && s.D.HasChange("compartment_id") {
428+
oldRaw, newRaw := s.D.GetChange("compartment_id")
429+
if newRaw != "" && oldRaw != "" {
430+
err := s.updateCompartment(compartment)
431+
if err != nil {
432+
return err
433+
}
434+
}
435+
}
428436
request := oci_dns.UpdateSteeringPolicyRequest{}
429437

430438
/* Do not uncomment until we get a solution to the terraform deficiency
@@ -1168,3 +1176,21 @@ func SteeringPolicyWeightedRuleCaseToMap(obj oci_dns.SteeringPolicyWeightedRuleC
11681176

11691177
return result
11701178
}
1179+
1180+
func (s *DnsSteeringPolicyResourceCrud) updateCompartment(compartment interface{}) error {
1181+
changeCompartmentRequest := oci_dns.ChangeSteeringPolicyCompartmentRequest{}
1182+
1183+
compartmentTmp := compartment.(string)
1184+
changeCompartmentRequest.CompartmentId = &compartmentTmp
1185+
1186+
idTmp := s.D.Id()
1187+
changeCompartmentRequest.SteeringPolicyId = &idTmp
1188+
1189+
changeCompartmentRequest.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "dns")
1190+
1191+
_, err := s.Client.ChangeSteeringPolicyCompartment(context.Background(), changeCompartmentRequest)
1192+
if err != nil {
1193+
return err
1194+
}
1195+
return nil
1196+
}

oci/dns_steering_policy_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func TestDnsSteeringPolicyResource_basic(t *testing.T) {
160160
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
161161
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
162162

163+
compartmentIdU := getEnvSettingWithDefault("compartment_id_for_update", compartmentId)
164+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
165+
163166
resourceName := "oci_dns_steering_policy.test_steering_policy"
164167

165168
datasourceName := "data.oci_dns_steering_policies.test_steering_policies"
@@ -262,6 +265,79 @@ func TestDnsSteeringPolicyResource_basic(t *testing.T) {
262265
),
263266
},
264267

268+
// verify update to the compartment (the compartment will be switched back in the next step)
269+
{
270+
Config: config + compartmentIdVariableStr + compartmentIdUVariableStr + SteeringPolicyResourceDependencies +
271+
generateResourceFromRepresentationMap("oci_dns_steering_policy", "test_steering_policy", Optional, Create,
272+
representationCopyWithNewProperties(steeringPolicyRepresentation, map[string]interface{}{
273+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id_for_update}`},
274+
})),
275+
Check: resource.ComposeAggregateTestCheckFunc(
276+
resource.TestCheckResourceAttr(resourceName, "answers.#", "1"),
277+
resource.TestCheckResourceAttr(resourceName, "answers.0.is_disabled", "false"),
278+
resource.TestCheckResourceAttr(resourceName, "answers.0.name", "name"),
279+
resource.TestCheckResourceAttr(resourceName, "answers.0.pool", "pool"),
280+
resource.TestCheckResourceAttr(resourceName, "answers.0.rdata", "192.0.2.1"),
281+
resource.TestCheckResourceAttr(resourceName, "answers.0.rtype", "A"),
282+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
283+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
284+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
285+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
286+
resource.TestCheckResourceAttrSet(resourceName, "health_check_monitor_id"),
287+
resource.TestCheckResourceAttr(resourceName, "rules.#", "5"),
288+
resource.TestCheckResourceAttr(resourceName, "rules.0.cases.#", "1"),
289+
resource.TestCheckResourceAttr(resourceName, "rules.0.cases.0.answer_data.#", "1"),
290+
resource.TestCheckResourceAttr(resourceName, "rules.0.cases.0.answer_data.0.answer_condition", "answer.name == 'sampler'"),
291+
resource.TestCheckResourceAttr(resourceName, "rules.0.cases.0.answer_data.0.should_keep", "false"),
292+
resource.TestCheckResourceAttr(resourceName, "rules.0.cases.0.case_condition", "query.client.address in (subnet '198.51.100.0/24')"),
293+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.#", "1"),
294+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.0.answer_condition", "answer.name == 'sampler'"),
295+
resource.TestCheckResourceAttr(resourceName, "rules.0.default_answer_data.0.should_keep", "false"),
296+
resource.TestCheckResourceAttr(resourceName, "rules.0.description", "filter description"),
297+
resource.TestCheckResourceAttr(resourceName, "rules.0.rule_type", "FILTER"),
298+
resource.TestCheckResourceAttr(resourceName, "rules.1.cases.#", "1"),
299+
resource.TestCheckResourceAttr(resourceName, "rules.1.cases.0.case_condition", "query.client.address in (subnet '198.51.100.0/24')"),
300+
resource.TestCheckResourceAttr(resourceName, "rules.1.description", "health description"),
301+
resource.TestCheckResourceAttr(resourceName, "rules.1.rule_type", "HEALTH"),
302+
resource.TestCheckResourceAttr(resourceName, "rules.2.cases.#", "1"),
303+
resource.TestCheckResourceAttr(resourceName, "rules.2.cases.0.case_condition", "query.client.address in (subnet '198.51.100.0/24')"),
304+
resource.TestCheckResourceAttr(resourceName, "rules.2.cases.0.count", "10"),
305+
resource.TestCheckResourceAttr(resourceName, "rules.2.default_count", "10"),
306+
resource.TestCheckResourceAttr(resourceName, "rules.2.description", "limit description"),
307+
resource.TestCheckResourceAttr(resourceName, "rules.2.rule_type", "LIMIT"),
308+
resource.TestCheckResourceAttr(resourceName, "rules.3.cases.#", "1"),
309+
resource.TestCheckResourceAttr(resourceName, "rules.3.cases.0.answer_data.#", "1"),
310+
resource.TestCheckResourceAttr(resourceName, "rules.3.cases.0.answer_data.0.answer_condition", "answer.name == 'sampler'"),
311+
resource.TestCheckResourceAttr(resourceName, "rules.3.cases.0.answer_data.0.value", "10"),
312+
resource.TestCheckResourceAttr(resourceName, "rules.3.cases.0.case_condition", "query.client.address in (subnet '198.51.100.0/24')"),
313+
resource.TestCheckResourceAttr(resourceName, "rules.3.default_answer_data.#", "1"),
314+
resource.TestCheckResourceAttr(resourceName, "rules.3.default_answer_data.0.answer_condition", "answer.name == 'sampler'"),
315+
resource.TestCheckResourceAttr(resourceName, "rules.3.default_answer_data.0.value", "10"),
316+
resource.TestCheckResourceAttr(resourceName, "rules.3.description", "priority description"),
317+
resource.TestCheckResourceAttr(resourceName, "rules.3.rule_type", "PRIORITY"),
318+
resource.TestCheckResourceAttr(resourceName, "rules.4.cases.#", "1"),
319+
resource.TestCheckResourceAttr(resourceName, "rules.4.cases.0.answer_data.#", "1"),
320+
resource.TestCheckResourceAttr(resourceName, "rules.4.cases.0.answer_data.0.answer_condition", "answer.name == 'sampler'"),
321+
resource.TestCheckResourceAttr(resourceName, "rules.4.cases.0.answer_data.0.value", "10"),
322+
resource.TestCheckResourceAttr(resourceName, "rules.4.cases.0.case_condition", "query.client.address in (subnet '198.51.100.0/24')"),
323+
resource.TestCheckResourceAttr(resourceName, "rules.4.default_answer_data.#", "1"),
324+
resource.TestCheckResourceAttr(resourceName, "rules.4.default_answer_data.0.answer_condition", "answer.name == 'sampler'"),
325+
resource.TestCheckResourceAttr(resourceName, "rules.4.default_answer_data.0.value", "10"),
326+
resource.TestCheckResourceAttr(resourceName, "rules.4.description", "weighted description"),
327+
resource.TestCheckResourceAttr(resourceName, "rules.4.rule_type", "WEIGHTED"),
328+
resource.TestCheckResourceAttr(resourceName, "template", "CUSTOM"),
329+
resource.TestCheckResourceAttr(resourceName, "ttl", "10"),
330+
331+
func(s *terraform.State) (err error) {
332+
resId2, err = fromInstanceState(s, resourceName, "id")
333+
if resId != resId2 {
334+
return fmt.Errorf("resource recreated when it was supposed to be updated")
335+
}
336+
return err
337+
},
338+
),
339+
},
340+
265341
// verify updates to updatable parameters
266342
{
267343
Config: config + compartmentIdVariableStr + SteeringPolicyResourceDependencies +

oci/dns_zone_resource.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func DnsZoneResource() *schema.Resource {
2727
"compartment_id": {
2828
Type: schema.TypeString,
2929
Required: true,
30-
ForceNew: true,
3130
},
3231
"name": {
3332
Type: schema.TypeString,
@@ -274,6 +273,15 @@ func (s *DnsZoneResourceCrud) Get() error {
274273
}
275274

276275
func (s *DnsZoneResourceCrud) Update() error {
276+
if compartment, ok := s.D.GetOkExists("compartment_id"); ok && s.D.HasChange("compartment_id") {
277+
oldRaw, newRaw := s.D.GetChange("compartment_id")
278+
if newRaw != "" && oldRaw != "" {
279+
err := s.updateCompartment(compartment)
280+
if err != nil {
281+
return err
282+
}
283+
}
284+
}
277285
request := oci_dns.UpdateZoneRequest{}
278286

279287
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
@@ -485,3 +493,21 @@ func TSIGToMap(obj *oci_dns.Tsig) map[string]interface{} {
485493

486494
return result
487495
}
496+
497+
func (s *DnsZoneResourceCrud) updateCompartment(compartment interface{}) error {
498+
changeCompartmentRequest := oci_dns.ChangeZoneCompartmentRequest{}
499+
500+
compartmentTmp := compartment.(string)
501+
changeCompartmentRequest.CompartmentId = &compartmentTmp
502+
503+
idTmp := s.D.Id()
504+
changeCompartmentRequest.ZoneId = &idTmp
505+
506+
changeCompartmentRequest.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "dns")
507+
508+
_, err := s.Client.ChangeZoneCompartment(context.Background(), changeCompartmentRequest)
509+
if err != nil {
510+
return err
511+
}
512+
return nil
513+
}

oci/dns_zone_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func TestDnsZoneResource_basic(t *testing.T) {
9090
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
9191
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
9292

93+
compartmentIdU := getEnvSettingWithDefault("compartment_id_for_update", compartmentId)
94+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
95+
9396
resourceName := "oci_dns_zone.test_zone"
9497
datasourceName := "data.oci_dns_zones.test_zones"
9598

@@ -171,6 +174,31 @@ func TestDnsZoneResource_basic(t *testing.T) {
171174
},
172175
),
173176
},
177+
178+
// verify update to the compartment (the compartment will be switched back in the next step)
179+
{
180+
Config: tokenFn(config+compartmentIdVariableStr+compartmentIdUVariableStr+ZoneResourceDependencies+
181+
generateResourceFromRepresentationMap("oci_dns_zone", "test_zone", Optional, Create,
182+
representationCopyWithNewProperties(representationCopyWithRemovedProperties(zoneRepresentationPrimary, []string{"external_masters"}), map[string]interface{}{
183+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id_for_update}`},
184+
})), nil),
185+
Check: resource.ComposeAggregateTestCheckFunc(
186+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentIdU),
187+
resource.TestMatchResourceAttr(resourceName, "name", regexp.MustCompile("\\.oci-zone-test")),
188+
resource.TestCheckResourceAttr(resourceName, "zone_type", "PRIMARY"),
189+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
190+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
191+
resource.TestCheckResourceAttrSet(resourceName, "nameservers.#"),
192+
193+
func(s *terraform.State) (err error) {
194+
resId2, err = fromInstanceState(s, resourceName, "id")
195+
if resId != resId2 {
196+
return fmt.Errorf("resource recreated when it was supposed to be updated")
197+
}
198+
return err
199+
},
200+
),
201+
},
174202
// verify updates to updatable parameters
175203
{
176204
Config: tokenFn(config+compartmentIdVariableStr+ZoneResourceDependencies+

website/docs/r/dns_steering_policy.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The following arguments are supported:
8080
* `pool` - (Optional) The freeform name of a group of one or more records in which this record is included, such as "LAX data center". An answer's `pool` property can be referenced in `answerCondition` properties of rules using `answer.pool`.
8181
* `rdata` - (Required) The record's data, as whitespace-delimited tokens in type-specific presentation format. All RDATA is normalized and the returned presentation of your RDATA may differ from its initial input. For more information about RDATA, see [Supported DNS Resource Record Types](https://docs.cloud.oracle.com/iaas/Content/DNS/Reference/supporteddnsresource.htm).
8282
* `rtype` - (Required) The canonical name for the record's type. Only A, AAAA, and CNAME are supported. For more information, see [Supported DNS Resource Record Types](https://docs.cloud.oracle.com/iaas/Content/DNS/Reference/supporteddnsresource.htm).
83-
* `compartment_id` - (Required) The OCID of the compartment containing the steering policy.
83+
* `compartment_id` - (Required) (Updatable) The OCID of the compartment containing the steering policy.
8484
* `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).
8585
* `display_name` - (Required) (Updatable) A user-friendly name for the steering policy. Does not have to be unique and can be changed. Avoid entering confidential information.
8686
* `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).

0 commit comments

Comments
 (0)