Skip to content

Commit 2a59957

Browse files
Akash Mishraravinitp
authored andcommitted
Bug Fix - TERRAFORM_ISSUE:NOSQL: Change on compartmentId of child table should be ignored
1 parent 4cd9241 commit 2a59957

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

internal/integrationtest/nosql_table_replica_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ func TestNosqlTableReplicaResource_basic(t *testing.T) {
7575
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
7676
resource.TestCheckResourceAttr(resourceName, "region", "ca-montreal-1"),
7777
resource.TestCheckResourceAttrSet(resourceName, "table_name_or_id"),
78+
resource.TestCheckResourceAttr(resourceName, "max_write_units", "10"),
79+
),
80+
},
81+
82+
// update the max_read_units/max_write_units of the resource, the changes should be ignored
83+
{
84+
Config: config + compartmentIdVariableStr + NosqlTableReplicaResourceDependencies +
85+
acctest.GenerateResourceFromRepresentationMap("oci_nosql_table_replica", "test_table_replica", acctest.Optional, acctest.Create, NosqlTableReplicaRepresentation),
86+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
87+
resource.TestCheckResourceAttr(resourceName, "region", "ca-montreal-1"),
88+
resource.TestCheckResourceAttrSet(resourceName, "table_name_or_id"),
89+
resource.TestCheckResourceAttr(resourceName, "max_write_units", "10"),
7890
),
7991
},
8092

internal/integrationtest/nosql_table_resource_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func TestNosqlTableResource_test(t *testing.T) {
102102
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
103103
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
104104

105+
compartmentIdU := utils.GetEnvSettingWithDefault("compartment_id_for_update", compartmentId)
106+
compartmentIdUVariableStr := fmt.Sprintf("variable \"compartment_id_for_update\" { default = \"%s\" }\n", compartmentIdU)
107+
105108
ondemandResourceName := "oci_nosql_table.test_ondemand"
106109
ondemandDatasourceName := "data.oci_nosql_tables.test_tables"
107110
ondemandSingularDatasourceName := "data.oci_nosql_table.test_ondemand"
@@ -240,7 +243,22 @@ func TestNosqlTableResource_test(t *testing.T) {
240243
resource.TestCheckResourceAttr(childResourceName, "compartment_id", compartmentId),
241244
resource.TestCheckResourceAttr(childResourceName, "ddl_statement", childTableDdlStatement),
242245
resource.TestCheckResourceAttr(childResourceName, "name", "test_table.test_child"),
243-
resource.TestCheckNoResourceAttr(childResourceName, "table_limits"),
246+
resource.TestCheckResourceAttr(childResourceName, "table_limits.#", "0"),
247+
),
248+
},
249+
250+
// verify updating compartment of the child table will be ignored
251+
{
252+
Config: config + compartmentIdVariableStr + compartmentIdUVariableStr + ChildTableResourceDependencies +
253+
acctest.GenerateResourceFromRepresentationMap("oci_nosql_table", "test_child", acctest.Required, acctest.Create,
254+
acctest.RepresentationCopyWithNewProperties(childTableRepresentation, map[string]interface{}{
255+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id_for_update}`},
256+
})),
257+
Check: resource.ComposeAggregateTestCheckFunc(
258+
resource.TestCheckResourceAttr(childResourceName, "compartment_id", compartmentId),
259+
resource.TestCheckResourceAttr(childResourceName, "ddl_statement", childTableDdlStatement),
260+
resource.TestCheckResourceAttr(childResourceName, "name", "test_table.test_child"),
261+
resource.TestCheckResourceAttr(childResourceName, "table_limits.#", "0"),
244262
),
245263
},
246264

@@ -257,7 +275,7 @@ func TestNosqlTableResource_test(t *testing.T) {
257275
resource.TestCheckResourceAttrSet(childDataResourceName, "table_collection.0.id"),
258276
resource.TestCheckResourceAttr(childDataResourceName, "table_collection.0.name", "test_table.test_child"),
259277
resource.TestCheckResourceAttr(childDataResourceName, "table_collection.0.state", "ACTIVE"),
260-
resource.TestCheckNoResourceAttr(childDataResourceName, "table_limits"),
278+
resource.TestCheckResourceAttr(childDataResourceName, "table_limits.#", "0"),
261279
),
262280
},
263281

@@ -276,7 +294,7 @@ func TestNosqlTableResource_test(t *testing.T) {
276294
resource.TestCheckResourceAttr(singularChildDatasourceName, "state", "ACTIVE"),
277295
resource.TestCheckResourceAttrSet(singularChildDatasourceName, "time_created"),
278296
resource.TestCheckResourceAttrSet(singularChildDatasourceName, "time_updated"),
279-
resource.TestCheckNoResourceAttr(singularChildDatasourceName, "table_limits"),
297+
resource.TestCheckResourceAttr(singularChildDatasourceName, "table_limits.#", "0"),
280298
),
281299
},
282300

internal/service/nosql/nosql_table_replica_resource.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ func (s *NosqlTableReplicaResourceCrud) Delete() error {
355355
}
356356

357357
func (s *NosqlTableReplicaResourceCrud) SetData() error {
358+
if s.Res == nil {
359+
return nil
360+
}
358361
region, tableNameOrId, err := parseTableReplicaCompositeId(s.D.Id())
359362
if err == nil {
360363
s.D.Set("region", &region)
@@ -391,8 +394,9 @@ func parseTableReplicaCompositeId(compositeId string) (region string, tableNameO
391394
}
392395

393396
func anyChangeSuppressFunction(k string, old string, new string, d *schema.ResourceData) bool {
394-
if old == "" && new != "" {
397+
if d.Id() == "" {
395398
return false
396399
}
400+
log.Printf("[INFO] Replica resource doesn't support update, ignoring change to %s, k=%s, old=%s, new=%s", d.Id(), k, old, new)
397401
return true
398402
}

internal/service/nosql/nosql_table_resource.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ func NosqlTableResource() *schema.Resource {
3333
Schema: map[string]*schema.Schema{
3434
// Required
3535
"compartment_id": {
36-
Type: schema.TypeString,
37-
Required: true,
36+
Type: schema.TypeString,
37+
Required: true,
38+
DiffSuppressFunc: compartmentIdSuppressFunction,
3839
},
3940
"ddl_statement": {
4041
Type: schema.TypeString,
@@ -1036,3 +1037,19 @@ func tableLimitsSuppressFunction(k string, old string, new string, d *schema.Res
10361037
}
10371038
return false
10381039
}
1040+
1041+
func compartmentIdSuppressFunction(k string, old string, new string, d *schema.ResourceData) bool {
1042+
if tableName, ok := d.GetOkExists("name"); ok {
1043+
/*
1044+
* Ignore changing compartmentId for child table
1045+
*/
1046+
if strings.Contains(tableName.(string), ".") {
1047+
if old != "" {
1048+
log.Printf(" Suppress compartmentId change to the child table %s from %s to %s",
1049+
tableName, old, new)
1050+
}
1051+
return (old != "")
1052+
}
1053+
}
1054+
return false
1055+
}

website/docs/r/nosql_table.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ resource "oci_nosql_table" "test_table" {
4242
The following arguments are supported:
4343

4444
* `compartment_id` - (Required) (Updatable) Compartment Identifier.
45-
* `ddl_statement` - (Required) (Updatable) Complete CREATE TABLE DDL statement. When update ddl_statement, it should be ALTER TABLE DDL statement.
45+
* `ddl_statement` - (Required) (Updatable) CREATE TABLE DDL statement. While updating an existing table, note that the column order should not be changed, and new columns can only be appended at the end of the table.
4646
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace": {"bar-key": "value"}}`
4747
* `freeform_tags` - (Optional) (Updatable) Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
4848
* `is_auto_reclaimable` - (Optional) True if table can be reclaimed after an idle period.

0 commit comments

Comments
 (0)