Skip to content

Commit eb26ae7

Browse files
committed
Add OpenTofu CLI support to Terraform plugin
Add OpenTofu as a new executable in the existing Terraform plugin, allowing `tofu` commands to authenticate via 1Password shell plugins. Closes #483
1 parent 49810df commit eb26ae7

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

plugins/terraform/opentofu.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package terraform
2+
3+
import (
4+
"github.com/1Password/shell-plugins/sdk"
5+
"github.com/1Password/shell-plugins/sdk/needsauth"
6+
"github.com/1Password/shell-plugins/sdk/schema"
7+
)
8+
9+
func OpenTofuCLI() schema.Executable {
10+
return schema.Executable{
11+
Name: "OpenTofu CLI",
12+
Runs: []string{"tofu"},
13+
DocsURL: sdk.URL("https://opentofu.org/docs/cli/"),
14+
NeedsAuth: needsauth.IfAll(
15+
needsauth.NotForHelpOrVersion(),
16+
needsauth.NotWithoutArgs(),
17+
),
18+
Uses: []schema.CredentialUsage{
19+
{
20+
Description: "Credentials to use within the OpenTofu project",
21+
SelectFrom: &schema.CredentialSelection{
22+
ID: "project",
23+
IncludeAllCredentials: true,
24+
AllowMultiple: true,
25+
},
26+
Optional: true,
27+
NeedsAuth: needsauth.IfAny(
28+
needsauth.ForCommand("refresh"),
29+
needsauth.ForCommand("init"),
30+
needsauth.ForCommand("state"),
31+
needsauth.ForCommand("plan"),
32+
needsauth.ForCommand("apply"),
33+
needsauth.ForCommand("destroy"),
34+
needsauth.ForCommand("import"),
35+
needsauth.ForCommand("test"),
36+
),
37+
},
38+
},
39+
}
40+
}

plugins/terraform/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func New() schema.Plugin {
1414
},
1515
Executables: []schema.Executable{
1616
TerraformCLI(),
17+
OpenTofuCLI(),
1718
},
1819
}
1920
}

0 commit comments

Comments
 (0)