Skip to content

Commit

Permalink
terraform updates from v1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 1, 2023
1 parent c9d5ff4 commit 35b01a9
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 46 deletions.
7 changes: 5 additions & 2 deletions completers/terraform_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package action

import "github.com/rsteube/carapace"
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

func ActionBool() carapace.Action {
return carapace.ActionValues("true", "false")
return carapace.ActionValues("true", "false").StyleF(style.ForKeyword)
}
24 changes: 13 additions & 11 deletions completers/terraform_completer/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ var applyCmd = &cobra.Command{
func init() {
carapace.Gen(applyCmd).Standalone()

applyCmd.Flags().BoolS("auto-approve", "auto-approve", false, "Skip interactive approval of plan before applying.")
applyCmd.Flags().StringS("backup", "backup", "", "Path to backup the existing state file before modifying.")
applyCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Show warnings in a more compact form that includes only the summary messages.")
applyCmd.Flags().StringS("input", "input", "", "Ask for input for variables if not directly set.")
applyCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation.")
applyCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock.")
applyCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color.")
applyCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of parallel resource operations.")
applyCmd.Flags().StringS("state", "state", "", "Path to read and save state.")
applyCmd.Flags().StringS("state-out", "state-out", "", "Path to write state to that is different than \"-state\".")
applyCmd.Flags().BoolS("auto-approve", "auto-approve", false, "Skip interactive approval of plan before applying")
applyCmd.Flags().StringS("backup", "backup", "", "Path to backup the existing state file before modifying")
applyCmd.Flags().BoolS("compact-warnings", "compact-warnings", false, "Show wanings in a more compact form that includes only the summary messages")
applyCmd.Flags().BoolS("destroy", "destroy", false, "Destroy Terraform-managed infrastructure")
applyCmd.Flags().StringS("input", "input", "", "Ask for input for variables if not directly set")
applyCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation dangerous if others might concurrently run commands against the same workspace.")
applyCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock")
applyCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color")
applyCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of parallel resource operations")
applyCmd.Flags().StringS("state", "state", "", "Path to read and save state")
applyCmd.Flags().StringS("state-out", "state-out", "", "Path to write state to that is different than \"-state\"")
rootCmd.AddCommand(applyCmd)

applyCmd.Flag("backup").NoOptDefVal = " "
applyCmd.Flag("lock-timeout").NoOptDefVal = " "
applyCmd.Flag("input").NoOptDefVal = " "
applyCmd.Flag("lock").NoOptDefVal = " "
applyCmd.Flag("lock-timeout").NoOptDefVal = " "
applyCmd.Flag("parallelism").NoOptDefVal = " "
applyCmd.Flag("state").NoOptDefVal = " "
applyCmd.Flag("state-out").NoOptDefVal = " "
Expand Down
6 changes: 3 additions & 3 deletions completers/terraform_completer/cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var consoleCmd = &cobra.Command{
func init() {
carapace.Gen(consoleCmd).Standalone()

consoleCmd.Flags().StringS("state", "state", "", "Legacy option for the local backend only.")
consoleCmd.Flags().StringArrayS("var", "var", []string{}, "Set a variable in the Terraform configuration.")
consoleCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file.")
consoleCmd.Flags().StringS("state", "state", "", "Legacy option for the local backend only")
consoleCmd.Flags().StringArrayS("var", "var", []string{}, "Set a variable in the Terraform configuration")
consoleCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file")

consoleCmd.Flag("state").NoOptDefVal = " "
consoleCmd.Flag("var-file").NoOptDefVal = " "
Expand Down
5 changes: 3 additions & 2 deletions completers/terraform_completer/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -52,11 +53,11 @@ func init() {
"out": carapace.ActionFiles(),
"refresh": action.ActionBool(),
"replace": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionResources().Invoke(c).ToMultiPartsA(".")
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
"state": carapace.ActionFiles(),
"target": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionResources().Invoke(c).ToMultiPartsA(".")
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
"var-file": carapace.ActionFiles(),
})
Expand Down
5 changes: 2 additions & 3 deletions completers/terraform_completer/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ var importCmd = &cobra.Command{
func init() {
carapace.Gen(importCmd).Standalone()

importCmd.Flags().BoolS("allow-missing-config", "allow-missing-config", false, "Allow import when no resource configuration block exists")
importCmd.Flags().StringS("config", "config", "", "Path to a directory of Terraform configuration files")
importCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only")
importCmd.Flags().StringS("input", "input", "", "Disable interactive input prompts")
importCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
importCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock")
importCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color")
importCmd.Flags().StringS("var", "var", "", "Set a variable in the Terraform configuration")
importCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file")
importCmd.Flags().StringSliceS("var", "var", []string{}, "Set a variable in the Terraform configuration")
importCmd.Flags().StringSliceS("var-file", "var-file", []string{}, "Set variables in the Terraform configuration from a file")
rootCmd.AddCommand(importCmd)

importCmd.Flag("config").NoOptDefVal = " "
Expand Down
27 changes: 15 additions & 12 deletions completers/terraform_completer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ var initCmd = &cobra.Command{
func init() {
carapace.Gen(initCmd).Standalone()

initCmd.Flags().StringS("backend", "backend", "", "Configure the backend for this configuration.")
initCmd.Flags().StringS("backend", "backend", "", "Configure the backend for this configuration")
initCmd.Flags().StringSliceS("backend-config", "backend-config", []string{}, "Backend configuration")
initCmd.Flags().BoolS("force-copy", "force-copy", false, "Suppress prompts about copying state data.")
initCmd.Flags().StringS("from-module", "from-module", "", "Copy the contents of the given module into the target directory before initialization.")
initCmd.Flags().StringS("get", "get", "", "Download any modules for this configuration.")
initCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only.")
initCmd.Flags().StringS("input", "input", "", "Ask for input if necessary.")
initCmd.Flags().StringS("lockfile", "lockfile", "", "Set a dependency lockfile mode.")
initCmd.Flags().BoolS("migrate-state", "migrate-state", false, "Reconfigure the backend, and attempt to migrate any existing state.")
initCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color.")
initCmd.Flags().BoolS("plugin-dir", "plugin-dir", false, "Directory containing plugin binaries.")
initCmd.Flags().BoolS("reconfigure", "reconfigure", false, "Reconfigure the backend, ignoring any saved configuration.")
initCmd.Flags().BoolS("force-copy", "force-copy", false, "Suppress prompts about copying state data")
initCmd.Flags().StringS("from-module", "from-module", "", "Copy the contents of the given module into the target directory before initialization")
initCmd.Flags().StringS("get", "get", "", "Download any modules for this configuration")
initCmd.Flags().BoolS("ignore-remote-version", "ignore-remote-version", false, "A rare option used for the remote backend only")
initCmd.Flags().StringS("input", "input", "", "Ask for input if necessary")
initCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during backend migration")
initCmd.Flags().StringS("lockfile", "lockfile", "", "Set a dependency lockfile mode")
initCmd.Flags().BoolS("migrate-state", "migrate-state", false, "Reconfigure the backend, and attempt to migrate any existing state")
initCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color")
initCmd.Flags().BoolS("plugin-dir", "plugin-dir", false, "Directory containing plugin binaries")
initCmd.Flags().BoolS("reconfigure", "reconfigure", false, "Reconfigure the backend, ignoring any saved configuration")
initCmd.Flags().StringS("upgrade", "upgrade", "", "ignore previously-downloaded objects and install the latest version allowed")
rootCmd.AddCommand(initCmd)

initCmd.Flag("backend").NoOptDefVal = " "
initCmd.Flag("backend-config").NoOptDefVal = " "
initCmd.Flag("backend").NoOptDefVal = " "
initCmd.Flag("from-module").NoOptDefVal = " "
initCmd.Flag("get").NoOptDefVal = " "
initCmd.Flag("input").NoOptDefVal = " "
initCmd.Flag("lock").NoOptDefVal = " "
initCmd.Flag("lockfile").NoOptDefVal = " "
initCmd.Flag("upgrade").NoOptDefVal = " "

Expand All @@ -45,6 +47,7 @@ func init() {
"backend-config": carapace.ActionFiles(),
"get": action.ActionBool(),
"input": action.ActionBool(),
"lock": action.ActionBool(),
"lockfile": carapace.ActionValues("readonly"),
"upgrade": action.ActionBool(),
})
Expand Down
18 changes: 18 additions & 0 deletions completers/terraform_completer/cmd/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var metadataCmd = &cobra.Command{
Use: "metadata",
Short: "Metadata related commands",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(metadataCmd).Standalone()

rootCmd.AddCommand(metadataCmd)
}
19 changes: 19 additions & 0 deletions completers/terraform_completer/cmd/metadata_functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var metadata_functionsCmd = &cobra.Command{
Use: "functions",
Short: "Show signatures and descriptions for the available functions",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(metadata_functionsCmd).Standalone()

metadata_functionsCmd.Flags().BoolS("json", "json", false, "Prints out a json representation of the available function signatures")
metadataCmd.AddCommand(metadata_functionsCmd)
}
2 changes: 1 addition & 1 deletion completers/terraform_completer/cmd/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var outputCmd = &cobra.Command{
func init() {
carapace.Gen(outputCmd).Standalone()

outputCmd.Flags().BoolS("json", "json", false, "Machine readable output will be printed in JSON format.")
outputCmd.Flags().BoolS("json", "json", false, "Machine readable output will be printed in JSON format")
outputCmd.Flags().BoolS("no-color", "no-color", false, "Output won't contain any color")
outputCmd.Flags().BoolS("raw", "raw", false, "print the raw string directly")
outputCmd.Flags().StringS("state", "state", "", "Path to the state file to read")
Expand Down
13 changes: 7 additions & 6 deletions completers/terraform_completer/cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -34,27 +35,27 @@ func init() {
planCmd.Flags().StringS("var-file", "var-file", "", "Load variable values from the given file.")
rootCmd.AddCommand(planCmd)

planCmd.Flag("refresh").NoOptDefVal = " "
planCmd.Flag("replace").NoOptDefVal = " "
planCmd.Flag("target").NoOptDefVal = " "
planCmd.Flag("var-file").NoOptDefVal = " "
planCmd.Flag("input").NoOptDefVal = " "
planCmd.Flag("lock").NoOptDefVal = " "
planCmd.Flag("lock-timeout").NoOptDefVal = " "
planCmd.Flag("out").NoOptDefVal = " "
planCmd.Flag("parallelism").NoOptDefVal = " "
planCmd.Flag("refresh").NoOptDefVal = " "
planCmd.Flag("replace").NoOptDefVal = " "
planCmd.Flag("state").NoOptDefVal = " "
planCmd.Flag("target").NoOptDefVal = " "
planCmd.Flag("var-file").NoOptDefVal = " "

carapace.Gen(planCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
"out": carapace.ActionFiles(),
"refresh": action.ActionBool(),
"replace": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionResources().Invoke(c).ToMultiPartsA(".")
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
"state": carapace.ActionFiles(),
"target": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionResources().Invoke(c).ToMultiPartsA(".")
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
"var-file": carapace.ActionFiles(),
})
Expand Down
5 changes: 4 additions & 1 deletion completers/terraform_completer/cmd/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand All @@ -20,6 +21,7 @@ func init() {
refreshCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
refreshCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock")
refreshCmd.Flags().BoolS("no-color", "no-color", false, "If specified, output won't contain any color")
refreshCmd.Flags().StringS("parallelism", "parallelism", "", "Limit the number of parallel resource operations")
refreshCmd.Flags().StringArrayS("target", "target", []string{}, "Resource to target")
refreshCmd.Flags().StringArrayS("var", "var", []string{}, "Set a variable in the Terraform configuration")
refreshCmd.Flags().StringS("var-file", "var-file", "", "Set variables in the Terraform configuration from a file")
Expand All @@ -28,6 +30,7 @@ func init() {
refreshCmd.Flag("input").NoOptDefVal = " "
refreshCmd.Flag("lock").NoOptDefVal = " "
refreshCmd.Flag("lock-timeout").NoOptDefVal = " "
refreshCmd.Flag("parallelism").NoOptDefVal = " "
refreshCmd.Flag("target").NoOptDefVal = " "
refreshCmd.Flag("var-file").NoOptDefVal = " "

Expand All @@ -36,7 +39,7 @@ func init() {
"input": action.ActionBool(),
"lock": action.ActionBool(),
"target": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionResources().Invoke(c).ToMultiPartsA(".")
return terraform.ActionResources().Invoke(c).ToMultiPartsA(".")
}),
"var-file": carapace.ActionFiles(),
})
Expand Down
11 changes: 11 additions & 0 deletions completers/terraform_completer/cmd/state_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -14,8 +15,18 @@ var state_pushCmd = &cobra.Command{
func init() {
carapace.Gen(state_pushCmd).Standalone()

state_pushCmd.Flags().BoolS("force", "force", false, "Write the state even if lineages don't match or the remote serial is higher")
state_pushCmd.Flags().StringS("lock", "lock", "", "Don't hold a state lock during the operation")
state_pushCmd.Flags().StringS("lock-timeout", "lock-timeout", "", "Duration to retry a state lock")
stateCmd.AddCommand(state_pushCmd)

state_pushCmd.Flag("lock").NoOptDefVal = " "
state_pushCmd.Flag("lock-timeout").NoOptDefVal = " "

carapace.Gen(state_pushCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
})

carapace.Gen(state_pushCmd).PositionalCompletion(
carapace.ActionDirectories(),
)
Expand Down
5 changes: 5 additions & 0 deletions completers/terraform_completer/cmd/untaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/spf13/cobra"
)

Expand All @@ -23,5 +24,9 @@ func init() {
untaintCmd.Flag("lock").NoOptDefVal = " "
untaintCmd.Flag("lock-timeout").NoOptDefVal = " "

carapace.Gen(untaintCmd).FlagCompletion(carapace.ActionMap{
"lock": action.ActionBool(),
})

// TODO positional completion
}
3 changes: 2 additions & 1 deletion completers/terraform_completer/cmd/workspace_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand All @@ -28,6 +29,6 @@ func init() {
})

carapace.Gen(workspace_deleteCmd).PositionalCompletion(
action.ActionWorkspaces(),
terraform.ActionWorkspaces(),
)
}
3 changes: 2 additions & 1 deletion completers/terraform_completer/cmd/workspace_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -30,6 +31,6 @@ func init() {
})

carapace.Gen(workspace_newCmd).PositionalCompletion(
action.ActionWorkspaces(),
terraform.ActionWorkspaces(),
)
}
10 changes: 9 additions & 1 deletion completers/terraform_completer/cmd/workspace_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/terraform_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/terraform"
"github.com/spf13/cobra"
)

Expand All @@ -15,9 +16,16 @@ var workspace_selectCmd = &cobra.Command{
func init() {
carapace.Gen(workspace_selectCmd).Standalone()

workspace_selectCmd.Flags().StringS("or-create", "or-create", "", "Create the Terraform workspace if it doesn't exist")
workspaceCmd.AddCommand(workspace_selectCmd)

workspace_selectCmd.Flag("or-create").NoOptDefVal = " "

carapace.Gen(workspace_selectCmd).FlagCompletion(carapace.ActionMap{
"or-create": action.ActionBool(),
})

carapace.Gen(workspace_selectCmd).PositionalCompletion(
action.ActionWorkspaces(),
terraform.ActionWorkspaces(),
)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package action
package terraform

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionResources completes resources
func ActionResources() carapace.Action {
return carapace.ActionExecCommand("terraform", "state", "list")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
Expand Down
Loading

0 comments on commit 35b01a9

Please sign in to comment.