Skip to content

Commit

Permalink
Use types.int64 instead of int64 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
vydrazde authored Jan 22, 2024
1 parent 46c58ab commit 762e5cc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
12 changes: 6 additions & 6 deletions internal/provider/sandbox_allocation_unit_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (r *sandboxAllocationUnitResource) Configure(_ context.Context, req resourc
}

func (r *sandboxAllocationUnitResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var poolId int64
var poolId types.Int64
var timeoutsValue timeouts.Value
var pollTimes types.Object

Expand All @@ -297,7 +297,7 @@ func (r *sandboxAllocationUnitResource) Create(ctx context.Context, req resource
return
}

allocationUnits, err := r.client.CreateSandboxAllocationUnits(ctx, poolId, 1)
allocationUnits, err := r.client.CreateSandboxAllocationUnits(ctx, poolId.ValueInt64(), 1)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create sandbox allocation unit, got error: %s", err))
return
Expand Down Expand Up @@ -344,7 +344,7 @@ func (r *sandboxAllocationUnitResource) Create(ctx context.Context, req resource
}

func (r *sandboxAllocationUnitResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var id int64
var id types.Int64
var timeoutsValue timeouts.Value

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)
Expand All @@ -363,7 +363,7 @@ func (r *sandboxAllocationUnitResource) Read(ctx context.Context, req resource.R

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
allocationUnit, err := r.client.GetSandboxAllocationUnit(ctx, id)
allocationUnit, err := r.client.GetSandboxAllocationUnit(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
resp.State.RemoveResource(ctx)
return
Expand Down Expand Up @@ -442,7 +442,7 @@ func (r *sandboxAllocationUnitResource) Update(ctx context.Context, req resource

func (r *sandboxAllocationUnitResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var allocationRequest *kypo.SandboxRequest
var id int64
var id types.Int64
var timeoutsValue timeouts.Value
var pollTimes types.Object

Expand Down Expand Up @@ -472,7 +472,7 @@ func (r *sandboxAllocationUnitResource) Delete(ctx context.Context, req resource
}
}

err := r.client.CreateSandboxCleanupRequestAwait(ctx, id, pollTimeDelete)
err := r.client.CreateSandboxCleanupRequestAwait(ctx, id.ValueInt64(), pollTimeDelete)
if errors.Is(err, kypo.ErrNotFound) {
return
}
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/sandbox_definition_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/vydrazde/kypo-go-client/pkg/kypo"
)
Expand Down Expand Up @@ -146,7 +147,7 @@ func (r *sandboxDefinitionResource) Create(ctx context.Context, req resource.Cre
}

func (r *sandboxDefinitionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -156,7 +157,7 @@ func (r *sandboxDefinitionResource) Read(ctx context.Context, req resource.ReadR

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
definition, err := r.client.GetSandboxDefinition(ctx, id)
definition, err := r.client.GetSandboxDefinition(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
resp.State.RemoveResource(ctx)
return
Expand All @@ -175,7 +176,7 @@ func (r *sandboxDefinitionResource) Update(_ context.Context, _ resource.UpdateR
}

func (r *sandboxDefinitionResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -185,7 +186,7 @@ func (r *sandboxDefinitionResource) Delete(ctx context.Context, req resource.Del

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
err := r.client.DeleteSandboxDefinition(ctx, id)
err := r.client.DeleteSandboxDefinition(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
return
}
Expand Down
13 changes: 7 additions & 6 deletions internal/provider/sandbox_pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/vydrazde/kypo-go-client/pkg/kypo"
)
Expand Down Expand Up @@ -208,7 +209,7 @@ func (r *sandboxPoolResource) Configure(_ context.Context, req resource.Configur
}

func (r *sandboxPoolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var definitionId, maxSize int64
var definitionId, maxSize types.Int64

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("definition").AtName("id"), &definitionId)...)
Expand All @@ -220,7 +221,7 @@ func (r *sandboxPoolResource) Create(ctx context.Context, req resource.CreateReq

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
pool, err := r.client.CreateSandboxPool(ctx, definitionId, maxSize)
pool, err := r.client.CreateSandboxPool(ctx, definitionId.ValueInt64(), maxSize.ValueInt64())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create sandbox pool, got error: %s", err))
return
Expand All @@ -235,7 +236,7 @@ func (r *sandboxPoolResource) Create(ctx context.Context, req resource.CreateReq
}

func (r *sandboxPoolResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -245,7 +246,7 @@ func (r *sandboxPoolResource) Read(ctx context.Context, req resource.ReadRequest

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
pool, err := r.client.GetSandboxPool(ctx, id)
pool, err := r.client.GetSandboxPool(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
resp.State.RemoveResource(ctx)
return
Expand All @@ -264,7 +265,7 @@ func (r *sandboxPoolResource) Update(_ context.Context, _ resource.UpdateRequest
}

func (r *sandboxPoolResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -274,7 +275,7 @@ func (r *sandboxPoolResource) Delete(ctx context.Context, req resource.DeleteReq

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
err := r.client.DeleteSandboxPool(ctx, id)
err := r.client.DeleteSandboxPool(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
return
}
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/training_definition_adaptive_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/vydrazde/kypo-go-client/pkg/kypo"
)
Expand Down Expand Up @@ -104,7 +105,7 @@ func (r *trainingDefinitionAdaptiveResource) Create(ctx context.Context, req res
}

func (r *trainingDefinitionAdaptiveResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -114,7 +115,7 @@ func (r *trainingDefinitionAdaptiveResource) Read(ctx context.Context, req resou

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
definition, err := r.client.GetTrainingDefinitionAdaptive(ctx, id)
definition, err := r.client.GetTrainingDefinitionAdaptive(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
resp.State.RemoveResource(ctx)
return
Expand All @@ -133,7 +134,7 @@ func (r *trainingDefinitionAdaptiveResource) Update(_ context.Context, _ resourc
}

func (r *trainingDefinitionAdaptiveResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -143,7 +144,7 @@ func (r *trainingDefinitionAdaptiveResource) Delete(ctx context.Context, req res

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
err := r.client.DeleteTrainingDefinitionAdaptive(ctx, id)
err := r.client.DeleteTrainingDefinitionAdaptive(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
return
}
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/training_definition_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/vydrazde/kypo-go-client/pkg/kypo"
)
Expand Down Expand Up @@ -104,7 +105,7 @@ func (r *trainingDefinitionResource) Create(ctx context.Context, req resource.Cr
}

func (r *trainingDefinitionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -114,7 +115,7 @@ func (r *trainingDefinitionResource) Read(ctx context.Context, req resource.Read

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
definition, err := r.client.GetTrainingDefinition(ctx, id)
definition, err := r.client.GetTrainingDefinition(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
resp.State.RemoveResource(ctx)
return
Expand All @@ -133,7 +134,7 @@ func (r *trainingDefinitionResource) Update(_ context.Context, _ resource.Update
}

func (r *trainingDefinitionResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var id int64
var id types.Int64

resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("id"), &id)...)

Expand All @@ -143,7 +144,7 @@ func (r *trainingDefinitionResource) Delete(ctx context.Context, req resource.De

// If applicable, this is a great opportunity to initialize any necessary
// provider client data and make a call using it.
err := r.client.DeleteTrainingDefinition(ctx, id)
err := r.client.DeleteTrainingDefinition(ctx, id.ValueInt64())
if errors.Is(err, kypo.ErrNotFound) {
return
}
Expand Down

0 comments on commit 762e5cc

Please sign in to comment.