Skip to content

Commit

Permalink
add support for specifying volume storage type
Browse files Browse the repository at this point in the history
  • Loading branch information
theocod3s committed Sep 12, 2023
1 parent 654aeed commit 0f58aaf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "genesiscloud_instance" "example" {
- `region` (String) The region identifier.
- If the value of this attribute changes, Terraform will destroy and recreate the resource.
- The value must be one of: [`ARC-IS-HAF-1` `EUC-DE-MUC-1` `NORD-NO-KRS-1`].
- `type` (String) The instance type identifier.[Learn more about instance types here](https://developers.genesiscloud.com/instances#instance-types)
- `type` (String) The instance type identifier. Learn more about instance types [here](https://developers.genesiscloud.com/instances#instance-types).
- If the value of this attribute changes, Terraform will destroy and recreate the resource.

### Optional
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ resource "genesiscloud_volume" "example" {
- `size` (Number) The storage size of this volume given in GiB.
- If the value of this attribute changes, Terraform will destroy and recreate the resource.
- The value must be at least 1.
- `type` (String) The storage type of the volume.
- If the value of this attribute changes, Terraform will destroy and recreate the resource.
- The value must be one of: [`hdd` `ssd`].

### Optional

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
},
}),
"type": resourceenhancer.Attribute(ctx, schema.StringAttribute{
MarkdownDescription: "The instance type identifier.[Learn more about instance types here](https://developers.genesiscloud.com/instances#instance-types)",
MarkdownDescription: "The instance type identifier. Learn more about instance types [here](https://developers.genesiscloud.com/instances#instance-types).",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
Expand Down
11 changes: 11 additions & 0 deletions internal/provider/volume_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func (r *VolumeResource) Schema(ctx context.Context, req resource.SchemaRequest,
stringplanmodifier.UseStateForUnknown(), // immutable
},
}),
"type": resourceenhancer.Attribute(ctx, schema.StringAttribute{
MarkdownDescription: "The storage type of the volume.",
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Validators: []validator.String{
stringvalidator.OneOf(sliceStringify(genesiscloud.AllVolumeTypes)...),
},
}),

// Internal
"retain_on_delete": resourceenhancer.Attribute(ctx, schema.BoolAttribute{
Expand Down Expand Up @@ -151,6 +161,7 @@ func (r *VolumeResource) Create(ctx context.Context, req resource.CreateRequest,
body.Name = data.Name.ValueString()
body.Region = genesiscloud.Region(data.Region.ValueString())
body.Size = int(data.Size.ValueInt64())
body.Type = pointer(genesiscloud.VolumeType(data.Type.ValueString()))

response, err := r.client.CreateVolumeWithResponse(ctx, body)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/volume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type VolumeModel struct {

// Status The volume status.
Status types.String `tfsdk:"status"`

// Type The storage type of the volume.
Type types.String `tfsdk:"type"`
}

func (data *VolumeModel) PopulateFromClientResponse(ctx context.Context, volume *genesiscloud.Volume) (diag diag.Diagnostics) {
Expand All @@ -39,6 +42,7 @@ func (data *VolumeModel) PopulateFromClientResponse(ctx context.Context, volume
data.Region = types.StringValue(string(volume.Region))
data.Size = types.Int64Value(int64(volume.Size))
data.Status = types.StringValue(string(volume.Status))
data.Type = types.StringValue(string(volume.Type))

return
}

0 comments on commit 0f58aaf

Please sign in to comment.