diff --git a/internal/backend/remote/backend_common.go b/internal/backend/remote/backend_common.go index 4ce318f262a8..120e990caca8 100644 --- a/internal/backend/remote/backend_common.go +++ b/internal/backend/remote/backend_common.go @@ -419,16 +419,16 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope case tfe.PolicyHardFailed: return fmt.Errorf(msgPrefix + " hard failed.") case tfe.PolicySoftFailed: - runUrl := fmt.Sprintf(runHeader, b.hostname, b.organization, op.Workspace, r.ID) + runURL := fmt.Sprintf(runHeaderErr, b.hostname, b.organization, op.Workspace, r.ID) if op.Type == backend.OperationTypePlan || op.UIOut == nil || op.UIIn == nil || !pc.Actions.IsOverridable || !pc.Permissions.CanOverride { - return fmt.Errorf(msgPrefix + " soft failed.\n" + runUrl) + return fmt.Errorf(msgPrefix + " soft failed.\n" + runURL) } if op.AutoApprove { if _, err = b.client.PolicyChecks.Override(stopCtx, pc.ID); err != nil { - return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err) + return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runURL), err) } } else { opts := &terraform.InputOpts{ @@ -439,16 +439,17 @@ func (b *Remote) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Ope err = b.confirm(stopCtx, op, opts, r, "override") if err != nil && err != errRunOverridden { return fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runUrl), + fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), ) } if err != errRunOverridden { if _, err = b.client.PolicyChecks.Override(stopCtx, pc.ID); err != nil { - return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err) + return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runURL), err) } } else { - b.CLI.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runUrl)) + runURL := fmt.Sprintf(runHeader, b.hostname, b.organization, op.Workspace, r.ID) + b.CLI.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runURL)) } } diff --git a/internal/backend/remote/backend_plan.go b/internal/backend/remote/backend_plan.go index 0f795e527fef..64b40189934c 100644 --- a/internal/backend/remote/backend_plan.go +++ b/internal/backend/remote/backend_plan.go @@ -443,8 +443,13 @@ Preparing the remote plan... ` const runHeader = ` -[reset][yellow]To view this run in a browser, visit: -https://%s/app/%s/%s/runs/%s[reset] +[reset][yellow]To view this run in a browser, visit:[reset] +[reset][yellow]https://%s/app/%s/%s/runs/%s[reset] +` + +const runHeaderErr = ` +To view this run in a browser, visit: +https://%s/app/%s/%s/runs/%s ` // The newline in this error is to make it look good in the CLI! diff --git a/internal/cloud/backend_common.go b/internal/cloud/backend_common.go index e9929490fef3..8d054d3ff8ae 100644 --- a/internal/cloud/backend_common.go +++ b/internal/cloud/backend_common.go @@ -391,16 +391,16 @@ func (b *Cloud) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Oper case tfe.PolicyHardFailed: return fmt.Errorf(msgPrefix + " hard failed.") case tfe.PolicySoftFailed: - runUrl := fmt.Sprintf(runHeader, b.Hostname, b.Organization, op.Workspace, r.ID) + runURL := fmt.Sprintf(runHeaderErr, b.Hostname, b.Organization, op.Workspace, r.ID) if op.Type == backend.OperationTypePlan || op.UIOut == nil || op.UIIn == nil || !pc.Actions.IsOverridable || !pc.Permissions.CanOverride { - return fmt.Errorf(msgPrefix + " soft failed.\n" + runUrl) + return fmt.Errorf(msgPrefix + " soft failed.\n" + runURL) } if op.AutoApprove { if _, err = b.client.PolicyChecks.Override(stopCtx, pc.ID); err != nil { - return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err) + return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runURL), err) } } else if !b.input { return errPolicyOverrideNeedsUIConfirmation @@ -413,16 +413,17 @@ func (b *Cloud) checkPolicy(stopCtx, cancelCtx context.Context, op *backend.Oper err = b.confirm(stopCtx, op, opts, r, "override") if err != nil && err != errRunOverridden { return fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runUrl), + fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), ) } if err != errRunOverridden { if _, err = b.client.PolicyChecks.Override(stopCtx, pc.ID); err != nil { - return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err) + return generalError(fmt.Sprintf("Failed to override policy check.\n%s", runURL), err) } } else { - b.CLI.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runUrl)) + runURL := fmt.Sprintf(runHeader, b.Hostname, b.Organization, op.Workspace, r.ID) + b.CLI.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runURL)) } } diff --git a/internal/cloud/backend_plan.go b/internal/cloud/backend_plan.go index ce51a99bea9b..64c17129123d 100644 --- a/internal/cloud/backend_plan.go +++ b/internal/cloud/backend_plan.go @@ -638,8 +638,13 @@ Preparing the remote plan... ` const runHeader = ` -[reset][yellow]To view this run in a browser, visit: -https://%s/app/%s/%s/runs/%s[reset] +[reset][yellow]To view this run in a browser, visit:[reset] +[reset][yellow]https://%s/app/%s/%s/runs/%s[reset] +` + +const runHeaderErr = ` +To view this run in the browser, visit: +https://%s/app/%s/%s/runs/%s ` // The newline in this error is to make it look good in the CLI! diff --git a/internal/cloud/backend_taskStages.go b/internal/cloud/backend_taskStages.go index 09acc511b20f..23000a32706a 100644 --- a/internal/cloud/backend_taskStages.go +++ b/internal/cloud/backend_taskStages.go @@ -174,22 +174,22 @@ func (b *Cloud) processStageOverrides(context *IntegrationContext, output Integr Query: "\nDo you want to override the failed policy check?", Description: "Only 'override' will be accepted to override.", } - runUrl := fmt.Sprintf(taskStageHeader, b.Hostname, b.Organization, context.Op.Workspace, context.Run.ID) + runURL := fmt.Sprintf(taskStageHeader, b.Hostname, b.Organization, context.Op.Workspace, context.Run.ID) err := b.confirm(context.StopContext, context.Op, opts, context.Run, "override") if err != nil && err != errRunOverridden { return false, fmt.Errorf( - fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runUrl), + fmt.Sprintf("Failed to override: %s\n%s\n", err.Error(), runURL), ) } if err != errRunOverridden { if _, err = b.client.TaskStages.Override(context.StopContext, taskStageID, tfe.TaskStageOverrideOptions{}); err != nil { - return false, generalError(fmt.Sprintf("Failed to override policy check.\n%s", runUrl), err) + return false, generalError(fmt.Sprintf("Failed to override policy check.\n%s", runURL), err) } else { return true, nil } } else { - output.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runUrl)) + output.Output(fmt.Sprintf("The run needs to be manually overridden or discarded.\n%s\n", runURL)) } return false, nil }