Skip to content

Commit d472e9a

Browse files
committed
Make size of volume updatable
1 parent 7340104 commit d472e9a

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

docs/core/volumes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ The following arguments support updates:
6666
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
6767
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
6868
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
69+
* `size_in_gbs` - The size of the volume in GBs.
6970

7071

7172
** IMPORTANT **

provider/core_volume_resource.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func VolumeResource() *schema.Resource {
6767
Type: schema.TypeString,
6868
Optional: true,
6969
Computed: true,
70-
ForceNew: true,
7170
ValidateFunc: validateInt64TypeString,
7271
DiffSuppressFunc: int64StringDiffSuppressFunction,
7372
},
@@ -209,6 +208,18 @@ func (s *VolumeResourceCrud) DeletedTarget() []string {
209208
}
210209
}
211210

211+
func (s *VolumeResourceCrud) UpdatedPending() []string {
212+
return []string{
213+
string(oci_core.VolumeLifecycleStateProvisioning),
214+
}
215+
}
216+
217+
func (s *VolumeResourceCrud) UpdatedTarget() []string {
218+
return []string{
219+
string(oci_core.VolumeLifecycleStateAvailable),
220+
}
221+
}
222+
212223
func (s *VolumeResourceCrud) Create() error {
213224
request := oci_core.CreateVolumeRequest{}
214225

@@ -331,6 +342,15 @@ func (s *VolumeResourceCrud) Update() error {
331342
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
332343
}
333344

345+
if sizeInGBs, ok := s.D.GetOkExists("size_in_gbs"); ok {
346+
tmp := sizeInGBs.(string)
347+
tmpInt64, err := strconv.ParseInt(tmp, 10, 64)
348+
if err != nil {
349+
return fmt.Errorf("unable to convert sizeInGBs string: %s to an int64 and encountered error: %v", tmp, err)
350+
}
351+
request.SizeInGBs = &tmpInt64
352+
}
353+
334354
tmp := s.D.Id()
335355
request.VolumeId = &tmp
336356

provider/core_volume_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestCoreVolumeResource_basic(t *testing.T) {
149149
variable "volume_defined_tags_value" { default = "updatedValue" }
150150
variable "volume_display_name" { default = "displayName2" }
151151
variable "volume_freeform_tags" { default = {"Department"= "Accounting"} }
152-
variable "volume_size_in_gbs" { default = 51 }
152+
variable "volume_size_in_gbs" { default = 52 }
153153
variable "volume_source_details_type" { default = "volume" }
154154
variable "volume_state" { default = "AVAILABLE" }
155155
@@ -162,8 +162,8 @@ variable "volume_state" { default = "AVAILABLE" }
162162
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName2"),
163163
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
164164
resource.TestCheckResourceAttrSet(resourceName, "id"),
165-
resource.TestCheckResourceAttr(resourceName, "size_in_gbs", "51"),
166-
resource.TestCheckResourceAttr(resourceName, "size_in_mbs", "52224"),
165+
resource.TestCheckResourceAttr(resourceName, "size_in_gbs", "52"),
166+
resource.TestCheckResourceAttr(resourceName, "size_in_mbs", "53248"),
167167
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
168168
resource.TestCheckResourceAttr(resourceName, "source_details.0.type", "volume"),
169169
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -186,7 +186,7 @@ variable "volume_state" { default = "AVAILABLE" }
186186
variable "volume_defined_tags_value" { default = "updatedValue" }
187187
variable "volume_display_name" { default = "displayName2" }
188188
variable "volume_freeform_tags" { default = {"Department"= "Accounting"} }
189-
variable "volume_size_in_gbs" { default = 51 }
189+
variable "volume_size_in_gbs" { default = 52 }
190190
variable "volume_source_details_type" { default = "volume" }
191191
variable "volume_state" { default = "AVAILABLE" }
192192
@@ -221,8 +221,8 @@ data "oci_core_volumes" "test_volumes" {
221221
resource.TestCheckResourceAttr(datasourceName, "volumes.0.display_name", "displayName2"),
222222
resource.TestCheckResourceAttr(datasourceName, "volumes.0.freeform_tags.%", "1"),
223223
resource.TestCheckResourceAttrSet(datasourceName, "volumes.0.id"),
224-
resource.TestCheckResourceAttr(datasourceName, "volumes.0.size_in_gbs", "51"),
225-
resource.TestCheckResourceAttr(datasourceName, "volumes.0.size_in_mbs", "52224"),
224+
resource.TestCheckResourceAttr(datasourceName, "volumes.0.size_in_gbs", "52"),
225+
resource.TestCheckResourceAttr(datasourceName, "volumes.0.size_in_mbs", "53248"),
226226
resource.TestCheckResourceAttrSet(datasourceName, "volumes.0.state"),
227227
resource.TestCheckResourceAttrSet(datasourceName, "volumes.0.time_created"),
228228
),

website/docs/r/core_volume.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The following arguments are supported:
5858
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`
5959
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
6060
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
61-
* `size_in_gbs` - (Optional) The size of the volume in GBs.
61+
* `size_in_gbs` - (Optional) (Updatable) The size of the volume in GBs.
6262
* `size_in_mbs` - (Optional) The size of the volume in MBs. The value must be a multiple of 1024. This field is deprecated. Use `size_in_gbs` instead.
6363
* `source_details` - (Optional) Specifies the volume source details for a new Block volume. The volume source is either another Block volume in the same Availability Domain or a Block volume backup. This is an optional field. If not specified or set to null, the new Block volume will be empty. When specified, the new Block volume will contain data from the source volume or backup.
6464
* `id` - (Required) The OCID of the volume or volume backup.

0 commit comments

Comments
 (0)