chore: work save

This commit is contained in:
Marcel_Henselin 2026-01-26 22:09:02 +01:00
parent 7c4ca25791
commit d20cf15f40
4 changed files with 107 additions and 20 deletions

View file

@ -8,4 +8,8 @@ fields:
- 'RequiresReplace'
- name: 'network.acl'
modifiers:
- 'UseStateForUnknown'
- name: 'network.access_scope'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'

View file

@ -206,7 +206,11 @@ func (r *instanceResource) Create(
}
ctx = core.LogResponse(ctx)
instanceId := *createResp.Id
instanceId, ok := createResp.GetIdOk()
if !ok {
core.LogAndAddError(ctx, &resp.Diagnostics, "error creating instance", "could not find instance id in response")
return
}
model.InstanceId = types.StringValue(instanceId)
model.Id = utils.BuildInternalTerraformId(projectId, region, instanceId)
@ -371,8 +375,27 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
ctx = core.InitProviderContext(ctx)
projectId := model.ProjectId.ValueString()
instanceId := model.InstanceId.ValueString()
// Read identity data
var identityData InstanceResourceIdentityModel
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
if resp.Diagnostics.HasError() {
return
}
//if model.InstanceId.IsNull() || model.InstanceId.IsUnknown() {
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "instanceId is null or unknown")
// return
//}
//
//if model.ProjectId.IsNull() || model.ProjectId.IsUnknown() {
// core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", "projectId is null or unknown")
// return
//}
//projectId := model.ProjectId.ValueString()
//instanceId := model.InstanceId.ValueString()
projectId := identityData.ProjectID.ValueString()
instanceId := identityData.InstanceID.ValueString()
region := model.Region.ValueString()
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
@ -485,20 +508,35 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
}
// ImportState imports a resource into the Terraform state on success.
// The expected format of the resource import identifier is: project_id,instance_id
// The expected format of the resource import identifier is: project_id,region,instance_id
func (r *instanceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
idParts := strings.Split(req.ID, core.Separator)
tflog.Debug(ctx, "ImportState called with id:", map[string]interface{}{"id": req.ID})
if req.ID != "" {
idParts := strings.Split(req.ID, core.Separator)
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
core.LogAndAddError(ctx, &resp.Diagnostics,
"Error importing instance",
fmt.Sprintf("Expected import identifier with format: [project_id],[region],[instance_id] Got: %q", req.ID),
)
if len(idParts) != 3 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" {
core.LogAndAddError(ctx, &resp.Diagnostics,
"Error importing instance",
fmt.Sprintf("Expected import identifier with format: [project_id],[region],[instance_id] Got: %q", req.ID),
)
return
}
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])...)
return
}
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])...)
var identityData InstanceResourceIdentityModel
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), identityData.ProjectID.ValueString())...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("region"), identityData.Region.ValueString())...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), identityData.InstanceID.ValueString())...)
tflog.Info(ctx, "Postgres Flex instance state imported")
}

View file

@ -175,16 +175,16 @@ func PartialUpdateInstanceWaitHandler(
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
case InstanceStateEmpty:
return false, nil, nil
case InstanceStateUnknown:
case InstanceStatePending:
return false, nil, nil
case InstanceStateProgressing:
return false, nil, nil
case InstanceStatePending:
return false, nil, nil
case InstanceStateTerminating:
return false, nil, nil
case InstanceStateSuccess:
return true, s, nil
case InstanceStateTerminating:
return false, nil, nil
case InstanceStateUnknown:
return false, nil, nil
case InstanceStateFailed:
return true, s, fmt.Errorf("update failed for instance with id %s", instanceId)
}