fix: pgsql_api_updates #16
6 changed files with 52 additions and 16 deletions
|
|
@ -56,7 +56,7 @@ func getDatabase(
|
|||
|
||||
const pageSize = 25
|
||||
|
||||
for page := int64(1); ; page++ {
|
||||
for page := int32(1); ; page++ {
|
||||
res, err := client.ListDatabasesRequest(ctx, projectId, region, instanceId).
|
||||
Page(page).Size(pageSize).Sort(postgresflex.DATABASESORT_INDEX_ASC).Execute()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
|
@ -365,7 +366,13 @@ func (r *databaseResource) Update(
|
|||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
instanceId := model.InstanceId.ValueString()
|
||||
databaseId := model.DatabaseId.ValueInt64()
|
||||
databaseId64 := model.DatabaseId.ValueInt64()
|
||||
if databaseId64 > math.MaxInt32 {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||
return
|
||||
}
|
||||
databaseId := int32(databaseId64)
|
||||
|
||||
region := model.Region.ValueString()
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
|
@ -449,7 +456,13 @@ func (r *databaseResource) Delete(
|
|||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
instanceId := model.InstanceId.ValueString()
|
||||
databaseId := model.DatabaseId.ValueInt64()
|
||||
databaseId64 := model.DatabaseId.ValueInt64()
|
||||
|
||||
if databaseId64 > math.MaxInt32 {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)")
|
||||
return
|
||||
}
|
||||
databaseId := int32(databaseId64)
|
||||
region := model.Region.ValueString()
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func getFlavorsByFilter(
|
|||
|
||||
var result = make([]postgresflex.ListFlavors, 0)
|
||||
|
||||
for page := int64(1); ; page++ {
|
||||
for page := int32(1); ; page++ {
|
||||
res, err := client.GetFlavorsRequest(ctx, projectId, region).
|
||||
Page(page).Size(pageSize).Sort(postgresflex.FLAVORSORT_INDEX_ASC).Execute()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -261,13 +261,11 @@ func modelToCreateInstancePayload(netAcl []string, model postgresflexalpha.Insta
|
|||
Encryption: &enc,
|
||||
FlavorId: model.FlavorId.ValueStringPointer(),
|
||||
Name: model.Name.ValueStringPointer(),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
Network: &postgresflex.InstanceNetworkCreate{
|
||||
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(
|
||||
model.Network.AccessScope.ValueStringPointer(),
|
||||
),
|
||||
Acl: &netAcl,
|
||||
InstanceAddress: model.Network.InstanceAddress.ValueStringPointer(),
|
||||
RouterAddress: model.Network.RouterAddress.ValueStringPointer(),
|
||||
Acl: &netAcl,
|
||||
},
|
||||
Replicas: postgresflex.CreateInstanceRequestPayloadGetReplicasAttributeType(&replVal),
|
||||
RetentionDays: model.RetentionDays.ValueInt64Pointer(),
|
||||
|
|
@ -452,10 +450,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
|
||||
FlavorId: model.FlavorId.ValueStringPointer(),
|
||||
Name: model.Name.ValueStringPointer(),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(
|
||||
model.Network.AccessScope.ValueStringPointer(),
|
||||
),
|
||||
Network: &postgresflex.InstanceNetworkUpdate{
|
||||
Acl: &netAcl,
|
||||
},
|
||||
Replicas: postgresflex.UpdateInstanceRequestPayloadGetReplicasAttributeType(&replInt32),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package postgresflexalpha
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -179,7 +180,13 @@ func (r *userDataSource) Read(
|
|||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
instanceId := model.InstanceId.ValueString()
|
||||
userId := model.UserId.ValueInt64()
|
||||
userId64 := model.UserId.ValueInt64()
|
||||
if userId64 > math.MaxInt32 {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
|
||||
region := r.providerData.GetRegionWithOverride(model.Region)
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -390,13 +391,20 @@ func (r *userResource) Update(
|
|||
return
|
||||
}
|
||||
|
||||
userId64 := arg.userId
|
||||
if userId64 > math.MaxInt32 {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
|
||||
// Update existing instance
|
||||
err = r.client.UpdateUserRequest(
|
||||
ctx,
|
||||
arg.projectId,
|
||||
arg.region,
|
||||
arg.instanceId,
|
||||
arg.userId,
|
||||
userId,
|
||||
).UpdateUserRequestPayload(*payload).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error())
|
||||
|
|
@ -446,8 +454,15 @@ func (r *userResource) Delete(
|
|||
ctx = r.setTFLogFields(ctx, &model)
|
||||
arg := r.getClientArg(&model)
|
||||
|
||||
userId64 := arg.userId
|
||||
if userId64 > math.MaxInt32 {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)")
|
||||
return
|
||||
}
|
||||
userId := int32(userId64)
|
||||
|
||||
// Delete existing record set
|
||||
err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, arg.userId).Execute()
|
||||
err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))
|
||||
}
|
||||
|
|
@ -555,8 +570,14 @@ func (r *userResource) getUserResource(ctx context.Context, model *Model) (bool,
|
|||
ctx = r.setTFLogFields(ctx, model)
|
||||
arg := r.getClientArg(model)
|
||||
|
||||
userId64 := arg.userId
|
||||
if userId64 > math.MaxInt32 {
|
||||
return false, errors.New("error in type conversion: int value too large (userId)")
|
||||
}
|
||||
userId := int32(userId64)
|
||||
|
||||
// API Call
|
||||
userResp, err := r.client.GetUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, arg.userId).Execute()
|
||||
userResp, err := r.client.GetUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue