From 883339be25dd11272b2bb96bea7e9c7be18f1a29 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 29 Jul 2020 01:50:11 -0700 Subject: [PATCH] Set project via project flag, not setting in the config (#9662) * set project via project flag, not setting in the config + tests --- builder/googlecompute/step_start_tunnel.go | 5 +---- builder/googlecompute/step_start_tunnel_test.go | 9 ++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/builder/googlecompute/step_start_tunnel.go b/builder/googlecompute/step_start_tunnel.go index f52839e8a..023ba1988 100644 --- a/builder/googlecompute/step_start_tunnel.go +++ b/builder/googlecompute/step_start_tunnel.go @@ -196,13 +196,11 @@ func (s *StepStartTunnel) createTempGcloudScript(args []string) (string, error) launchTemplate := ` gcloud auth activate-service-account --key-file='{{.AccountFile}}' -gcloud config set project {{.ProjectID}} {{.Args}} ` if runtime.GOOS == "windows" { launchTemplate = ` call gcloud auth activate-service-account --key-file "{{.AccountFile}}" -call gcloud config set project {{.ProjectID}} call {{.Args}} ` } @@ -215,7 +213,6 @@ call {{.Args}} opts := map[string]string{ "AccountFile": s.AccountFile, - "ProjectID": s.ProjectId, "Args": argString, } @@ -276,7 +273,7 @@ func (s *StepStartTunnel) Run(ctx context.Context, state multistep.StateBag) mul args := []string{"compute", "start-iap-tunnel", instanceName, strconv.Itoa(s.CommConf.Port()), fmt.Sprintf("--local-host-port=localhost:%d", s.IAPConf.IAPLocalhostPort), - "--zone", c.Zone, + "--zone", c.Zone, "--project", s.ProjectId, } // This is the port the IAP tunnel listens on, on localhost. diff --git a/builder/googlecompute/step_start_tunnel_test.go b/builder/googlecompute/step_start_tunnel_test.go index b82411e86..a65d457dd 100644 --- a/builder/googlecompute/step_start_tunnel_test.go +++ b/builder/googlecompute/step_start_tunnel_test.go @@ -49,7 +49,8 @@ func TestStepStartTunnel_CreateTempScript(t *testing.T) { s := getTestStepStartTunnel() args := []string{"compute", "start-iap-tunnel", "fakeinstance-12345", - "1234", "--local-host-port=localhost:8774", "--zone", "us-central-b"} + "1234", "--local-host-port=localhost:8774", "--zone", "us-central-b", + "--project", "fake-project-123"} scriptPath, err := s.createTempGcloudScript(args) if err != nil { @@ -65,16 +66,14 @@ func TestStepStartTunnel_CreateTempScript(t *testing.T) { expected := `#!/bin/bash gcloud auth activate-service-account --key-file='/path/to/account_file.json' -gcloud config set project fake-project-123 -gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b +gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b --project fake-project-123 ` if runtime.GOOS == "windows" { // in real life you'd not be passing a HashBang here, but GIGO. expected = `#!/bin/bash call gcloud auth activate-service-account --key-file "/path/to/account_file.json" -call gcloud config set project fake-project-123 -call gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b +call gcloud compute start-iap-tunnel fakeinstance-12345 1234 --local-host-port=localhost:8774 --zone us-central-b --project fake-project-123 ` } if fmt.Sprintf("%s", f) != expected {