Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reservationId #95

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ReservationId = types.StringValue(*instance.ReservationId)
}

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