Skip to content

Commit 0da6a1a

Browse files
Added implemetation for updatecompartment to managed core resources
1 parent 84ee657 commit 0da6a1a

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Support Update `DrgAttachment` of types `Virtual_Circuit`, `RPC` and `IPSec`
1111
- Support for E3 Flex Notebooks added to `datascience`
1212
- Support for Non-Rolling patch mode added to `database_maintenance_run_resource`
13+
- Support for update compartment for `oci_core_default_security_list`, `oci_core_default_dhcp_options`, `oci_core_default_route_table`
1314

1415
## 4.27.0 (May 19, 2021)
1516

oci/core_dhcp_options_resource_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
var defaultDhcpOpts = `
2020
resource "oci_core_default_dhcp_options" "default" {
2121
manage_default_resource_id = "${oci_core_virtual_network.t.default_dhcp_options_id}"
22+
compartment_id = "${var.compartment_id}"
2223
options {
2324
type = "DomainNameServer"
2425
server_type = "CustomDnsServer"
@@ -55,6 +56,10 @@ func TestResourceCoreDHCPOptions_basic(t *testing.T) {
5556

5657
provider := testAccProvider
5758

59+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
60+
compartmentIdU := getEnvSettingWithDefault("compartment_id_for_update", compartmentId)
61+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
62+
5863
config := legacyTestProviderConfig() + `
5964
resource "oci_core_virtual_network" "t" {
6065
cidr_block = "10.0.0.0/16"
@@ -178,7 +183,7 @@ func TestResourceCoreDHCPOptions_basic(t *testing.T) {
178183
ExpectError: regexp.MustCompile(".*JSON input"),
179184
},
180185
{
181-
Config: config + additionalDhcpOption4 + defaultDhcpOpts,
186+
Config: config + additionalDhcpOption4 + defaultDhcpOpts + compartmentIdUVariableStr,
182187
Check: resource.ComposeAggregateTestCheckFunc(
183188

184189
resource.TestCheckResourceAttr("oci_core_dhcp_options.opt1", "display_name", "display_name1"),
@@ -251,8 +256,7 @@ func TestResourceCoreDHCPOptions_basic(t *testing.T) {
251256
resource.TestCheckResourceAttrSet("oci_core_default_dhcp_options.default", "time_created"),
252257
resource.TestCheckResourceAttr("oci_core_default_dhcp_options.default", "state", string(core.DhcpOptionsLifecycleStateAvailable)),
253258
resource.TestCheckNoResourceAttr("oci_core_default_dhcp_options.default", "vcn_id"),
254-
resource.TestCheckNoResourceAttr("oci_core_default_dhcp_options.default", "compartment_id"),
255-
259+
resource.TestCheckResourceAttr("oci_core_default_dhcp_options.default", "compartment_id", compartmentIdU),
256260
func(s *terraform.State) (err error) {
257261
if resDefaultId, err = fromInstanceState(s, "oci_core_default_dhcp_options.default", "id"); err != nil {
258262
return err
@@ -286,7 +290,6 @@ func TestResourceCoreDHCPOptions_basic(t *testing.T) {
286290
resource.TestCheckResourceAttrSet("oci_core_default_dhcp_options.default", "time_created"),
287291
resource.TestCheckResourceAttr("oci_core_default_dhcp_options.default", "state", string(core.DhcpOptionsLifecycleStateAvailable)),
288292
resource.TestCheckNoResourceAttr("oci_core_default_dhcp_options.default", "vcn_id"),
289-
resource.TestCheckNoResourceAttr("oci_core_default_dhcp_options.default", "compartment_id"),
290293

291294
func(s *terraform.State) (err error) {
292295
resId2, err = fromInstanceState(s, "oci_core_default_dhcp_options.default", "id")

oci/core_route_table_resource_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
299299
display_name = "-tf-internet-gateway"
300300
}`
301301

302+
compartmentIdU := getEnvSettingWithDefault("compartment_id_for_update", compartmentId)
303+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
302304
resourceName := "oci_core_route_table.t"
303305
defaultResourceName := "oci_core_default_route_table.default"
304306

@@ -356,6 +358,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
356358
"network_entity_id",
357359
}),
358360
resource.TestCheckResourceAttrSet(defaultResourceName, "manage_default_resource_id"),
361+
resource.TestCheckResourceAttrSet(defaultResourceName, "compartment_id"),
359362
resource.TestCheckResourceAttr(defaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
360363
resource.TestCheckResourceAttrSet(defaultResourceName, "display_name"),
361364
resource.TestCheckResourceAttr(defaultResourceName, "route_rules.#", "1"),
@@ -369,7 +372,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
369372
},
370373
// verify update
371374
{
372-
Config: config + `
375+
Config: compartmentIdUVariableStr + config + `
373376
resource "oci_core_route_table" "t" {
374377
compartment_id = "${var.compartment_id}"
375378
vcn_id = "${oci_core_virtual_network.t.id}"
@@ -386,6 +389,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
386389
resource "oci_core_default_route_table" "default" {
387390
manage_default_resource_id = "${oci_core_virtual_network.t.default_route_table_id}"
388391
display_name = "default-tf-route-table"
392+
compartment_id = "${var.compartment_id_for_update}"
389393
route_rules {
390394
cidr_block = "0.0.0.0/0"
391395
network_entity_id = "${oci_core_internet_gateway.internet-gateway1.id}"
@@ -415,6 +419,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
415419
}),
416420
resource.TestCheckResourceAttr(resourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
417421
resource.TestCheckResourceAttrSet(defaultResourceName, "manage_default_resource_id"),
422+
resource.TestCheckResourceAttr(defaultResourceName, "compartment_id", compartmentIdU),
418423
resource.TestCheckResourceAttr(defaultResourceName, "display_name", "default-tf-route-table"),
419424
resource.TestCheckResourceAttr(defaultResourceName, "route_rules.#", "2"),
420425
CheckResourceSetContainsElementWithProperties(defaultResourceName, "route_rules", map[string]string{
@@ -443,6 +448,7 @@ func TestResourceCoreRouteTable_defaultResource(t *testing.T) {
443448
Check: resource.ComposeAggregateTestCheckFunc(
444449
resource.TestCheckResourceAttrSet(defaultResourceName, "manage_default_resource_id"),
445450
resource.TestCheckResourceAttrSet(defaultResourceName, "display_name"),
451+
resource.TestCheckResourceAttrSet(defaultResourceName, "compartment_id"),
446452
resource.TestCheckResourceAttr(defaultResourceName, "route_rules.#", "1"),
447453
CheckResourceSetContainsElementWithProperties(defaultResourceName, "route_rules", map[string]string{
448454
"cidr_block": "0.0.0.0/0",

oci/core_security_list_resource_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package oci
55

66
import (
7+
"fmt"
78
"testing"
89

910
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
@@ -134,6 +135,7 @@ var fullConfig = `
134135
func (s *ResourceCoreSecurityListTestSuite) BuildTestsForFullConfig(resourceName, prefix string) []resource.TestCheckFunc {
135136
return []resource.TestCheckFunc{
136137
resource.TestCheckResourceAttr(resourceName, prefix+"display_name", "-tf-security_list"),
138+
//resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
137139
resource.TestCheckResourceAttr(resourceName, prefix+"egress_security_rules.#", "4"),
138140
CheckResourceSetContainsElementWithProperties(resourceName, prefix+"egress_security_rules", map[string]string{
139141
"destination": "0.0.0.0/1",
@@ -566,6 +568,9 @@ func (s *ResourceCoreSecurityListTestSuite) TestAccResourceCoreSecurityList_defa
566568
}
567569
}
568570
}`
571+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
572+
compartmentIdU := getEnvSettingWithDefault("compartment_id_for_update", compartmentId)
573+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
569574
resource.Test(s.T(), resource.TestCase{
570575
Providers: s.Providers,
571576
Steps: []resource.TestStep{
@@ -595,10 +600,11 @@ func (s *ResourceCoreSecurityListTestSuite) TestAccResourceCoreSecurityList_defa
595600
},
596601
// Update
597602
{
598-
Config: s.Config + `
603+
Config: compartmentIdUVariableStr + s.Config + `
599604
resource "oci_core_default_security_list" "default" {
600605
manage_default_resource_id = "${oci_core_virtual_network.t.default_security_list_id}"
601606
display_name = "default-tf-security_list-updated"
607+
compartment_id = "${var.compartment_id_for_update}"
602608
egress_security_rules {
603609
destination = "0.0.0.0/0"
604610
protocol = "17"
@@ -654,6 +660,7 @@ func (s *ResourceCoreSecurityListTestSuite) TestAccResourceCoreSecurityList_defa
654660
},
655661
nil),
656662
resource.TestCheckNoResourceAttr(s.DefaultResourceName, "ingress_security_rules.2.udp_options"),
663+
resource.TestCheckResourceAttr(s.DefaultResourceName, "compartment_id", compartmentIdU),
657664
),
658665
},
659666
// Verify removing the default resource

oci/helpers_core.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ func ConvertToDefaultVcnResourceSchema(resourceSchema *schema.Resource) *schema.
4141
ForceNew: true,
4242
}
4343

44-
delete(resourceSchema.Schema, "compartment_id")
44+
resourceSchema.Schema["compartment_id"] = &schema.Schema{
45+
Type: schema.TypeString,
46+
Optional: true,
47+
Computed: true,
48+
}
49+
4550
delete(resourceSchema.Schema, "vcn_id")
4651

4752
return resourceSchema

0 commit comments

Comments
 (0)