Skip to content

Commit 2d6ac83

Browse files
authored
added storage_generation attribute to is_volume (IBM-Cloud#6413)
* added storage_generation attribute to is_volume * added acceptance tests
1 parent b897760 commit 2d6ac83

9 files changed

+212
-1
lines changed

ibm/service/vpc/data_source_ibm_is_volume.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ func DataSourceIBMISVolume() *schema.Resource {
169169
Description: "IOPS value for the Volume",
170170
},
171171

172+
"storage_generation": {
173+
Type: schema.TypeInt,
174+
Computed: true,
175+
Description: "storage_generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1.",
176+
},
177+
172178
isVolumeCrn: {
173179
Type: schema.TypeString,
174180
Computed: true,
@@ -479,6 +485,11 @@ func volumeGet(context context.Context, d *schema.ResourceData, meta interface{}
479485
if err = d.Set("iops", flex.IntValue(volume.Iops)); err != nil {
480486
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting iops: %s", err), "(Data) ibm_is_volume", "read", "set-iops").GetDiag()
481487
}
488+
489+
if err = d.Set("storage_generation", flex.IntValue(volume.StorageGeneration)); err != nil {
490+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting storage_generation: %s", err), "(Data) ibm_is_volume", "read", "set-storage_generation").GetDiag()
491+
}
492+
482493
if err = d.Set("capacity", flex.IntValue(volume.Capacity)); err != nil {
483494
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting capacity: %s", err), "(Data) ibm_is_volume", "read", "set-capacity").GetDiag()
484495
}

ibm/service/vpc/data_source_ibm_is_volume_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,91 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
206206
},
207207
})
208208
}
209+
func TestAccIBMISVolumeDatasource_storage_generation(t *testing.T) {
210+
211+
resName := "data.ibm_is_volume.testacc_dsvol"
212+
resName1 := "data.ibm_is_volume.testacc_dsvolid"
213+
resName2 := "data.ibm_is_volume.testacc_dsvol2"
214+
resName3 := "data.ibm_is_volume.testacc_dsvol2id"
215+
name := fmt.Sprintf("tf-vol-%d", acctest.RandIntRange(10, 100))
216+
name1 := fmt.Sprintf("tf-vol2-%d", acctest.RandIntRange(10, 100))
217+
218+
resource.Test(t, resource.TestCase{
219+
PreCheck: func() { acc.TestAccPreCheck(t) },
220+
Providers: acc.TestAccProviders,
221+
Steps: []resource.TestStep{
222+
{
223+
Config: testAccCheckIBMISVolumeDataSourceStorageGeneration(name, name1),
224+
Check: resource.ComposeTestCheckFunc(
225+
resource.TestCheckResourceAttrSet(
226+
resName, "active"),
227+
resource.TestCheckResourceAttrSet(
228+
resName, "attachment_state"),
229+
resource.TestCheckResourceAttrSet(
230+
resName, "bandwidth"),
231+
resource.TestCheckResourceAttrSet(
232+
resName, "busy"),
233+
resource.TestCheckResourceAttrSet(
234+
resName, "created_at"),
235+
resource.TestCheckResourceAttrSet(
236+
resName, "resource_group"),
237+
resource.TestCheckResourceAttrSet(
238+
resName, "profile"),
239+
resource.TestCheckResourceAttrSet(
240+
resName, "storage_generation"),
241+
resource.TestCheckResourceAttrSet(
242+
resName1, "active"),
243+
resource.TestCheckResourceAttrSet(
244+
resName1, "attachment_state"),
245+
resource.TestCheckResourceAttrSet(
246+
resName1, "bandwidth"),
247+
resource.TestCheckResourceAttrSet(
248+
resName1, "busy"),
249+
resource.TestCheckResourceAttrSet(
250+
resName1, "created_at"),
251+
resource.TestCheckResourceAttrSet(
252+
resName1, "resource_group"),
253+
resource.TestCheckResourceAttrSet(
254+
resName1, "profile"),
255+
resource.TestCheckResourceAttrSet(
256+
resName1, "storage_generation"),
257+
resource.TestCheckResourceAttrSet(
258+
resName2, "active"),
259+
resource.TestCheckResourceAttrSet(
260+
resName2, "attachment_state"),
261+
resource.TestCheckResourceAttrSet(
262+
resName2, "bandwidth"),
263+
resource.TestCheckResourceAttrSet(
264+
resName2, "busy"),
265+
resource.TestCheckResourceAttrSet(
266+
resName2, "created_at"),
267+
resource.TestCheckResourceAttrSet(
268+
resName2, "resource_group"),
269+
resource.TestCheckResourceAttrSet(
270+
resName2, "profile"),
271+
resource.TestCheckResourceAttrSet(
272+
resName2, "storage_generation"),
273+
resource.TestCheckResourceAttrSet(
274+
resName3, "active"),
275+
resource.TestCheckResourceAttrSet(
276+
resName3, "attachment_state"),
277+
resource.TestCheckResourceAttrSet(
278+
resName3, "bandwidth"),
279+
resource.TestCheckResourceAttrSet(
280+
resName3, "busy"),
281+
resource.TestCheckResourceAttrSet(
282+
resName3, "created_at"),
283+
resource.TestCheckResourceAttrSet(
284+
resName3, "resource_group"),
285+
resource.TestCheckResourceAttrSet(
286+
resName3, "profile"),
287+
resource.TestCheckResourceAttrSet(
288+
resName3, "storage_generation"),
289+
),
290+
},
291+
},
292+
})
293+
}
209294
func TestAccIBMISVolumeDatasourceWithCatalogOffering(t *testing.T) {
210295

211296
resName := "data.ibm_is_volume.testacc_dsvol"
@@ -244,6 +329,24 @@ func testAccCheckIBMISVolumeDataSourceFromSnapshotConfig(vpcname, subnetname, ss
244329
name = ibm_is_volume.storage.name
245330
}`)
246331
}
332+
func testAccCheckIBMISVolumeDataSourceStorageGeneration(name, name1 string) string {
333+
return testAccCheckIBMISVolumeStorageConfig(name, name1) + fmt.Sprintf(`
334+
335+
data "ibm_is_volume" "testacc_dsvol" {
336+
name = ibm_is_volume.storage.name
337+
}
338+
data "ibm_is_volume" "testacc_dsvolid" {
339+
identifier = ibm_is_volume.storage2.id
340+
}
341+
data "ibm_is_volume" "testacc_dsvol2" {
342+
name = ibm_is_volume.storage.name
343+
}
344+
data "ibm_is_volume" "testacc_dsvol2id" {
345+
identifier = ibm_is_volume.storage2.id
346+
}
347+
348+
`)
349+
}
247350
func testAccCheckIBMISVolumeDataSourceConfig(name, zone string) string {
248351
return fmt.Sprintf(`
249352
resource "ibm_is_volume" "testacc_volume"{

ibm/service/vpc/data_source_ibm_is_volumes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ func DataSourceIBMIsVolumes() *schema.Resource {
411411
Type: schema.TypeString,
412412
},
413413
},
414+
"storage_generation": {
415+
Type: schema.TypeInt,
416+
Computed: true,
417+
Description: "storage_generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1.",
418+
},
414419
isVolumesStatus: &schema.Schema{
415420
Type: schema.TypeString,
416421
Computed: true,
@@ -799,6 +804,9 @@ func dataSourceVolumeCollectionVolumesToMap(volumesItem vpcv1.Volume, meta inter
799804
if volumesItem.Iops != nil {
800805
volumesMap[isVolumesIops] = volumesItem.Iops
801806
}
807+
if volumesItem.StorageGeneration != nil {
808+
volumesMap["storage_generation"] = volumesItem.StorageGeneration
809+
}
802810
if volumesItem.Name != nil {
803811
volumesMap[isVolumesName] = volumesItem.Name
804812
}

ibm/service/vpc/data_source_ibm_is_volumes_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ func TestAccIBMIsVolumesDataSourceSdpBasic(t *testing.T) {
6060
},
6161
})
6262
}
63+
func TestAccIBMIsVolumesDataSourceStorageGenerationBasic(t *testing.T) {
64+
name := fmt.Sprintf("tf-vol-%d", acctest.RandIntRange(10, 100))
65+
name1 := fmt.Sprintf("tf-vol2-%d", acctest.RandIntRange(10, 100))
66+
resource.Test(t, resource.TestCase{
67+
PreCheck: func() { acc.TestAccPreCheck(t) },
68+
Providers: acc.TestAccProviders,
69+
Steps: []resource.TestStep{
70+
resource.TestStep{
71+
Config: testAccCheckIBMIsVolumesDataSourceStorageGenerationConfig(name, name1),
72+
Check: resource.ComposeTestCheckFunc(
73+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "id"),
74+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "volumes.#"),
75+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "volumes.0.name"),
76+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "volumes.0.storage_generation"),
77+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "volumes.1.name"),
78+
resource.TestCheckResourceAttrSet("data.ibm_is_volumes.is_volumes", "volumes.1.storage_generation"),
79+
),
80+
},
81+
},
82+
})
83+
}
6384
func TestAccIBMIsVolumesFromSnapshotDataSourceBasic(t *testing.T) {
6485
resName := "data.ibm_is_volumes.is_volumes"
6586
vpcname := fmt.Sprintf("tf-vpc-%d", acctest.RandIntRange(10, 100))
@@ -178,6 +199,13 @@ func testAccCheckIBMIsVolumesDataSourceSdpConfig() string {
178199
}
179200
`)
180201
}
202+
func testAccCheckIBMIsVolumesDataSourceStorageGenerationConfig(name, name1 string) string {
203+
return testAccCheckIBMISVolumeStorageConfig(name, name1) + fmt.Sprintf(`
204+
data "ibm_is_volumes" "is_volumes" {
205+
depends_on = [ibm_is_volume.storage, ibm_is_volume.storage2]
206+
}
207+
`)
208+
}
181209

182210
func testAccCheckIBMIsVolumesDataSourceConfigFilterByZone() string {
183211
return fmt.Sprintf(`

ibm/service/vpc/resource_ibm_is_volume.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func ResourceIBMISVolume() *schema.Resource {
130130
Computed: true,
131131
Description: "Volume encryption type info",
132132
},
133+
"storage_generation": {
134+
Type: schema.TypeInt,
135+
Computed: true,
136+
Description: "storage_generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1.",
137+
},
133138

134139
isVolumeCapacity: {
135140
Type: schema.TypeInt,
@@ -684,6 +689,9 @@ func volGet(context context.Context, d *schema.ResourceData, meta interface{}, i
684689
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_is_volume", "read", "set-name").GetDiag()
685690
}
686691
}
692+
if err = d.Set("storage_generation", flex.IntValue(volume.StorageGeneration)); err != nil {
693+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting storage_generation: %s", err), "(Data) ibm_is_volume", "read", "set-storage_generation").GetDiag()
694+
}
687695
if !core.IsNil(volume.Profile) {
688696
if err = d.Set("profile", *volume.Profile.Name); err != nil {
689697
err = fmt.Errorf("Error setting profile: %s", err)

ibm/service/vpc/resource_ibm_is_volume_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ func TestAccIBMISVolume_basic(t *testing.T) {
4848
},
4949
})
5050
}
51+
func TestAccIBMISVolume_storage_generation(t *testing.T) {
52+
var vol string
53+
name := fmt.Sprintf("tf-vol-%d", acctest.RandIntRange(10, 100))
54+
name1 := fmt.Sprintf("tf-vol-tier-%d", acctest.RandIntRange(10, 100))
55+
56+
resource.Test(t, resource.TestCase{
57+
PreCheck: func() { acc.TestAccPreCheck(t) },
58+
Providers: acc.TestAccProviders,
59+
CheckDestroy: testAccCheckIBMISVolumeDestroy,
60+
Steps: []resource.TestStep{
61+
{
62+
Config: testAccCheckIBMISVolumeStorageConfig(name, name1),
63+
Check: resource.ComposeTestCheckFunc(
64+
testAccCheckIBMISVolumeExists("ibm_is_volume.storage", vol),
65+
resource.TestCheckResourceAttr(
66+
"ibm_is_volume.storage", "name", name),
67+
resource.TestCheckResourceAttr(
68+
"ibm_is_volume.storage2", "name", name1),
69+
resource.TestCheckResourceAttrSet(
70+
"ibm_is_volume.storage", "storage_generation"),
71+
resource.TestCheckResourceAttrSet(
72+
"ibm_is_volume.storage2", "storage_generation"),
73+
resource.TestCheckResourceAttr(
74+
"ibm_is_volume.storage", "storage_generation", "1"),
75+
resource.TestCheckResourceAttr(
76+
"ibm_is_volume.storage2", "storage_generation", "2"),
77+
),
78+
},
79+
},
80+
})
81+
}
5182
func TestAccIBMISVolume_sdp(t *testing.T) {
5283
var vol string
5384
name := fmt.Sprintf("tf-vol-%d", acctest.RandIntRange(10, 100))
@@ -591,6 +622,25 @@ func testAccCheckIBMISVolumeConfig(name string) string {
591622
}
592623
`, name)
593624

625+
}
626+
func testAccCheckIBMISVolumeStorageConfig(name, name2 string) string {
627+
return fmt.Sprintf(
628+
`
629+
resource "ibm_is_volume" "storage"{
630+
name = "%s"
631+
profile = "10iops-tier"
632+
zone = "%s"
633+
# capacity= 200
634+
}
635+
resource "ibm_is_volume" "storage2"{
636+
name = "%s"
637+
profile = "sdp"
638+
zone = "%s"
639+
capacity = 100
640+
bandwidth = 6000
641+
}
642+
`, name, acc.ISZoneName, name2, acc.ISZoneName)
643+
594644
}
595645

596646
func testAccCheckIBMISVolumeSdpConfig(name string, capacity int) string {

website/docs/d/is_volume.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ In addition to all argument reference list, you can access the following attribu
111111
- `code` - (String) A snake case string identifying the status reason.
112112
- `message` - (String) An explanation of the status reason
113113
- `more_info` - (String) Link to documentation about this status reason
114+
- `storage_generation` - (Int) The storage generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1. For the sdp profile, this value is 2.
114115
- `tags` - (String) User Tags associated with the volume. (https://cloud.ibm.com/apidocs/tagging#types-of-tags)
115116
- `unattached_capacity_update_supported` - (Boolean) Indicates whether the capacity for the volume can be changed when not attached to a running virtual server instance.
116117
- `unattached_iops_update_supported` - (Boolean) Indicates whether the IOPS for the volume can be changed when not attached to a running virtual server instance.

website/docs/d/is_volumes.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ In addition to all argument references listed, you can access the following attr
143143
- `code` - (String) A snake case string succinctly identifying the status reason.
144144
- `message` - (String) An explanation of the status reason.
145145
- `more_info` - (Optional, String) Link to documentation about this status reason.
146+
- `storage_generation` - (Int) The storage generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1. For the sdp profile, this value is 2.
146147
- `tags` - (String) User Tags associated with the volume. (https://cloud.ibm.com/apidocs/tagging#types-of-tags)
147148
- `volume_attachments` - (List) The volume attachments for this volume.
148149
Nested scheme for **volume_attachments**:

website/docs/r/is_volume.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ In addition to all argument reference list, you can access the following attribu
156156

157157
Nested schema for `deleted`:
158158
- `more_info` - (String) Link to documentation about deleted resources.
159+
- `crn` - (String) The CRN for the volume.
159160
- `encryption_type` - (String) The type of encryption used in the volume [**provider_managed**, **user_managed**].
160161
- `health_reasons` - (List) The reasons for the current health_state (if any).
161162

@@ -172,7 +173,7 @@ In addition to all argument reference list, you can access the following attribu
172173
- `code` - (String) A string with an underscore as a special character identifying the status reason.
173174
- `message` - (String) An explanation of the status reason.
174175
- `more_info` - (String) Link to documentation about this status reason
175-
- `crn` - (String) The CRN for the volume.
176+
- `storage_generation` - (Int) The storage generation indicates which generation the profile family belongs to. For the custom and tiered profiles, this value is 1. For the sdp profile, this value is 2.
176177

177178
## Import
178179
The `ibm_is_volume` resource can be imported by using volume ID.

0 commit comments

Comments
 (0)