Skip to content

Commit 56bd760

Browse files
kilokahnalexng-canuck
authored andcommitted
Update tests for volume resizing
1 parent 7b6ac8f commit 56bd760

File tree

5 files changed

+52
-31
lines changed

5 files changed

+52
-31
lines changed

docs/core/volumes.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
The following attributes are exported:
88

9-
* `availability_domain` - The Availability Domain of the volume. Example: `Uocm:PHX-AD-1`
9+
* `availability_domain` - The availability domain of the volume. Example: `Uocm:PHX-AD-1`
1010
* `compartment_id` - The OCID of the compartment that contains the volume.
1111
* `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"}`
1212
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
@@ -15,7 +15,7 @@ The following attributes are exported:
1515
* `is_hydrated` - Specifies whether the cloned volume's data has finished copying from the source volume or backup.
1616
* `size_in_gbs` - The size of the volume in GBs.
1717
* `size_in_mbs` - The size of the volume in MBs. This field is deprecated. Use `size_in_gbs` instead.
18-
* `source_details` - The volume source, either an existing volume in the same Availability Domain or a volume backup. If null, an empty volume is created.
18+
* `source_details` - The volume source, either an existing volume in the same availability domain or a volume backup. If null, an empty volume is created.
1919
* `id` - The OCID of the volume or volume backup.
2020
* `type` - The type of volume source. It should be set to either `volumeBackup` or `volume`.
2121
* `state` - The current state of a volume.
@@ -30,11 +30,11 @@ Creates a new volume in the specified compartment. Volumes can be created in siz
3030
For general information about block volumes, see
3131
[Overview of Block Volume Service](https://docs.us-phoenix-1.oraclecloud.com/Content/Block/Concepts/overview.htm).
3232

33-
A volume and instance can be in separate compartments but must be in the same Availability Domain.
33+
A volume and instance can be in separate compartments but must be in the same availability domain.
3434
For information about access control and compartments, see
3535
[Overview of the IAM Service](https://docs.us-phoenix-1.oraclecloud.com/Content/Identity/Concepts/overview.htm). For information about
36-
Availability Domains, see [Regions and Availability Domains](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/regions.htm).
37-
To get a list of Availability Domains, use the `ListAvailabilityDomains` operation
36+
availability domains, see [Regions and Availability Domains](https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/regions.htm).
37+
To get a list of availability domains, use the `ListAvailabilityDomains` operation
3838
in the Identity and Access Management Service API.
3939

4040
You may optionally specify a *display name* for the volume, which is simply a friendly name or
@@ -43,15 +43,15 @@ description. It does not have to be unique, and you can change it. Avoid enterin
4343

4444
The following arguments are supported:
4545

46-
* `availability_domain` - (Required) The Availability Domain of the volume. Example: `Uocm:PHX-AD-1`
46+
* `availability_domain` - (Required) The availability domain of the volume. Example: `Uocm:PHX-AD-1`
4747
* `backup_policy_id` - (Optional) If provided, specifies the ID of the volume backup policy to assign to the newly created volume. If omitted, no policy will be assigned.
4848
* `compartment_id` - (Required) The OCID of the compartment that contains the volume.
4949
* `defined_tags` - (Optional) 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"}`
5050
* `display_name` - (Optional) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
5151
* `freeform_tags` - (Optional) 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"}`
5252
* `size_in_gbs` - (Optional) The size of the volume in GBs.
5353
* `size_in_mbs` - (Optional) The size of the volume in MBs. The value must be a multiple of 1024. This field is deprecated. Use sizeInGBs instead.
54-
* `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.
54+
* `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.
5555
* `id` - (Required) The OCID of the volume or volume backup.
5656
* `type` - (Required) The type of volume source. It should be set to either `volumeBackup` or `volume`.
5757
* `volume_backup_id` - (Optional) The OCID of the volume backup from which the data should be restored on the newly created volume. This field is deprecated. Use the `source_details` field instead to specify the backup for the volume.
@@ -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 **
@@ -101,11 +102,11 @@ resource "oci_core_volume" "test_volume" {
101102
Gets a list of volumes.
102103

103104
### List Operation
104-
Lists the volumes in the specified compartment and Availability Domain.
105+
Lists the volumes in the specified compartment and availability domain.
105106

106107
The following arguments are supported:
107108

108-
* `availability_domain` - (Optional) The name of the Availability Domain. Example: `Uocm:PHX-AD-1`
109+
* `availability_domain` - (Optional) The name of the availability domain. Example: `Uocm:PHX-AD-1`
109110
* `compartment_id` - (Required) The OCID of the compartment.
110111
* `display_name` - (Optional) A filter to return only resources that match the given display name exactly.
111112
* `state` - (Optional) A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.

oci/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

oci/core_volume_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ resource "oci_core_volume" "test_volume" {
4747
variable "volume_defined_tags_value" { default = "value" }
4848
variable "volume_display_name" { default = "displayName" }
4949
variable "volume_freeform_tags" { default = {"Department"= "Finance"} }
50-
variable "volume_size_in_gbs" { default = 50 }
50+
variable "volume_size_in_gbs" { default = 51 }
5151
variable "volume_source_details_type" { default = "volume" }
5252
variable "volume_state" { default = "AVAILABLE" }
5353
@@ -127,8 +127,8 @@ func TestCoreVolumeResource_basic(t *testing.T) {
127127
resource.TestCheckResourceAttr(resourceName, "display_name", "displayName"),
128128
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
129129
resource.TestCheckResourceAttrSet(resourceName, "id"),
130-
resource.TestCheckResourceAttr(resourceName, "size_in_gbs", "50"),
131-
resource.TestCheckResourceAttr(resourceName, "size_in_mbs", "51200"),
130+
resource.TestCheckResourceAttr(resourceName, "size_in_gbs", "51"),
131+
resource.TestCheckResourceAttr(resourceName, "size_in_mbs", "52224"),
132132
resource.TestCheckResourceAttr(resourceName, "source_details.#", "1"),
133133
resource.TestCheckResourceAttr(resourceName, "source_details.0.type", "volume"),
134134
resource.TestCheckResourceAttrSet(resourceName, "state"),
@@ -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 = 50 }
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", "50"),
166-
resource.TestCheckResourceAttr(resourceName, "size_in_mbs", "51200"),
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 = 50 }
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", "50"),
225-
resource.TestCheckResourceAttr(datasourceName, "volumes.0.size_in_mbs", "51200"),
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/d/core_volumes.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: |-
99
# Data Source: oci_core_volumes
1010
The `oci_core_volumes` data source allows access to the list of OCI volumes
1111

12-
Lists the volumes in the specified compartment and Availability Domain.
12+
Lists the volumes in the specified compartment and availability domain.
1313

1414

1515
## Example Usage
@@ -31,7 +31,7 @@ data "oci_core_volumes" "test_volumes" {
3131

3232
The following arguments are supported:
3333

34-
* `availability_domain` - (Optional) The name of the Availability Domain. Example: `Uocm:PHX-AD-1`
34+
* `availability_domain` - (Optional) The name of the availability domain. Example: `Uocm:PHX-AD-1`
3535
* `compartment_id` - (Required) The OCID of the compartment.
3636
* `display_name` - (Optional) A filter to return only resources that match the given display name exactly.
3737
* `state` - (Optional) A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
@@ -48,7 +48,7 @@ The following attributes are exported:
4848

4949
The following attributes are exported:
5050

51-
* `availability_domain` - The Availability Domain of the volume. Example: `Uocm:PHX-AD-1`
51+
* `availability_domain` - The availability domain of the volume. Example: `Uocm:PHX-AD-1`
5252
* `compartment_id` - The OCID of the compartment that contains the volume.
5353
* `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"}`
5454
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
@@ -57,7 +57,7 @@ The following attributes are exported:
5757
* `is_hydrated` - Specifies whether the cloned volume's data has finished copying from the source volume or backup.
5858
* `size_in_gbs` - The size of the volume in GBs.
5959
* `size_in_mbs` - The size of the volume in MBs. This field is deprecated. Use `size_in_gbs` instead.
60-
* `source_details` - The volume source, either an existing volume in the same Availability Domain or a volume backup. If null, an empty volume is created.
60+
* `source_details` - The volume source, either an existing volume in the same availability domain or a volume backup. If null, an empty volume is created.
6161
* `id` - The OCID of the volume or volume backup.
6262
* `type` - The type of volume source. It should be set to either `volumeBackup` or `volume`.
6363
* `state` - The current state of a volume.

0 commit comments

Comments
 (0)