Skip to content

Commit

Permalink
add reservationId
Browse files Browse the repository at this point in the history
  • Loading branch information
theocod3s committed May 21, 2024
1 parent 827fefa commit 96e50c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 12 additions & 0 deletions internal/provider/instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,6 +136,10 @@ func (data *InstanceResourceModel) PopulateFromClientResponse(ctx context.Contex
data.FloatingIpId = types.StringValue(instance.FloatingIp.Id)
}

if instance.ReservationId != nil {
data.FloatingIpId = types.StringValue(*instance.ReservationId)
}

if instance.DiskSize != nil {
data.DiskSize = types.Int64Value(int64(*instance.DiskSize))
}
Expand Down

0 comments on commit 96e50c3

Please sign in to comment.