Skip to content

Add "workspace" subcommand to NeedsAuth in Terraform shell plugin #581

@moraisph

Description

@moraisph

Platform or tool

HashiCorp Terraform

Desired or expected behavior

The Terraform shell plugin does not trigger authentication for the workspace subcommand.
As a result, commands such as:

terraform workspace list
terraform workspace select
terraform workspace new

do not provision credentials via the 1Password plugin, even though these commands require backend authentication. This leads to backend credential resolution failure such as:

Error: error configuring S3 Backend: no valid credential sources for S3 Backend found.

The expected behavior is having the workspace subcommand triggering authentication in the same way as init and state.

Proposed change:

needsauth.ForCommand("workspace"),

added to the existing NeedsAuth list.

Location: plugins/terraform/terraform.go

Inside the NeedsAuth Block

	NeedsAuth: needsauth.IfAny(
		needsauth.ForCommand("refresh"),
		needsauth.ForCommand("init"),
		needsauth.ForCommand("state"),
		needsauth.ForCommand("plan"),
		needsauth.ForCommand("apply"),
		needsauth.ForCommand("destroy"),
		needsauth.ForCommand("import"),
		needsauth.ForCommand("test"),
		needsauth.ForCommand("workspace"),
	),

Current behavior

In plugins/terraform/terraform.go, the NeedsAuth block includes:

needsauth.ForCommand("refresh"),
needsauth.ForCommand("init"),
needsauth.ForCommand("state"),
needsauth.ForCommand("plan"),
needsauth.ForCommand("apply"),
needsauth.ForCommand("destroy"),
needsauth.ForCommand("import"),
needsauth.ForCommand("test"),

However, workspace is not included.

Because of this:

terraform init -> triggers authentication and it works
terraform plan/apply -> triggers authentication and it works
terraform workspace -> does NOT trigger authentication and fails

Since workspace interacts directly with the backend, it requires valid AWS credentials just like init.

Relevant log output

op CLI version

2.33.0-beta.02

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions