diff --git a/internal/helpers/client.go b/internal/helpers/client.go index 036a54b..ce4c2d7 100644 --- a/internal/helpers/client.go +++ b/internal/helpers/client.go @@ -133,6 +133,7 @@ func (c *HttpCaller) RequestDataToClient(verb HttpCallerVerb, url string, header } req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-No-Cache", "true") if headers != nil && len(*headers) > 0 { for k, v := range *headers { req.Header.Set(k, v) diff --git a/internal/remoteimage/resource.go b/internal/remoteimage/resource.go index 5a6047a..f173d9b 100644 --- a/internal/remoteimage/resource.go +++ b/internal/remoteimage/resource.go @@ -706,7 +706,6 @@ func (r *RemoteVmResource) Update(ctx context.Context, req resource.UpdateReques resp.Diagnostics.Append(diag...) return } - apiclient.DeleteVm(ctx, hostConfig, data.ID.ValueString()) } return } @@ -864,6 +863,16 @@ func (r *RemoteVmResource) Delete(ctx context.Context, req resource.DeleteReques _ = common.RunPostProcessorScript(ctx, hostConfig, vm, data.OnDestroyScript) } + if len(data.ReverseProxyHosts) > 0 { + rpHostConfig := hostConfig + rpHostConfig.HostId = vm.HostId + rpHostsCopy := reverseproxy.CopyReverseProxyHosts(data.ReverseProxyHosts) + if diag := reverseproxy.Delete(ctx, rpHostConfig, rpHostsCopy); diag.HasError() { + resp.Diagnostics.Append(diag...) + return + } + } + // Stopping the machine if _, stopDiag := common.EnsureMachineStopped(ctx, hostConfig, vm); stopDiag.HasError() { resp.Diagnostics.Append(stopDiag...) @@ -897,16 +906,6 @@ func (r *RemoteVmResource) Delete(ctx context.Context, req resource.DeleteReques time.Sleep(10 * time.Second) } - if len(data.ReverseProxyHosts) > 0 { - rpHostConfig := hostConfig - rpHostConfig.HostId = vm.HostId - rpHostsCopy := reverseproxy.CopyReverseProxyHosts(data.ReverseProxyHosts) - if diag := reverseproxy.Delete(ctx, rpHostConfig, rpHostsCopy); diag.HasError() { - resp.Diagnostics.Append(diag...) - return - } - } - resp.Diagnostics.Append(req.State.Set(ctx, &data)...) if resp.Diagnostics.HasError() { diff --git a/internal/schemas/reverseproxy/operations.go b/internal/schemas/reverseproxy/operations.go index 6b6d538..4d7a5dd 100644 --- a/internal/schemas/reverseproxy/operations.go +++ b/internal/schemas/reverseproxy/operations.go @@ -335,6 +335,11 @@ func updateHost(ctx context.Context, config apiclient.HostConfig, currentHost Re if createDiag.HasError() { diagnostic = append(diagnostic, createDiag...) } + if r == nil { + errDiag := diag.NewErrorDiagnostic("Failed to create reverse proxy host", "The reverse proxy response was nil") + diagnostic = append(diagnostic, errDiag) + return requestHost, diagnostic + } requestHost.ID = types.StringValue(r.ID) return requestHost, diagnostic