diff --git a/backend/remote/backend_common.go b/backend/remote/backend_common.go index d1f56b4b3..5ebd0f61a 100644 --- a/backend/remote/backend_common.go +++ b/backend/remote/backend_common.go @@ -275,8 +275,8 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op deltaRepr := strings.Replace(ce.DeltaMonthlyCost, "-", "", 1) if b.CLI != nil { - b.CLI.Output(b.Colorize().Color(fmt.Sprintf("Resources: %s of %s estimated", ce.MatchedResourcesCount, ce.ResourcesCount))) - b.CLI.Output(b.Colorize().Color(fmt.Sprintf("\t$%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr))) + b.CLI.Output(b.Colorize().Color(fmt.Sprintf("Resources: %d of %d estimated", ce.MatchedResourcesCount, ce.ResourcesCount))) + b.CLI.Output(b.Colorize().Color(fmt.Sprintf(" $%s/mo %s$%s", ce.ProposedMonthlyCost, sign, deltaRepr))) if len(r.PolicyChecks) == 0 && r.HasChanges && op.Type == backend.OperationTypeApply { b.CLI.Output("\n------------------------------------------------------------------------") @@ -297,7 +297,7 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op elapsed = fmt.Sprintf( " (%s elapsed)", current.Sub(started).Truncate(30*time.Second)) } - b.CLI.Output(b.Colorize().Color("Waiting for cost estimation to complete..." + elapsed)) + b.CLI.Output(b.Colorize().Color("Waiting for cost estimation to complete..." + elapsed + "\n")) } continue case tfe.CostEstimateErrored: diff --git a/backend/remote/backend_plan.go b/backend/remote/backend_plan.go index ca49ae24b..9563080e1 100644 --- a/backend/remote/backend_plan.go +++ b/backend/remote/backend_plan.go @@ -316,6 +316,14 @@ to capture the filesystem context the remote workspace expects: return r, nil } + // Show any cost estimation output. + if r.CostEstimate != nil { + err = b.costEstimate(stopCtx, cancelCtx, op, r) + if err != nil { + return r, err + } + } + // Check any configured sentinel policies. if len(r.PolicyChecks) > 0 { err = b.checkPolicy(stopCtx, cancelCtx, op, r) diff --git a/go.mod b/go.mod index 263bb0412..d8a039ae1 100644 --- a/go.mod +++ b/go.mod @@ -63,7 +63,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.5.2 github.com/hashicorp/go-rootcerts v1.0.0 github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect - github.com/hashicorp/go-tfe v0.3.22 + github.com/hashicorp/go-tfe v0.3.23 github.com/hashicorp/go-uuid v1.0.1 github.com/hashicorp/go-version v1.1.0 github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f diff --git a/go.sum b/go.sum index 4f256f40f..ed573374e 100644 --- a/go.sum +++ b/go.sum @@ -202,6 +202,8 @@ github.com/hashicorp/go-tfe v0.3.21 h1:JVB+DqX4zevWmaVHGsJfElyScf1ZjbF6EUDLPzU96 github.com/hashicorp/go-tfe v0.3.21/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM= github.com/hashicorp/go-tfe v0.3.22 h1:Wodv4Y3kiC6bTPHQzhrn026V3HLhfwhc1rVlLY8suKs= github.com/hashicorp/go-tfe v0.3.22/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM= +github.com/hashicorp/go-tfe v0.3.23 h1:kd9hlFQvGubNF/CpF7T5AP/xU8uLUq8ANbI5xRDVSms= +github.com/hashicorp/go-tfe v0.3.23/go.mod h1:SuPHR+OcxvzBZNye7nGPfwZTEyd3rWPfLVbCgyZPezM= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= diff --git a/vendor/github.com/hashicorp/go-tfe/cost_estimate.go b/vendor/github.com/hashicorp/go-tfe/cost_estimate.go index f73c75c8f..b0ccecfb4 100644 --- a/vendor/github.com/hashicorp/go-tfe/cost_estimate.go +++ b/vendor/github.com/hashicorp/go-tfe/cost_estimate.go @@ -47,13 +47,13 @@ type CostEstimate struct { ID string `jsonapi:"primary,cost-estimates"` DeltaMonthlyCost string `jsonapi:"attr,delta-monthly-cost"` ErrorMessage string `jsonapi:"attr,error-message"` - MatchedResourcesCount string `jsonapi:"attr,matched-resources-count"` + MatchedResourcesCount int `jsonapi:"attr,matched-resources-count"` PriorMonthlyCost string `jsonapi:"attr,prior-monthly-cost"` ProposedMonthlyCost string `jsonapi:"attr,proposed-monthly-cost"` - ResourcesCount string `jsonapi:"attr,resources-count"` + ResourcesCount int `jsonapi:"attr,resources-count"` Status CostEstimateStatus `jsonapi:"attr,status"` StatusTimestamps *CostEstimateStatusTimestamps `jsonapi:"attr,status-timestamps"` - UnmatchedResourcesCount string `jsonapi:"attr,unmatched-resources-count"` + UnmatchedResourcesCount int `jsonapi:"attr,unmatched-resources-count"` } // CostEstimateStatusTimestamps holds the timestamps for individual costEstimate statuses. diff --git a/vendor/modules.txt b/vendor/modules.txt index aebc1ce44..0a66ab626 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -315,7 +315,7 @@ github.com/hashicorp/go-rootcerts github.com/hashicorp/go-safetemp # github.com/hashicorp/go-slug v0.3.0 github.com/hashicorp/go-slug -# github.com/hashicorp/go-tfe v0.3.22 +# github.com/hashicorp/go-tfe v0.3.23 github.com/hashicorp/go-tfe # github.com/hashicorp/go-uuid v1.0.1 github.com/hashicorp/go-uuid