Skip to content

Commit dec63b5

Browse files
author
Theophilus Okwugwuni
authored
add reservationId (#95)
1 parent 827fefa commit dec63b5

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

docs/resources/instance.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ resource "genesiscloud_instance" "example" {
5252
- The string length must be at least 16.
5353
- `placement_option` (String) The placement option identifier in which instances are physically located relative to each other within a zone. For example A or B.
5454
- If the value of this attribute changes, Terraform will destroy and recreate the resource.
55+
- `reservation_id` (String) The id of the reservation the instance is associated with.
5556
- `security_group_ids` (Set of String) The security groups of the instance. If not provided will be set to the default security group.
5657
- `ssh_key_ids` (Set of String) The ssh keys of the instance.
5758
- If the value of this attribute changes, Terraform will destroy and recreate the resource.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.22.1
66

77
require (
8-
github.com/genesiscloud/genesiscloud-go v1.0.7
8+
github.com/genesiscloud/genesiscloud-go v1.0.8
99
github.com/hashicorp/go-retryablehttp v0.7.6
1010
github.com/hashicorp/terraform-plugin-docs v0.19.2
1111
github.com/hashicorp/terraform-plugin-framework v1.8.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
4747
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
4848
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
4949
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
50-
github.com/genesiscloud/genesiscloud-go v1.0.7 h1:bew0WlAeZjxJeQ8fGDsk9KVtI2yoPwiBe5PRzMY1Zdw=
51-
github.com/genesiscloud/genesiscloud-go v1.0.7/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg=
50+
github.com/genesiscloud/genesiscloud-go v1.0.8 h1:HiRHHaST1UOgsIAko739LPICB9SkgafalJHVu26DdKk=
51+
github.com/genesiscloud/genesiscloud-go v1.0.8/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg=
5252
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
5353
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
5454
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=

internal/provider/instance_resource.go

+12
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques
212212

213213
// TODO: Update of this field does not work in pulumi
214214
}),
215+
"reservation_id": resourceenhancer.Attribute(ctx, schema.StringAttribute{
216+
MarkdownDescription: "The id of the reservation the instance is associated with.",
217+
Optional: true,
218+
}),
215219

216220
// Internal
217221
"timeouts": timeouts.AttributesAll(ctx),
@@ -260,6 +264,10 @@ func (r *InstanceResource) Create(ctx context.Context, req resource.CreateReques
260264
body.FloatingIp = data.FloatingIpId.ValueStringPointer()
261265
}
262266

267+
if !data.ReservationId.IsNull() && !data.ReservationId.IsUnknown() {
268+
body.ReservationId = data.ReservationId.ValueStringPointer()
269+
}
270+
263271
if data.Metadata != nil {
264272
body.Metadata = &struct {
265273
StartupScript *string `json:"startup_script,omitempty"`
@@ -459,6 +467,10 @@ func (r *InstanceResource) Update(ctx context.Context, req resource.UpdateReques
459467
body.DiskSize = diskSize
460468
}
461469

470+
if !data.ReservationId.IsNull() && !data.ReservationId.IsUnknown() {
471+
body.ReservationId = data.ReservationId.ValueStringPointer()
472+
}
473+
462474
instanceId := data.Id.ValueString()
463475

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

internal/provider/instance_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type InstanceResourceModel struct {
7979
// FloatingIp The floating IP of the instance.
8080
FloatingIpId types.String `tfsdk:"floating_ip_id"`
8181

82+
// ReservationId The id of the reservation the instance is associated with.
83+
ReservationId types.String `tfsdk:"reservation_id"`
84+
8285
// Internal
8386

8487
// Timeouts The resource timeouts
@@ -133,6 +136,10 @@ func (data *InstanceResourceModel) PopulateFromClientResponse(ctx context.Contex
133136
data.FloatingIpId = types.StringValue(instance.FloatingIp.Id)
134137
}
135138

139+
if instance.ReservationId != nil {
140+
data.ReservationId = types.StringValue(*instance.ReservationId)
141+
}
142+
136143
if instance.DiskSize != nil {
137144
data.DiskSize = types.Int64Value(int64(*instance.DiskSize))
138145
}

0 commit comments

Comments
 (0)