chore: work save
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 4m1s
CI Workflow / CI run build and linting (pull_request) Failing after 5m1s
CI Workflow / CI run tests (pull_request) Failing after 5m16s
CI Workflow / Code coverage report (pull_request) Has been skipped
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 4m1s
CI Workflow / CI run build and linting (pull_request) Failing after 5m1s
CI Workflow / CI run tests (pull_request) Failing after 5m16s
CI Workflow / Code coverage report (pull_request) Has been skipped
This commit is contained in:
parent
d6d3a795bb
commit
7f5802aff0
27 changed files with 802 additions and 962 deletions
|
|
@ -55,7 +55,7 @@ type UserResourceIdentityModel struct {
|
|||
ProjectID types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
InstanceID types.String `tfsdk:"instance_id"`
|
||||
UserID types.Int32 `tfsdk:"user_id"`
|
||||
UserID types.Int64 `tfsdk:"user_id"`
|
||||
}
|
||||
|
||||
// userResource implements the resource handling for a PostgreSQL Flex user.
|
||||
|
|
@ -189,8 +189,8 @@ func (r *userResource) Create(
|
|||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
arg := &clientArg{
|
||||
projectId: model.ProjectId.ValueString(),
|
||||
instanceId: model.InstanceId.ValueString(),
|
||||
projectID: model.ProjectId.ValueString(),
|
||||
instanceID: model.InstanceId.ValueString(),
|
||||
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||
}
|
||||
|
||||
|
|
@ -211,9 +211,9 @@ func (r *userResource) Create(
|
|||
// Create new user
|
||||
userResp, err := r.client.DefaultAPI.CreateUserRequest(
|
||||
ctx,
|
||||
arg.projectId,
|
||||
arg.projectID,
|
||||
arg.region,
|
||||
arg.instanceId,
|
||||
arg.instanceID,
|
||||
).CreateUserRequestPayload(*payload).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
||||
|
|
@ -230,7 +230,7 @@ func (r *userResource) Create(
|
|||
)
|
||||
return
|
||||
}
|
||||
arg.userId = *id
|
||||
arg.userID = int64(*id)
|
||||
|
||||
ctx = tflog.SetField(ctx, "user_id", id)
|
||||
|
||||
|
|
@ -238,28 +238,28 @@ func (r *userResource) Create(
|
|||
|
||||
// Set data returned by API in identity
|
||||
identity := UserResourceIdentityModel{
|
||||
ProjectID: types.StringValue(arg.projectId),
|
||||
ProjectID: types.StringValue(arg.projectID),
|
||||
Region: types.StringValue(arg.region),
|
||||
InstanceID: types.StringValue(arg.instanceId),
|
||||
UserID: types.Int32Value(*id),
|
||||
InstanceID: types.StringValue(arg.instanceID),
|
||||
UserID: types.Int64Value(int64(*id)),
|
||||
}
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
model.Id = types.Int32Value(*id)
|
||||
model.UserId = types.Int32Value(*id)
|
||||
model.Id = types.Int64Value(int64(*id))
|
||||
model.UserId = types.Int64Value(int64(*id))
|
||||
model.Password = types.StringValue(userResp.GetPassword())
|
||||
model.Status = types.StringValue(userResp.GetStatus())
|
||||
|
||||
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||
ctx,
|
||||
r.client.DefaultAPI,
|
||||
arg.projectId,
|
||||
arg.instanceId,
|
||||
arg.projectID,
|
||||
arg.instanceID,
|
||||
arg.region,
|
||||
*id,
|
||||
int64(*id),
|
||||
).SetSleepBeforeWait(
|
||||
10 * time.Second,
|
||||
).SetTimeout(
|
||||
|
|
@ -324,8 +324,8 @@ func (r *userResource) Read(
|
|||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
arg := &clientArg{
|
||||
projectId: model.ProjectId.ValueString(),
|
||||
instanceId: model.InstanceId.ValueString(),
|
||||
projectID: model.ProjectId.ValueString(),
|
||||
instanceID: model.InstanceId.ValueString(),
|
||||
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||
}
|
||||
|
||||
|
|
@ -337,10 +337,10 @@ func (r *userResource) Read(
|
|||
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||
ctx,
|
||||
r.client.DefaultAPI,
|
||||
arg.projectId,
|
||||
arg.instanceId,
|
||||
arg.projectID,
|
||||
arg.instanceID,
|
||||
arg.region,
|
||||
model.UserId.ValueInt32(),
|
||||
model.UserId.ValueInt64(),
|
||||
).SetSleepBeforeWait(
|
||||
10 * time.Second,
|
||||
).SetTimeout(
|
||||
|
|
@ -357,7 +357,7 @@ func (r *userResource) Read(
|
|||
return
|
||||
}
|
||||
|
||||
if waitResp.Id != model.UserId.ValueInt32() {
|
||||
if int64(waitResp.Id) != model.UserId.ValueInt64() {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -366,16 +366,16 @@ func (r *userResource) Read(
|
|||
)
|
||||
return
|
||||
}
|
||||
arg.userId = waitResp.Id
|
||||
arg.userID = int64(waitResp.Id)
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Set data returned by API in identity
|
||||
identity := UserResourceIdentityModel{
|
||||
ProjectID: types.StringValue(arg.projectId),
|
||||
ProjectID: types.StringValue(arg.projectID),
|
||||
Region: types.StringValue(arg.region),
|
||||
InstanceID: types.StringValue(arg.instanceId),
|
||||
UserID: types.Int32Value(arg.userId),
|
||||
InstanceID: types.StringValue(arg.instanceID),
|
||||
UserID: types.Int64Value(arg.userID),
|
||||
}
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -407,8 +407,8 @@ func (r *userResource) Update(
|
|||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
arg := &clientArg{
|
||||
projectId: model.ProjectId.ValueString(),
|
||||
instanceId: model.InstanceId.ValueString(),
|
||||
projectID: model.ProjectId.ValueString(),
|
||||
instanceID: model.InstanceId.ValueString(),
|
||||
region: r.providerData.GetRegionWithOverride(model.Region),
|
||||
}
|
||||
|
||||
|
|
@ -435,20 +435,20 @@ func (r *userResource) Update(
|
|||
return
|
||||
}
|
||||
|
||||
userId64 := arg.userId
|
||||
if userId64 > math.MaxInt32 {
|
||||
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) // nolint:gosec // check is performed above
|
||||
userID := int32(userID64) // nolint:gosec // check is performed above
|
||||
|
||||
// Update existing instance
|
||||
err = r.client.DefaultAPI.UpdateUserRequest(
|
||||
ctx,
|
||||
arg.projectId,
|
||||
arg.projectID,
|
||||
arg.region,
|
||||
arg.instanceId,
|
||||
userId,
|
||||
arg.instanceID,
|
||||
userID,
|
||||
).UpdateUserRequestPayload(*payload).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error())
|
||||
|
|
@ -459,10 +459,10 @@ func (r *userResource) Update(
|
|||
|
||||
// Set data returned by API in identity
|
||||
identity := UserResourceIdentityModel{
|
||||
ProjectID: types.StringValue(arg.projectId),
|
||||
ProjectID: types.StringValue(arg.projectID),
|
||||
Region: types.StringValue(arg.region),
|
||||
InstanceID: types.StringValue(arg.instanceId),
|
||||
UserID: types.Int32Value(userId64),
|
||||
InstanceID: types.StringValue(arg.instanceID),
|
||||
UserID: types.Int64Value(userID64),
|
||||
}
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -473,10 +473,10 @@ func (r *userResource) Update(
|
|||
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||
ctx,
|
||||
r.client.DefaultAPI,
|
||||
arg.projectId,
|
||||
arg.instanceId,
|
||||
arg.projectID,
|
||||
arg.instanceID,
|
||||
arg.region,
|
||||
model.UserId.ValueInt32(),
|
||||
model.UserId.ValueInt64(),
|
||||
).SetSleepBeforeWait(
|
||||
10 * time.Second,
|
||||
).SetTimeout(
|
||||
|
|
@ -493,7 +493,7 @@ func (r *userResource) Update(
|
|||
return
|
||||
}
|
||||
|
||||
if waitResp.Id != model.UserId.ValueInt32() {
|
||||
if int64(waitResp.Id) != model.UserId.ValueInt64() {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -502,7 +502,7 @@ func (r *userResource) Update(
|
|||
)
|
||||
return
|
||||
}
|
||||
arg.userId = waitResp.Id
|
||||
arg.userID = int64(waitResp.Id)
|
||||
|
||||
// Set state to fully populated data
|
||||
diags = resp.State.Set(ctx, stateModel)
|
||||
|
|
@ -547,15 +547,15 @@ func (r *userResource) Delete(
|
|||
ctx = r.setTFLogFields(ctx, arg)
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
userId64 := arg.userId
|
||||
if userId64 > math.MaxInt32 {
|
||||
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) // nolint:gosec // check is performed above
|
||||
userID := int32(userID64) // nolint:gosec // check is performed above
|
||||
|
||||
// Delete existing record set
|
||||
err := r.client.DefaultAPI.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute()
|
||||
err := r.client.DefaultAPI.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))
|
||||
}
|
||||
|
|
@ -598,7 +598,7 @@ func (r *userResource) IdentitySchema(
|
|||
"instance_id": identityschema.StringAttribute{
|
||||
RequiredForImport: true,
|
||||
},
|
||||
"user_id": identityschema.Int32Attribute{
|
||||
"user_id": identityschema.Int64Attribute{
|
||||
RequiredForImport: true,
|
||||
},
|
||||
},
|
||||
|
|
@ -607,10 +607,10 @@ func (r *userResource) IdentitySchema(
|
|||
|
||||
// clientArg holds the arguments for API calls.
|
||||
type clientArg struct {
|
||||
projectId string
|
||||
instanceId string
|
||||
projectID string
|
||||
instanceID string
|
||||
region string
|
||||
userId int32
|
||||
userID int64
|
||||
}
|
||||
|
||||
// ImportState imports a resource into the Terraform state on success.
|
||||
|
|
@ -637,7 +637,7 @@ func (r *userResource) ImportState(
|
|||
return
|
||||
}
|
||||
|
||||
userId, err := strconv.ParseInt(idParts[3], 10, 64)
|
||||
userID, err := strconv.ParseInt(idParts[3], 10, 64)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -651,7 +651,7 @@ func (r *userResource) ImportState(
|
|||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), idParts[1])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[2])...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), userId)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), userID)...)
|
||||
|
||||
tflog.Info(ctx, "Postgres Flex user state imported")
|
||||
|
||||
|
|
@ -665,15 +665,15 @@ func (r *userResource) ImportState(
|
|||
return
|
||||
}
|
||||
|
||||
projectId := identityData.ProjectID.ValueString()
|
||||
projectID := identityData.ProjectID.ValueString()
|
||||
region := identityData.Region.ValueString()
|
||||
instanceId := identityData.InstanceID.ValueString()
|
||||
userId := identityData.UserID.ValueInt32()
|
||||
instanceID := identityData.InstanceID.ValueString()
|
||||
userID := identityData.UserID.ValueInt64()
|
||||
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), projectId)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), projectID)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), region)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), instanceId)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), userId)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), instanceID)...)
|
||||
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), userID)...)
|
||||
|
||||
tflog.Info(ctx, "Postgres Flex user state imported")
|
||||
}
|
||||
|
|
@ -683,25 +683,24 @@ func (r *userResource) extractIdentityData(
|
|||
model resourceModel,
|
||||
identity UserResourceIdentityModel,
|
||||
) (*clientArg, error) {
|
||||
var projectId, region, instanceId string
|
||||
var userId int32
|
||||
|
||||
var projectID, region, instanceID string
|
||||
var userID int64
|
||||
if !model.UserId.IsNull() && !model.UserId.IsUnknown() {
|
||||
userId = model.UserId.ValueInt32()
|
||||
userID = model.UserId.ValueInt64()
|
||||
} else {
|
||||
if identity.UserID.IsNull() || identity.UserID.IsUnknown() {
|
||||
return nil, fmt.Errorf("user_id not found in config")
|
||||
}
|
||||
userId = identity.UserID.ValueInt32()
|
||||
userID = identity.UserID.ValueInt64()
|
||||
}
|
||||
|
||||
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {
|
||||
projectId = model.ProjectId.ValueString()
|
||||
projectID = model.ProjectId.ValueString()
|
||||
} else {
|
||||
if identity.ProjectID.IsNull() || identity.ProjectID.IsUnknown() {
|
||||
return nil, fmt.Errorf("project_id not found in config")
|
||||
}
|
||||
projectId = identity.ProjectID.ValueString()
|
||||
projectID = identity.ProjectID.ValueString()
|
||||
}
|
||||
|
||||
if !model.Region.IsNull() && !model.Region.IsUnknown() {
|
||||
|
|
@ -714,27 +713,27 @@ func (r *userResource) extractIdentityData(
|
|||
}
|
||||
|
||||
if !model.InstanceId.IsNull() && !model.InstanceId.IsUnknown() {
|
||||
instanceId = model.InstanceId.ValueString()
|
||||
instanceID = model.InstanceId.ValueString()
|
||||
} else {
|
||||
if identity.InstanceID.IsNull() || identity.InstanceID.IsUnknown() {
|
||||
return nil, fmt.Errorf("instance_id not found in config")
|
||||
}
|
||||
instanceId = identity.InstanceID.ValueString()
|
||||
instanceID = identity.InstanceID.ValueString()
|
||||
}
|
||||
return &clientArg{
|
||||
projectId: projectId,
|
||||
instanceId: instanceId,
|
||||
projectID: projectID,
|
||||
instanceID: instanceID,
|
||||
region: region,
|
||||
userId: userId,
|
||||
userID: userID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// setTFLogFields adds relevant fields to the context for terraform logging purposes.
|
||||
func (r *userResource) setTFLogFields(ctx context.Context, arg *clientArg) context.Context {
|
||||
ctx = tflog.SetField(ctx, "project_id", arg.projectId)
|
||||
ctx = tflog.SetField(ctx, "instance_id", arg.instanceId)
|
||||
ctx = tflog.SetField(ctx, "project_id", arg.projectID)
|
||||
ctx = tflog.SetField(ctx, "instance_id", arg.instanceID)
|
||||
ctx = tflog.SetField(ctx, "region", arg.region)
|
||||
ctx = tflog.SetField(ctx, "user_id", arg.userId)
|
||||
ctx = tflog.SetField(ctx, "user_id", arg.userID)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue