Skip to content

Commit

Permalink
🐛 fix terraform cli interaction (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlimus authored Sep 30, 2023
1 parent b18ce89 commit 5e59bf1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions providers/terraform/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import (
)

const (
// asset connection types, used internally
StateConnectionType = "terraform-state"
PlanConnectionType = "terraform-plan"
HclConnectionType = "terraform-hcl"
HclGitConnectionType = "terraform-hcl-git"
// CLI keywords, e.g. `<binary> run terraform plan file.json ...`
CLIPlan = "plan"
CLIHcl = "hcl"
CLIState = "state"
)

type Service struct {
Expand Down Expand Up @@ -51,14 +56,23 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error)
// and later on decide which thing to call based on the conn.Type
// below in this file we already have something similar:
// tc.Options["asset-type"] == "state"
switch req.Args[0] {
case StateConnectionType, PlanConnectionType, HclConnectionType:
conf.Type = req.Args[0]
if len(req.Args) > 1 {
conf.Options["path"] = req.Args[1]
} else {
action := req.Args[0]
switch action {
case CLIPlan, CLIHcl, CLIState:
switch action {
case CLIPlan:
conf.Type = PlanConnectionType
case CLIHcl:
conf.Type = HclConnectionType
case CLIState:
conf.Type = StateConnectionType
}

if len(req.Args) < 2 {
return nil, errors.New("no path provided")
}
conf.Options["path"] = req.Args[1]

default:
if len(req.Args) > 1 {
return nil, errors.New("unknown set of arguments, use 'state <path>', 'plan <path>' or 'hcl <path>'")
Expand Down

0 comments on commit 5e59bf1

Please sign in to comment.