diff --git a/docs/resources/instance.md b/docs/resources/instance.md index 2cc54b4..ef88d97 100644 --- a/docs/resources/instance.md +++ b/docs/resources/instance.md @@ -52,6 +52,7 @@ resource "genesiscloud_instance" "example" { - The string length must be at least 16. - `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. - If the value of this attribute changes, Terraform will destroy and recreate the resource. +- `reservation_id` (String) The id of the reservation the instance is associated with. - `security_group_ids` (Set of String) The security groups of the instance. If not provided will be set to the default security group. - `ssh_key_ids` (Set of String) The ssh keys of the instance. - If the value of this attribute changes, Terraform will destroy and recreate the resource. diff --git a/go.mod b/go.mod index 1dd40b5..c0c7837 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.22.1 require ( - github.com/genesiscloud/genesiscloud-go v1.0.7 + github.com/genesiscloud/genesiscloud-go v1.0.8 github.com/hashicorp/go-retryablehttp v0.7.6 github.com/hashicorp/terraform-plugin-docs v0.19.2 github.com/hashicorp/terraform-plugin-framework v1.8.0 diff --git a/go.sum b/go.sum index edb4317..1861558 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/genesiscloud/genesiscloud-go v1.0.7 h1:bew0WlAeZjxJeQ8fGDsk9KVtI2yoPwiBe5PRzMY1Zdw= -github.com/genesiscloud/genesiscloud-go v1.0.7/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg= +github.com/genesiscloud/genesiscloud-go v1.0.8 h1:HiRHHaST1UOgsIAko739LPICB9SkgafalJHVu26DdKk= +github.com/genesiscloud/genesiscloud-go v1.0.8/go.mod h1:OAMjSCejQTC4BBLWXleegT/fg+X46SZ6t/vW9RPtXWg= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= diff --git a/internal/provider/instance_resource.go b/internal/provider/instance_resource.go index 0455101..5f6b628 100644 --- a/internal/provider/instance_resource.go +++ b/internal/provider/instance_resource.go @@ -212,6 +212,10 @@ func (r *InstanceResource) Schema(ctx context.Context, req resource.SchemaReques // TODO: Update of this field does not work in pulumi }), + "reservation_id": resourceenhancer.Attribute(ctx, schema.StringAttribute{ + MarkdownDescription: "The id of the reservation the instance is associated with.", + Optional: true, + }), // Internal "timeouts": timeouts.AttributesAll(ctx), @@ -260,6 +264,10 @@ func (r *InstanceResource) Create(ctx context.Context, req resource.CreateReques body.FloatingIp = data.FloatingIpId.ValueStringPointer() } + if !data.ReservationId.IsNull() && !data.ReservationId.IsUnknown() { + body.ReservationId = data.ReservationId.ValueStringPointer() + } + if data.Metadata != nil { body.Metadata = &struct { StartupScript *string `json:"startup_script,omitempty"` @@ -459,6 +467,10 @@ func (r *InstanceResource) Update(ctx context.Context, req resource.UpdateReques body.DiskSize = diskSize } + if !data.ReservationId.IsNull() && !data.ReservationId.IsUnknown() { + body.ReservationId = data.ReservationId.ValueStringPointer() + } + instanceId := data.Id.ValueString() response, err := r.client.UpdateInstanceWithResponse(ctx, instanceId, body) diff --git a/internal/provider/instance_types.go b/internal/provider/instance_types.go index a5f4061..6facee2 100644 --- a/internal/provider/instance_types.go +++ b/internal/provider/instance_types.go @@ -79,6 +79,9 @@ type InstanceResourceModel struct { // FloatingIp The floating IP of the instance. FloatingIpId types.String `tfsdk:"floating_ip_id"` + // ReservationId The id of the reservation the instance is associated with. + ReservationId types.String `tfsdk:"reservation_id"` + // Internal // Timeouts The resource timeouts @@ -133,6 +136,10 @@ func (data *InstanceResourceModel) PopulateFromClientResponse(ctx context.Contex data.FloatingIpId = types.StringValue(instance.FloatingIp.Id) } + if instance.ReservationId != nil { + data.ReservationId = types.StringValue(*instance.ReservationId) + } + if instance.DiskSize != nil { data.DiskSize = types.Int64Value(int64(*instance.DiskSize)) }