Skip to content

Commit 6af6659

Browse files
authored
Refactor Project Commands and Docs (#186)
- Added `tfx project show` command for displaying detailed project information - Enhanced documentation with new project command docs and improved configuration - Updated build tools and configuration handling
1 parent a998fd4 commit 6af6659

File tree

15 files changed

+250
-29
lines changed

15 files changed

+250
-29
lines changed

.github/workflows/docs-deploy.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ name: Build and Deploy Docs https://tfx.rocks
44
# Controls when the workflow will run
55
on:
66
# Triggers the workflow on push or pull request events but only for the "main" branch
7-
push:
8-
branches:
9-
- "main"
10-
paths:
11-
- site/**
7+
# push:
8+
# branches:
9+
# - "main"
10+
# paths:
11+
# - site/**
12+
# Only allow manual publishing while I clean up the docs
1213

1314
# Allows you to run this workflow manually from the Actions tab
1415
workflow_dispatch:

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install Go
2828
uses: actions/setup-go@v4
2929
with:
30-
go-version: 1.23.1
30+
go-version: 1.25.1
3131
- name: Install gox
3232
run: |
3333
go get github.com/mitchellh/gox

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: Set up Go
2828
uses: actions/setup-go@v4
2929
with:
30-
go-version: 1.23
30+
go-version: 1.25
3131
-
3232
name: Set up QEMU
3333
uses: docker/setup-qemu-action@v2

.vscode/launch.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"request": "launch",
125125
"mode": "auto",
126126
"program": "${fileDirname}/../main.go",
127-
"args": ["gpg", "list", "--tfeOrganization=terraform-tom"]
127+
"args": ["admin", "gpg", "list", "--tfeOrganization=terraform-tom"]
128128
},
129129
{
130130
"name": "TFX - GPG Keys Delete",
@@ -227,6 +227,14 @@
227227
"mode": "auto",
228228
"program": "${fileDirname}/../main.go",
229229
"args": ["variable", "show", "-w=tfx-test", "-k=variable3"]
230+
},
231+
{
232+
"name": "TFX - project show",
233+
"type": "go",
234+
"request": "launch",
235+
"mode": "auto",
236+
"program": "${fileDirname}/../main.go",
237+
"args": ["project", "show", "-i=prj-bXXfedUa9Xa598L8"]
230238
}
231239
]
232240
}

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [v0.1.5] - TBD
9+
10+
**Added**
11+
12+
* Added `tfx project list`
13+
14+
**Changed**
15+
16+
* Removed HCL Configuration Option
17+
* Better Config File error handling (and update to maintain .hcl configuration files)
18+
819
## [v0.1.4] - 2024.10.29
920

1021
**Added**

Taskfile.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ tasks:
1717
desc: Upgrade Go dependencies
1818
cmds:
1919
- go get -u ./...
20-
- go mod tidy
20+
- go mod tidy
21+
serve-docs:
22+
desc: Serve documentation site
23+
cmds:
24+
- mkdocs serve -f site/mkdocs.yml

cmd/helper_logs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ func logError(err error, message string) {
1717

1818
// Warning but dont exit
1919
func logWarning(err error, message string) {
20-
fmt.Println()
21-
fmt.Println()
22-
fmt.Println(color.YellowString("Error: " + message))
20+
fmt.Println(color.YellowString("Warning: " + message))
2321
}

cmd/project.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,32 @@ var (
6868
}
6969
},
7070
}
71+
72+
// `tfx project show` command
73+
projectShowCmd = &cobra.Command{
74+
Use: "show",
75+
Short: "Show project details",
76+
Long: "Show Project in a TFx Organization.",
77+
RunE: func(cmd *cobra.Command, args []string) error {
78+
return projectShow(
79+
getTfxClientContext(),
80+
*viperString("id"))
81+
},
82+
}
7183
)
7284

7385
func init() {
7486
// `tfx project list`
7587
projectListCmd.Flags().StringP("search", "s", "", "Search string for Project Name (optional).")
7688
projectListCmd.Flags().BoolP("all", "a", false, "List All Organizations Projects (optional).")
7789

90+
// `tfx project show`
91+
projectShowCmd.Flags().StringP("id", "i", "", "ID of the project.")
92+
projectShowCmd.MarkFlagRequired("id")
93+
7894
rootCmd.AddCommand(projectCmd)
7995
projectCmd.AddCommand(projectListCmd)
96+
projectCmd.AddCommand(projectShowCmd)
8097

8198
}
8299

@@ -163,3 +180,36 @@ func projectList(c TfxClientContext, searchString string) error {
163180

164181
return nil
165182
}
183+
184+
func projectShow(c TfxClientContext, projectId string) error {
185+
o.AddMessageUserProvided("Show Project:", projectId)
186+
p, err := c.Client.Projects.ReadWithOptions(c.Context, projectId, tfe.ProjectReadOptions{
187+
Include: []tfe.ProjectIncludeOpt{
188+
tfe.ProjectEffectiveTagBindings,
189+
},
190+
})
191+
192+
if err != nil {
193+
logError(err, "failed to read project")
194+
}
195+
196+
o.AddDeferredMessageRead("Name", p.Name)
197+
o.AddDeferredMessageRead("ID", p.ID)
198+
o.AddDeferredMessageRead("Description", p.Description)
199+
o.AddDeferredMessageRead("DefaultExecutionMode", p.DefaultExecutionMode)
200+
201+
var duration string
202+
if p.AutoDestroyActivityDuration.IsSpecified() {
203+
if duration, err = p.AutoDestroyActivityDuration.Get(); err == nil {
204+
}
205+
}
206+
o.AddDeferredMessageRead("Auto Destroy Activity Duration", duration)
207+
208+
tags := make(map[string]interface{})
209+
for _, i := range p.EffectiveTagBindings {
210+
tags[i.Key] = i.Value
211+
}
212+
o.AddDeferredMapMessageRead("Tags", tags)
213+
214+
return nil
215+
}

cmd/root.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ package cmd
2323
import (
2424
"log"
2525

26+
"github.com/go-viper/encoding/hcl"
27+
2628
"github.com/logrusorgru/aurora"
2729
"github.com/spf13/cobra"
2830
"github.com/spf13/pflag"
@@ -111,12 +113,21 @@ func initConfig() {
111113
viper.SetConfigName(".tfx")
112114
}
113115

114-
viper.AutomaticEnv() // read in environment variables that match
116+
// Load 3rd party extension for HCL
117+
codecRegistry := viper.NewCodecRegistry()
118+
codecRegistry.RegisterCodec("hcl", hcl.Codec{})
119+
viper.SetOptions(viper.WithCodecRegistry(codecRegistry))
120+
121+
// read in environment variables that match
122+
viper.AutomaticEnv()
115123

116124
// If a config file is found, read it in.
117125
isConfigFile := false
118-
if err := viper.ReadInConfig(); err == nil {
126+
err := viper.ReadInConfig()
127+
if err == nil {
119128
isConfigFile = true // Capture information here to bring after all flags are loaded (namely which output type)
129+
} else {
130+
logWarning(err, "Unable to parse config file, will continue without it.")
120131
}
121132

122133
// Some hacking here to let viper use the cobra required flags, simplifies this checking

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/cavaliergopher/grab/v3 v3.0.1
99
github.com/coreos/go-semver v0.3.1
1010
github.com/fatih/color v1.18.0
11+
github.com/go-viper/encoding/hcl v0.1.0
1112
github.com/hashicorp/go-slug v0.16.7
1213
github.com/hashicorp/go-tfe v1.91.1
1314
github.com/jedib0t/go-pretty v4.3.0+incompatible
@@ -31,7 +32,9 @@ require (
3132
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
3233
github.com/google/uuid v1.6.0 // indirect
3334
github.com/hashicorp/go-version v1.7.0 // indirect
35+
github.com/hashicorp/hcl v1.0.0 // indirect
3436
github.com/json-iterator/go v1.1.12 // indirect
37+
github.com/mitchellh/mapstructure v1.5.0 // indirect
3538
github.com/mmcdole/goxpp v1.1.1 // indirect
3639
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3740
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -53,7 +56,6 @@ require (
5356
github.com/mattn/go-colorable v0.1.14 // indirect
5457
github.com/mattn/go-isatty v0.0.20 // indirect
5558
github.com/mattn/go-runewidth v0.0.16 // indirect
56-
github.com/mitchellh/mapstructure v1.5.0 // indirect
5759
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
5860
github.com/rivo/uniseg v0.4.7 // indirect
5961
github.com/spf13/afero v1.14.0 // indirect

0 commit comments

Comments
 (0)