Skip to content

Commit 4b1d7ea

Browse files
committed
Fix resize of bootVolume in instance for source_type=boot_volume
1 parent 3dc4b1a commit 4b1d7ea

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
- Support added for update Instance Console Connections
55
- Support added for `oci_core_public_ip_pool` resource and `byoip` data source
66

7+
### Fixed
8+
- Fix resizing of boot_volume in `oci_core_instance` resource for `source_type` bootVolume
9+
710
## 3.94.0 (September 23, 2020)
811

912
### Added

oci/core_instance_resource.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,32 +1762,16 @@ func (s *CoreInstanceResourceCrud) updateCompartment(compartment interface{}) er
17621762
}
17631763

17641764
func (s *CoreInstanceResourceCrud) mapToUpdateInstanceBootVolumeSizeInGbs(fieldKeyFormat string) error {
1765-
//discriminator
1766-
sourceTypeRaw, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "source_type"))
1767-
var sourceType string
1768-
if ok {
1769-
sourceType = sourceTypeRaw.(string)
1770-
} else {
1771-
sourceType = "" // default value
1772-
}
1773-
switch strings.ToLower(sourceType) {
1774-
case strings.ToLower("image"):
1775-
if bootVolumeSizeInGBs, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "boot_volume_size_in_gbs")); ok && s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "boot_volume_size_in_gbs")) {
1776-
oldRaw, newRaw := s.D.GetChange(fmt.Sprintf(fieldKeyFormat, "boot_volume_size_in_gbs"))
1777-
if newRaw != "" && oldRaw != "" {
1778-
tmp := bootVolumeSizeInGBs.(string)
1779-
tmpInt64, err := strconv.ParseInt(tmp, 10, 64)
1780-
if err != nil {
1781-
return fmt.Errorf("unable to convert bootVolumeSizeInGBs string: %s to an int64 and encountered error: %v", tmp, err)
1782-
}
1783-
err = s.updateBootVolumeSizeInGbs(tmpInt64)
1784-
if err != nil {
1785-
return err
1786-
}
1787-
}
1765+
if bootVolumeSizeInGBs, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "boot_volume_size_in_gbs")); ok && s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "boot_volume_size_in_gbs")) {
1766+
tmp := bootVolumeSizeInGBs.(string)
1767+
tmpInt64, err := strconv.ParseInt(tmp, 10, 64)
1768+
if err != nil {
1769+
return fmt.Errorf("unable to convert bootVolumeSizeInGBs string: %s to an int64 and encountered error: %v", tmp, err)
1770+
}
1771+
err = s.updateBootVolumeSizeInGbs(tmpInt64)
1772+
if err != nil {
1773+
return err
17881774
}
1789-
default:
1790-
return fmt.Errorf("unknown source_type '%v' was specified", sourceType)
17911775
}
17921776
return nil
17931777
}

oci/core_instance_resource_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,53 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_preserveBoot
956956
},
957957
),
958958
},
959+
// Verify updating boot_volume_size_in_gbs without recreating the instance
960+
{
961+
Config: s.Config + `
962+
resource "oci_core_instance" "t" {
963+
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
964+
compartment_id = "${var.compartment_id}"
965+
subnet_id = "${oci_core_subnet.t.id}"
966+
hostname_label = "hostname2"
967+
source_details {
968+
source_type = "bootVolume"
969+
source_id = "{{.preservedBootVolumeId}}"
970+
boot_volume_size_in_gbs = "60"
971+
}
972+
preserve_boot_volume = "false"
973+
shape = "VM.Standard2.1"
974+
metadata = {
975+
ssh_authorized_keys = "${var.ssh_public_key}"
976+
user_data = "ZWNobyBoZWxsbw=="
977+
}
978+
timeouts {
979+
create = "15m"
980+
}
981+
}`,
982+
Check: resource.ComposeAggregateTestCheckFunc(
983+
resource.TestCheckResourceAttr(s.ResourceName, "preserve_boot_volume", "false"),
984+
resource.TestCheckResourceAttr(s.ResourceName, "source_details.0.boot_volume_size_in_gbs", "60"),
985+
// Verify that we got a new Instance
986+
func(ts *terraform.State) (err error) {
987+
newId, err := fromInstanceState(ts, s.ResourceName, "id")
988+
if newId != instanceId {
989+
return fmt.Errorf("expected same instance ocid, got different")
990+
}
991+
992+
instanceId = newId
993+
return err
994+
},
995+
// Verify that the boot volume attachment is the same as the preserved boot volume
996+
func(ts *terraform.State) (err error) {
997+
volumeId, err := fromInstanceState(ts, s.ResourceName, "boot_volume_id")
998+
if preservedBootVolumeId != volumeId {
999+
return fmt.Errorf("expected attached boot volume ID to be same as preserved boot volume, got different one")
1000+
}
1001+
1002+
return err
1003+
},
1004+
),
1005+
},
9591006
// to verify reattaching to the old boot volume resource should be terminated before the waiting for boot volume condition
9601007
{
9611008
Config: s.Config,

oci/core_instance_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ var (
100100
"remote_data_volume_type": Representation{repType: Optional, create: `PARAVIRTUALIZED`},
101101
}
102102
instanceSourceDetailsRepresentation = map[string]interface{}{
103-
"source_id": Representation{repType: Required, create: `${var.InstanceImageOCID[var.region]}`},
104-
"source_type": Representation{repType: Required, create: `image`},
105-
"kms_key_id": Representation{repType: Optional, create: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
103+
"source_id": Representation{repType: Required, create: `${var.InstanceImageOCID[var.region]}`},
104+
"source_type": Representation{repType: Required, create: `image`},
105+
"kms_key_id": Representation{repType: Optional, create: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
106+
"boot_volume_size_in_gbs": Representation{repType: Optional, create: `60`, update: `70`},
106107
}
107108

108109
InstanceWithPVEncryptionInTransitEnabled = `
@@ -277,6 +278,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
277278
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
278279
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
279280
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
281+
resource.TestCheckResourceAttr(resourceName, "source_details.0.boot_volume_size_in_gbs", "60"),
280282
resource.TestCheckResourceAttr(resourceName, "state", "STOPPED"),
281283
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
282284
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -343,6 +345,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
343345
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
344346
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
345347
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
348+
resource.TestCheckResourceAttr(resourceName, "source_details.0.boot_volume_size_in_gbs", "60"),
346349
resource.TestCheckResourceAttr(resourceName, "state", "STOPPED"),
347350
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
348351
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -405,6 +408,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
405408
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
406409
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
407410
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
411+
resource.TestCheckResourceAttr(resourceName, "source_details.0.boot_volume_size_in_gbs", "70"),
408412
resource.TestCheckResourceAttr(resourceName, "state", "RUNNING"),
409413
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
410414
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
@@ -519,6 +523,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
519523
resource.TestCheckResourceAttrSet(singularDatasourceName, "shape_config.0.processor_description"),
520524
resource.TestCheckResourceAttr(singularDatasourceName, "source_details.#", "1"),
521525
resource.TestCheckResourceAttr(singularDatasourceName, "source_details.0.source_type", "image"),
526+
resource.TestCheckResourceAttr(resourceName, "source_details.0.boot_volume_size_in_gbs", "70"),
522527
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
523528
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
524529

@@ -530,7 +535,10 @@ func TestCoreInstanceResource_basic(t *testing.T) {
530535
// verify updates to original parameters
531536
{
532537
Config: config + compartmentIdVariableStr + InstanceResourceDependencies +
533-
generateResourceFromRepresentationMap("oci_core_instance", "test_instance", Optional, Create, instanceRepresentation),
538+
generateResourceFromRepresentationMap("oci_core_instance", "test_instance", Optional, Create,
539+
getUpdatedRepresentationCopy("source_details", RepresentationGroup{Optional,
540+
representationCopyWithRemovedProperties(instanceSourceDetailsRepresentation, []string{"boot_volume_size_in_gbs"})},
541+
instanceRepresentation)),
534542
Check: resource.ComposeAggregateTestCheckFunc(
535543
resource.TestCheckResourceAttr(resourceName, "agent_config.#", "1"),
536544
resource.TestCheckResourceAttr(resourceName, "agent_config.0.is_monitoring_disabled", "false"),
@@ -561,6 +569,7 @@ func TestCoreInstanceResource_basic(t *testing.T) {
561569
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
562570
resource.TestCheckResourceAttrSet(resourceName, "source_details.0.source_id"),
563571
resource.TestCheckResourceAttr(resourceName, "source_details.0.source_type", "image"),
572+
resource.TestCheckResourceAttr(resourceName, "source_details.0.boot_volume_size_in_gbs", "70"),
564573
resource.TestCheckResourceAttr(resourceName, "state", "STOPPED"),
565574
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
566575
resource.TestCheckResourceAttrSet(resourceName, "time_created"),

0 commit comments

Comments
 (0)