From 650a272a1d1e04e343045982bdb9b98993c6caea Mon Sep 17 00:00:00 2001 From: Mike Nomitch Date: Wed, 13 May 2020 10:05:22 -0500 Subject: [PATCH] Change message sent to remote backend if -target used --- backend/remote/backend_mock.go | 4 ++++ backend/remote/backend_plan.go | 7 ++++++- backend/remote/backend_plan_test.go | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/remote/backend_mock.go b/backend/remote/backend_mock.go index 0a57801e8..a856b0612 100644 --- a/backend/remote/backend_mock.go +++ b/backend/remote/backend_mock.go @@ -760,6 +760,10 @@ func (m *mockRuns) Create(ctx context.Context, options tfe.RunCreateOptions) (*t TargetAddrs: options.TargetAddrs, } + if options.Message != nil { + r.Message = *options.Message + } + if pc != nil { r.PolicyChecks = []*tfe.PolicyCheck{pc} } diff --git a/backend/remote/backend_plan.go b/backend/remote/backend_plan.go index 8b37f62e1..957b28aea 100644 --- a/backend/remote/backend_plan.go +++ b/backend/remote/backend_plan.go @@ -209,9 +209,14 @@ in order to capture the filesystem context the remote workspace expects: "Failed to upload configuration files", errors.New("operation timed out")) } + queueMessage := "Queued manually using Terraform" + if op.Targets != nil { + queueMessage = "Queued manually via Terraform using -target" + } + runOptions := tfe.RunCreateOptions{ IsDestroy: tfe.Bool(op.Destroy), - Message: tfe.String("Queued manually using Terraform"), + Message: tfe.String(queueMessage), ConfigurationVersion: cv, Workspace: w, } diff --git a/backend/remote/backend_plan_test.go b/backend/remote/backend_plan_test.go index 7ea84694b..89cdc1ff1 100644 --- a/backend/remote/backend_plan_test.go +++ b/backend/remote/backend_plan_test.go @@ -301,6 +301,10 @@ func TestRemote_planWithTarget(t *testing.T) { if diff := cmp.Diff([]string{"null_resource.foo"}, run.TargetAddrs); diff != "" { t.Errorf("wrong TargetAddrs in the created run\n%s", diff) } + + if !strings.Contains(run.Message, "using -target") { + t.Fatalf("incorrrect Message on the created run: %s", run.Message) + } } }