Skip to content

Commit 1fde979

Browse files
committed
bt: add command to show config
1 parent e72ea3b commit 1fde979

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

bt/config.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/DavidGamba/dgtools/bt/config"
8+
"github.com/DavidGamba/go-getoptions"
9+
)
10+
11+
func configCMD(ctx context.Context, parent *getoptions.GetOpt) *getoptions.GetOpt {
12+
opt := parent.NewCommand("config", "Show bt config file details")
13+
opt.SetCommandFn(configRun)
14+
15+
return opt
16+
}
17+
18+
func configRun(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
19+
cfg := config.ConfigFromContext(ctx)
20+
fmt.Printf("%s", cfg)
21+
return nil
22+
}

bt/config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ func (t TerraformProfile) String() string {
7272
return output
7373
}
7474

75+
func (c Config) String() string {
76+
output := ""
77+
output += fmt.Sprintf("config_root: %s\n", c.ConfigRoot)
78+
output += fmt.Sprintf("default_terraform_profile: %s\n", c.Config.DefaultTerraformProfile)
79+
output += fmt.Sprintf("terraform_profile_env_var: %s\n", c.Config.TerraformProfileEnvVar)
80+
81+
for k := range c.TFProfile {
82+
output += fmt.Sprintf("profile '%s': %s\n", k, c.TFProfile[k])
83+
}
84+
85+
return output
86+
}
87+
7588
func (c Config) Profile(profile string) string {
7689
_, ok := c.TFProfile[profile]
7790
if !ok {

bt/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func program(args []string) int {
4141
opt.SetUnknownMode(getoptions.Pass)
4242

4343
terraform.NewCommand(ctx, opt)
44+
configCMD(ctx, opt)
4445

4546
opt.HelpCommand("help", opt.Alias("?"))
4647
remaining, err := opt.Parse(args[1:])

bt/tests/.bt.cue

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
terraform: {
2-
init: {
3-
backend_config: ["backend.tfvars"]
4-
}
5-
plan: {
6-
var_file: ["vars.tfvars"]
7-
}
8-
workspaces: {
9-
enabled: true
10-
dir: "envs"
1+
config: {
2+
default_terraform_profile: "default"
3+
terraform_profile_env_var: "BT_TERRAFORM_PROFILE"
4+
}
5+
terraform_profile: {
6+
default: {
7+
binary_name: "terraform"
8+
init: {
9+
backend_config: ["backend.tfvars"]
10+
}
11+
plan: {
12+
var_file: ["~/auth.tfvars"]
13+
}
14+
workspaces: {
15+
enabled: true
16+
dir: "envs"
17+
}
18+
pre_apply_checks: {
19+
enabled: true
20+
commands: [
21+
{name: "conftest", command: ["conftest", "test", "$TERRAFORM_JSON_PLAN"]},
22+
]
23+
}
24+
platforms: ["darwin_amd64", "darwin_arm64", "linux_amd64", "linux_arm64"]
1125
}
1226
}

0 commit comments

Comments
 (0)