Skip to content

Commit

Permalink
add port to volume datasource, make port readonly for volume re…
Browse files Browse the repository at this point in the history
…source, add docs
  • Loading branch information
0x4c6565 committed Jul 15, 2024
1 parent 1ca9e04 commit 73fa9ea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/data-sources/ecloud_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data "ecloud_volume" "volume-1" {
- `capacity`: Capacity of volume
- `iops`: IOPs of volume
- `volume_group_id`: ID of volume volumegroup
- `port`: Port number of volume (when member of a volume group)

## Attributes Reference

Expand All @@ -29,4 +30,5 @@ data "ecloud_volume" "volume-1" {
- `availability_zone_id`: ID of volume availability zone
- `capacity`: Capacity of volume
- `iops`: IOPs of volume
- `volume_group_id`: ID of volume volumegroup
- `volume_group_id`: ID of volume volumegroup
- `port`: Port number of volume (when member of a volume group)
3 changes: 2 additions & 1 deletion docs/resources/ecloud_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ resource "ecloud_volume" "volume-1" {
- `name`: Name of volume
- `capacity`: Volume size in GiB
- `iops`: IOPS of volume
- `volume_group_id`: ID of the volumegroup that the volume is a member of
- `volume_group_id`: ID of the volume group that the volume is a member of
- `port`: Port number of volume (when member of a volume group)
8 changes: 8 additions & 0 deletions ecloud/data_source_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func dataSourceVolume() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"port": {
Type: schema.TypeInt,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -73,6 +77,9 @@ func dataSourceVolumeRead(ctx context.Context, d *schema.ResourceData, meta inte
if volumeGroupID, ok := d.GetOk("volume_group_id"); ok {
params.WithFilter(*connection.NewAPIRequestFiltering("volume_group_id", connection.EQOperator, []string{volumeGroupID.(string)}))
}
if port, ok := d.GetOk("port"); ok {
params.WithFilter(*connection.NewAPIRequestFiltering("port", connection.EQOperator, []string{strconv.Itoa(port.(int))}))
}

volumes, err := service.GetVolumes(params)
if err != nil {
Expand All @@ -94,6 +101,7 @@ func dataSourceVolumeRead(ctx context.Context, d *schema.ResourceData, meta inte
d.Set("vpc_id", volumes[0].VPCID)
d.Set("availability_zone_id", volumes[0].AvailabilityZoneID)
d.Set("volume_group_id", volumes[0].VolumeGroupID)
d.Set("port", volumes[0].Port)

return nil
}
1 change: 0 additions & 1 deletion ecloud/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func resourceVolume() *schema.Resource {
},
"port": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
},
Expand Down

0 comments on commit 73fa9ea

Please sign in to comment.