Skip to content

Commit 51f32c5

Browse files
authored
add diskSize to instance resource (#69)
1 parent 2836ead commit 51f32c5

File tree

7 files changed

+35
-2
lines changed

7 files changed

+35
-2
lines changed

docs/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ resource "genesiscloud_instance" "instance" {
114114
115115
floating_ip_id = genesiscloud_floating_ip.floating_ip.id
116116
117+
disk_size = 128
118+
117119
metadata = {
118120
startup_script = <<EOF
119121
#!/bin/bash

docs/resources/instance.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ resource "genesiscloud_instance" "example" {
4242

4343
### Optional
4444

45+
- `disk_size` (Number) The disk size of the instance in GB.
4546
- `floating_ip_id` (String) The floating IP attached to the instance.
4647
- `hostname` (String) The hostname of your instance. If not provided will be initially set to the `name` attribute.
4748
- If the value of this attribute is configured and changes, Terraform will destroy and recreate the resource.

examples/provider/provider.tf

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ resource "genesiscloud_instance" "instance" {
9090

9191
floating_ip_id = genesiscloud_floating_ip.floating_ip.id
9292

93+
disk_size = 128
94+
9395
metadata = {
9496
startup_script = <<EOF
9597
#!/bin/bash

go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module github.com/genesiscloud/terraform-provider-genesiscloud
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.22.1
46

57
require (
6-
github.com/genesiscloud/genesiscloud-go v1.0.6
8+
github.com/genesiscloud/genesiscloud-go v1.0.7
79
github.com/hashicorp/go-retryablehttp v0.7.5
810
github.com/hashicorp/terraform-plugin-docs v0.18.0
911
github.com/hashicorp/terraform-plugin-framework v1.7.0

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij
3939
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
4040
github.com/genesiscloud/genesiscloud-go v1.0.6 h1:31c6gltkSLB/dflEv/KUEq3q2RSLS7CiptmdfOCpxRk=
4141
github.com/genesiscloud/genesiscloud-go v1.0.6/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg=
42+
github.com/genesiscloud/genesiscloud-go v1.0.7-0.20240326133630-6d0921ca102e h1:GYona7mTHrCxH2fKEkhNFf1otpsw/r+lUwXP9u0dmQc=
43+
github.com/genesiscloud/genesiscloud-go v1.0.7-0.20240326133630-6d0921ca102e/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg=
44+
github.com/genesiscloud/genesiscloud-go v1.0.7 h1:bew0WlAeZjxJeQ8fGDsk9KVtI2yoPwiBe5PRzMY1Zdw=
45+
github.com/genesiscloud/genesiscloud-go v1.0.7/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg=
4246
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
4347
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
4448
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=

internal/provider/instance_resource.go

+15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
7979
stringplanmodifier.RequiresReplace(),
8080
},
8181
}),
82+
"disk_size": resourceenhancer.Attribute(ctx, schema.Int64Attribute{
83+
MarkdownDescription: "The disk size of the instance in GB.",
84+
Optional: true,
85+
Computed: true,
86+
}),
8287
"image_id": resourceenhancer.Attribute(ctx, schema.StringAttribute{
8388
MarkdownDescription: "The resulting image ID of the instance.",
8489
Computed: true,
@@ -263,6 +268,11 @@ func (r *InstanceResource) Create(ctx context.Context, req resource.CreateReques
263268
}
264269
}
265270

271+
if !data.DiskSize.IsNull() {
272+
diskSize := pointer(int(data.DiskSize.ValueInt64()))
273+
body.DiskSize = diskSize
274+
}
275+
266276
if !data.Password.IsNull() && !data.Password.IsUnknown() {
267277
body.Password = pointer(data.Password.ValueString())
268278
}
@@ -443,6 +453,11 @@ func (r *InstanceResource) Update(ctx context.Context, req resource.UpdateReques
443453
body.Volumes = &volumeIds
444454
}
445455

456+
if !data.DiskSize.IsNull() {
457+
diskSize := pointer(int(data.DiskSize.ValueInt64()))
458+
body.DiskSize = diskSize
459+
}
460+
446461
instanceId := data.Id.ValueString()
447462

448463
response, err := r.client.UpdateInstanceWithResponse(ctx, instanceId, body)

internal/provider/instance_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type InstanceResourceModel struct {
3535
// Metadata Option to provide metadata. Currently supported is `startup_script`.
3636
Metadata *InstanceMetadataModel `tfsdk:"metadata"`
3737

38+
// DiskSize The disk size of the instance in GiB.
39+
DiskSize types.Int64 `tfsdk:"disk_size"`
40+
3841
// Name The human-readable name for the instance.
3942
Name types.String `tfsdk:"name"`
4043

@@ -130,6 +133,10 @@ func (data *InstanceResourceModel) PopulateFromClientResponse(ctx context.Contex
130133
data.FloatingIpId = types.StringValue(instance.FloatingIp.Id)
131134
}
132135

136+
if instance.DiskSize != nil {
137+
data.DiskSize = types.Int64Value(int64(*instance.DiskSize))
138+
}
139+
133140
data.Region = types.StringValue(string(instance.Region))
134141
data.Status = types.StringValue(string(instance.Status))
135142
data.CreatedAt = types.StringValue(instance.CreatedAt.Format(time.RFC3339))

0 commit comments

Comments
 (0)