2828 }
2929
3030 compartmentDataSourceRepresentation = map [string ]interface {}{
31- "compartment_id" : Representation {repType : Required , create : `${var.tenancy_ocid }` },
31+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id }` },
3232 "access_level" : Representation {repType : Optional , create : `ANY` },
3333 "compartment_id_in_subtree" : Representation {repType : Optional , create : `false` },
3434 "filter" : RepresentationGroup {Required , compartmentDataSourceFilterRepresentation }}
3838 }
3939
4040 compartmentRepresentation = map [string ]interface {}{
41- "compartment_id" : Representation {repType : Required , create : `${var.tenancy_ocid }` },
41+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id }` },
4242 "description" : Representation {repType : Required , create : `For network components` , update : `description2` },
4343 "name" : Representation {repType : Required , create : `Network` , update : `name2` },
4444 "defined_tags" : Representation {repType : 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")}` },
@@ -57,7 +57,9 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
5757
5858 compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
5959 compartmentIdVariableStr := fmt .Sprintf ("variable \" compartment_id\" { default = \" %s\" }\n " , compartmentId )
60- tenancyId := getEnvSettingWithBlankDefault ("tenancy_ocid" )
60+
61+ compartmentIdU := getEnvSettingWithDefault ("compartment_id_for_update" , compartmentId )
62+ compartmentIdUVariableStr := fmt .Sprintf ("variable \" compartment_id_for_update\" { default = \" %s\" }\n " , compartmentIdU )
6163
6264 resourceName := "oci_identity_compartment.test_compartment"
6365 datasourceName := "data.oci_identity_compartments.test_compartments"
@@ -77,7 +79,7 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
7779 Config : config + compartmentIdVariableStr + CompartmentResourceDependencies +
7880 generateResourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Required , Create , compartmentRepresentation ),
7981 Check : resource .ComposeAggregateTestCheckFunc (
80- resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
82+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
8183 resource .TestCheckResourceAttr (resourceName , "description" , "For network components" ),
8284 resource .TestCheckResourceAttr (resourceName , "name" , "Network" ),
8385
@@ -92,7 +94,7 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
9294 Config : config + compartmentIdVariableStr + CompartmentResourceDependencies +
9395 generateResourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Optional , Create , compartmentRepresentation ),
9496 Check : resource .ComposeAggregateTestCheckFunc (
95- resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
97+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
9698 resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "1" ),
9799 resource .TestCheckResourceAttr (resourceName , "description" , "For network components" ),
98100 resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
@@ -108,12 +110,39 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
108110 ),
109111 },
110112
113+ // verify update to the compartment (the compartment will be switched back in the next step)
114+ {
115+ Config : config + compartmentIdVariableStr + compartmentIdUVariableStr + CompartmentResourceDependencies +
116+ generateResourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Optional , Create ,
117+ representationCopyWithNewProperties (compartmentRepresentation , map [string ]interface {}{
118+ "compartment_id" : Representation {repType : Required , create : `${var.compartment_id_for_update}` },
119+ })),
120+ Check : resource .ComposeAggregateTestCheckFunc (
121+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentIdU ),
122+ resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "1" ),
123+ resource .TestCheckResourceAttr (resourceName , "description" , "For network components" ),
124+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
125+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
126+ resource .TestCheckResourceAttr (resourceName , "name" , "Network" ),
127+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
128+ resource .TestCheckResourceAttrSet (resourceName , "time_created" ),
129+
130+ func (s * terraform.State ) (err error ) {
131+ resId2 , err = fromInstanceState (s , resourceName , "id" )
132+ if resId != resId2 {
133+ return fmt .Errorf ("resource recreated when it was supposed to be updated" )
134+ }
135+ return err
136+ },
137+ ),
138+ },
139+
111140 // verify updates to updatable parameters
112141 {
113142 Config : config + compartmentIdVariableStr + CompartmentResourceDependencies +
114143 generateResourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Optional , Update , compartmentRepresentation ),
115144 Check : resource .ComposeAggregateTestCheckFunc (
116- resource .TestCheckResourceAttr (resourceName , "compartment_id" , tenancyId ),
145+ resource .TestCheckResourceAttr (resourceName , "compartment_id" , compartmentId ),
117146 resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "1" ),
118147 resource .TestCheckResourceAttr (resourceName , "description" , "description2" ),
119148 resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
@@ -139,11 +168,11 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
139168 generateResourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Optional , Update , compartmentRepresentation ),
140169 Check : resource .ComposeAggregateTestCheckFunc (
141170 resource .TestCheckResourceAttr (datasourceName , "access_level" , "ANY" ),
142- resource .TestCheckResourceAttr (datasourceName , "compartment_id" , tenancyId ),
171+ resource .TestCheckResourceAttr (datasourceName , "compartment_id" , compartmentId ),
143172 resource .TestCheckResourceAttr (datasourceName , "compartment_id_in_subtree" , "false" ),
144173
145174 resource .TestCheckResourceAttr (datasourceName , "compartments.#" , "1" ),
146- resource .TestCheckResourceAttr (datasourceName , "compartments.0.compartment_id" , tenancyId ),
175+ resource .TestCheckResourceAttr (datasourceName , "compartments.0.compartment_id" , compartmentId ),
147176 resource .TestCheckResourceAttr (datasourceName , "compartments.0.defined_tags.%" , "1" ),
148177 resource .TestCheckResourceAttr (datasourceName , "compartments.0.description" , "description2" ),
149178 resource .TestCheckResourceAttr (datasourceName , "compartments.0.freeform_tags.%" , "1" ),
@@ -159,7 +188,7 @@ func TestIdentityCompartmentResource_basic(t *testing.T) {
159188 generateDataSourceFromRepresentationMap ("oci_identity_compartment" , "test_compartment" , Required , Create , compartmentSingularDataSourceRepresentation ) +
160189 compartmentIdVariableStr + CompartmentResourceConfig ,
161190 Check : resource .ComposeAggregateTestCheckFunc (
162- resource .TestCheckResourceAttrSet (singularDatasourceName , "compartment_id" ),
191+ resource .TestCheckResourceAttr (singularDatasourceName , "compartment_id" , compartmentId ),
163192 resource .TestCheckResourceAttr (singularDatasourceName , "defined_tags.%" , "1" ),
164193 resource .TestCheckResourceAttr (singularDatasourceName , "description" , "description2" ),
165194 resource .TestCheckResourceAttr (singularDatasourceName , "freeform_tags.%" , "1" ),
0 commit comments