Skip to content

Commit

Permalink
terraform_cli: support path and env and in terraform_cli blocks
Browse files Browse the repository at this point in the history
At some point during the serial to multiplex rewrite of Enos we stopped
respecting the special `path` and `env` attributes in `terraform_cli`
blocks.

I discovered this when attempting to test an older version of Terraform
with enos by setting the `path` and it was still resolving the latest
version which it found via the `PATH`.

This resolves that by configuring the Terraform executor in the
workspace with any special `terraform_cli` variables that have been set
in the flight plan.

Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed Jul 3, 2024
1 parent 62f3a69 commit 8096df9
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 150 deletions.
15 changes: 13 additions & 2 deletions internal/server/service_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (s *ServiceV1) dispatch(
flightplan.DecodeTargetAll,
f,
)

hclDiags := scenarioDecoder.DecodeAll(ctx, fp)
if len(hclDiags) > 0 {
decRes.Diagnostics = append(decRes.GetDiagnostics(), diagnostics.FromHCL(nil, hclDiags)...)
Expand Down Expand Up @@ -381,11 +382,21 @@ func (s *ServiceV1) dispatch(

for _, scenario := range scenarios {
req := &pb.Operation_Request{}

// Configure our Terraform executor with any values that are present in the "terraform_cli" block
if cli := scenario.TerraformCLI; cli != nil {
if cli.Path != "" {
baseReq.Workspace.TfExecCfg.BinPath = cli.Path
}
for k, v := range cli.Env {
baseReq.Workspace.TfExecCfg.Env[k] = v
}
}

err := proto.Copy(baseReq, req)
if err != nil {
diags = append(diags, diagnostics.FromErr(err)...)

continue
break
}

req.Scenario = scenario.Ref()
Expand Down
Loading

0 comments on commit 8096df9

Please sign in to comment.