Skip to content

Commit 333fbdc

Browse files
authored
Merge pull request #24989 from hashicorp/radditude/update-go-tfe
2 parents 8e1615a + 22e5a30 commit 333fbdc

File tree

8 files changed

+97
-14
lines changed

8 files changed

+97
-14
lines changed

backend/remote/backend_apply_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,41 @@ func TestRemote_applyWithTarget(t *testing.T) {
299299
}
300300
}
301301

302+
func TestRemote_applyWithTargetIncompatibleAPIVersion(t *testing.T) {
303+
b, bCleanup := testBackendDefault(t)
304+
defer bCleanup()
305+
306+
op, configCleanup := testOperationPlan(t, "./testdata/plan")
307+
defer configCleanup()
308+
309+
// Set the tfe client's RemoteAPIVersion to an empty string, to mimic
310+
// API versions prior to 2.3.
311+
b.client.SetFakeRemoteAPIVersion("")
312+
313+
addr, _ := addrs.ParseAbsResourceStr("null_resource.foo")
314+
315+
op.Targets = []addrs.Targetable{addr}
316+
op.Workspace = backend.DefaultStateName
317+
318+
run, err := b.Operation(context.Background(), op)
319+
if err != nil {
320+
t.Fatalf("error starting operation: %v", err)
321+
}
322+
323+
<-run.Done()
324+
if run.Result == backend.OperationSuccess {
325+
t.Fatal("expected apply operation to fail")
326+
}
327+
if !run.PlanEmpty {
328+
t.Fatalf("expected plan to be empty")
329+
}
330+
331+
errOutput := b.CLI.(*cli.MockUi).ErrorWriter.String()
332+
if !strings.Contains(errOutput, "Resource targeting is not supported") {
333+
t.Fatalf("expected a targeting error, got: %v", errOutput)
334+
}
335+
}
336+
302337
func TestRemote_applyWithVariables(t *testing.T) {
303338
b, bCleanup := testBackendDefault(t)
304339
defer bCleanup()

backend/remote/backend_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (b *Remote) costEstimate(stopCtx, cancelCtx context.Context, op *backend.Op
316316
b.CLI.Output(b.Colorize().Color("Waiting for cost estimate to complete..." + elapsed + "\n"))
317317
}
318318
continue
319-
case "skipped_due_to_targeting": // TEMP: not available in the go-tfe library yet; will update this to be tfe.CostEstimateSkippedDueToTargeting once that's available.
319+
case tfe.CostEstimateSkippedDueToTargeting:
320320
b.CLI.Output("Not available for this plan, because it was created with the -target option.")
321321
b.CLI.Output("\n------------------------------------------------------------------------")
322322
return nil

backend/remote/backend_plan_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,41 @@ func TestRemote_planWithTarget(t *testing.T) {
338338
}
339339
}
340340

341+
func TestRemote_planWithTargetIncompatibleAPIVersion(t *testing.T) {
342+
b, bCleanup := testBackendDefault(t)
343+
defer bCleanup()
344+
345+
op, configCleanup := testOperationPlan(t, "./testdata/plan")
346+
defer configCleanup()
347+
348+
// Set the tfe client's RemoteAPIVersion to an empty string, to mimic
349+
// API versions prior to 2.3.
350+
b.client.SetFakeRemoteAPIVersion("")
351+
352+
addr, _ := addrs.ParseAbsResourceStr("null_resource.foo")
353+
354+
op.Targets = []addrs.Targetable{addr}
355+
op.Workspace = backend.DefaultStateName
356+
357+
run, err := b.Operation(context.Background(), op)
358+
if err != nil {
359+
t.Fatalf("error starting operation: %v", err)
360+
}
361+
362+
<-run.Done()
363+
if run.Result == backend.OperationSuccess {
364+
t.Fatal("expected plan operation to fail")
365+
}
366+
if !run.PlanEmpty {
367+
t.Fatalf("expected plan to be empty")
368+
}
369+
370+
errOutput := b.CLI.(*cli.MockUi).ErrorWriter.String()
371+
if !strings.Contains(errOutput, "Resource targeting is not supported") {
372+
t.Fatalf("expected a targeting error, got: %v", errOutput)
373+
}
374+
}
375+
341376
func TestRemote_planWithVariables(t *testing.T) {
342377
b, bCleanup := testBackendDefault(t)
343378
defer bCleanup()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ require (
6464
github.com/hashicorp/go-retryablehttp v0.5.2
6565
github.com/hashicorp/go-rootcerts v1.0.0
6666
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 // indirect
67-
github.com/hashicorp/go-tfe v0.8.0
67+
github.com/hashicorp/go-tfe v0.8.1
6868
github.com/hashicorp/go-uuid v1.0.1
6969
github.com/hashicorp/go-version v1.2.0
7070
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86 h1:7YOlAIO2Y
233233
github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
234234
github.com/hashicorp/go-tfe v0.8.0 h1:kz3x3tbIKRkEAzKg05P/qbFY88fkEU7TiSX3w8xUrmE=
235235
github.com/hashicorp/go-tfe v0.8.0/go.mod h1:XAV72S4O1iP8BDaqiaPLmL2B4EE6almocnOn8E8stHc=
236+
github.com/hashicorp/go-tfe v0.8.1 h1:J6ulpLaKPHrcnwudRjxvlMYIGzqQFlnPhg3SVFh5N4E=
237+
github.com/hashicorp/go-tfe v0.8.1/go.mod h1:XAV72S4O1iP8BDaqiaPLmL2B4EE6almocnOn8E8stHc=
236238
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
237239
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
238240
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

vendor/github.com/hashicorp/go-tfe/cost_estimate.go

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/go-tfe/tfe.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ github.com/hashicorp/go-safetemp
348348
github.com/hashicorp/go-slug
349349
# github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86
350350
## explicit
351-
# github.com/hashicorp/go-tfe v0.8.0
351+
# github.com/hashicorp/go-tfe v0.8.1
352352
## explicit
353353
github.com/hashicorp/go-tfe
354354
# github.com/hashicorp/go-uuid v1.0.1

0 commit comments

Comments
 (0)