Skip to content

Commit e38f47a

Browse files
committed
bugfix for shape_config missing error for update_instance_request if only shape is changed
1 parent 9a93582 commit e38f47a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

oci/core_instance_resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,16 @@ func (s *CoreInstanceResourceCrud) updateOptionsViaWorkRequest() error {
18601860
if newRaw != "" && oldRaw != "" {
18611861
shapeTmp := shape.(string)
18621862
request.Shape = &shapeTmp
1863+
if shapeConfig, ok := s.D.GetOkExists("shape_config"); ok && !s.D.HasChange("shape_config") {
1864+
if tmpList := shapeConfig.([]interface{}); len(tmpList) > 0 {
1865+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "shape_config", 0)
1866+
tmp, err := s.mapToUpdateInstanceShapeConfigDetails(fieldKeyFormat)
1867+
if err != nil {
1868+
return err
1869+
}
1870+
request.ShapeConfig = &tmp
1871+
}
1872+
}
18631873
}
18641874
}
18651875

oci/core_instance_resource_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ var (
4343
"ocpus": Representation{repType: Optional, create: "2"},
4444
"memory_in_gbs": Representation{repType: Optional, create: `10.0`, update: `20.0`},
4545
}
46+
instanceShapeConfigRepresentation_ForFlexibleMemoryNoUpdate = map[string]interface{}{
47+
"ocpus": Representation{repType: Optional, create: "2"},
48+
"memory_in_gbs": Representation{repType: Optional, create: `10.0`, update: `20.0`},
49+
}
50+
instanceRepresentationCore_ForFlexibleMemoryNoUpdate = representationCopyWithRemovedProperties(representationCopyWithNewProperties(instanceRepresentation, map[string]interface{}{
51+
"fault_domain": Representation{repType: Optional, create: `FAULT-DOMAIN-3`, update: `FAULT-DOMAIN-2`},
52+
"shape": Representation{repType: Required, create: `VM.Standard.E3.Flex`},
53+
"image": Representation{repType: Required, create: `${var.FlexInstanceImageOCID[var.region]}`},
54+
"shape_config": RepresentationGroup{Optional, instanceShapeConfigRepresentation_ForFlexibleMemoryNoUpdate},
55+
"source_details": RepresentationGroup{Optional, instanceFlexSourceDetailsRepresentation},
56+
}), []string{
57+
"dedicated_vm_host_id",
58+
})
4659
instanceLaunchOptionsRepresentation_ForLaunchOptionsUpdate = representationCopyWithNewProperties(instanceLaunchOptionsRepresentation, map[string]interface{}{
4760
"boot_volume_type": Representation{repType: Optional, create: `ISCSI`, update: `PARAVIRTUALIZED`},
4861
"is_pv_encryption_in_transit_enabled": Representation{repType: Optional, update: `true`},
@@ -1774,6 +1787,58 @@ func TestAccResourceCoreInstance_FlexibleMemory(t *testing.T) {
17741787
),
17751788
},
17761789

1790+
// verify updates to updatable parameters but no change in shape_config
1791+
{
1792+
Config: config + compartmentIdVariableStr + InstanceResourceDependenciesWithoutDHV + FlexVmImageIdsVariable +
1793+
generateResourceFromRepresentationMap("oci_core_instance", "test_instance", Optional, Update, instanceRepresentationCore_ForFlexibleMemoryNoUpdate),
1794+
Check: resource.ComposeAggregateTestCheckFunc(
1795+
resource.TestCheckResourceAttr(resourceName, "agent_config.#", "1"),
1796+
resource.TestCheckResourceAttr(resourceName, "agent_config.0.is_management_disabled", "true"),
1797+
resource.TestCheckResourceAttr(resourceName, "agent_config.0.is_monitoring_disabled", "true"),
1798+
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
1799+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
1800+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.#", "1"),
1801+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.assign_public_ip", "true"),
1802+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.defined_tags.%", "1"),
1803+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.display_name", "displayName"),
1804+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.freeform_tags.%", "1"),
1805+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.hostname_label", "hostnamelabel"),
1806+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.nsg_ids.#", "0"),
1807+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.private_ip", "10.0.0.5"),
1808+
resource.TestCheckResourceAttr(resourceName, "create_vnic_details.0.skip_source_dest_check", "false"),
1809+
resource.TestCheckResourceAttrSet(resourceName, "create_vnic_details.0.subnet_id"),
1810+
resource.TestCheckResourceAttr(resourceName, "defined_tags.%", "1"),
1811+
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
1812+
resource.TestCheckResourceAttr(resourceName, "extended_metadata.%", "3"),
1813+
resource.TestCheckResourceAttr(resourceName, "fault_domain", "FAULT-DOMAIN-2"),
1814+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
1815+
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnamelabel"),
1816+
resource.TestCheckResourceAttrSet(resourceName, "id"),
1817+
resource.TestCheckResourceAttrSet(resourceName, "image"),
1818+
resource.TestCheckResourceAttr(resourceName, "ipxe_script", "ipxeScript"),
1819+
resource.TestCheckResourceAttr(resourceName, "is_pv_encryption_in_transit_enabled", "false"),
1820+
resource.TestCheckResourceAttr(resourceName, "metadata.%", "2"),
1821+
resource.TestCheckResourceAttrSet(resourceName, "region"),
1822+
resource.TestCheckResourceAttr(resourceName, "shape", "VM.Standard.E3.Flex"),
1823+
resource.TestCheckResourceAttr(resourceName, "shape_config.#", "1"),
1824+
resource.TestCheckResourceAttr(resourceName, "shape_config.0.memory_in_gbs", "20"),
1825+
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
1826+
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
1827+
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
1828+
resource.TestCheckResourceAttr(resourceName, "state", "RUNNING"),
1829+
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
1830+
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
1831+
1832+
func(s *terraform.State) (err error) {
1833+
resId2, err = fromInstanceState(s, resourceName, "id")
1834+
if resId != resId2 {
1835+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
1836+
}
1837+
return err
1838+
},
1839+
),
1840+
},
1841+
17771842
// verify updates to updatable parameters
17781843
{
17791844
Config: config + compartmentIdVariableStr + InstanceResourceDependenciesWithoutDHV + FlexVmImageIdsVariable +
@@ -1825,6 +1890,7 @@ func TestAccResourceCoreInstance_FlexibleMemory(t *testing.T) {
18251890
},
18261891
),
18271892
},
1893+
18281894
// verify datasource
18291895
{
18301896
Config: config +

0 commit comments

Comments
 (0)