Add VCS module publish command - #105
Conversation
paladin-devops
left a comment
There was a problem hiding this comment.
I have some pretty minor feedback, great job adding this command!
| ShortHelp: "Manage private registry modules.", | ||
| LongHelp: heredoc.New(inv.IO).Mustf(` | ||
| The {{ template "mdCodeOrBold" "%s module" }} command group lets you manage | ||
| private registry modules in HCP Terraform and Terraform Enterprise. | ||
| `, version.Name), |
There was a problem hiding this comment.
Good description and short help text. 👍🏻
| if opts.Quiet { | ||
| logger.Debug("Quiet mode enabled, rendering skipped") | ||
| return nil | ||
| } | ||
|
|
There was a problem hiding this comment.
We should drain the body before returning here. This way, if the server were to have keep-alives enabled, then the TCP connection could be returned to the connection pool, instead of being closed, which is the default behavior of Go's HTTP implementation for undrained response body.
| if opts.Quiet { | |
| logger.Debug("Quiet mode enabled, rendering skipped") | |
| return nil | |
| } | |
| if opts.Quiet { | |
| logger.Debug("Quiet mode enabled, rendering skipped") | |
| io.Copy(io.Discard, resp.Body) | |
| return nil | |
| } |
| @@ -0,0 +1,3 @@ | |||
| kind: ENHANCEMENTS | |||
| body: "Added `tfctl module publish` for publishing VCS-backed private registry modules from existing OAuth or GitHub App connections" | |||
There was a problem hiding this comment.
nit: Present-tense changelog note.
| body: "Added `tfctl module publish` for publishing VCS-backed private registry modules from existing OAuth or GitHub App connections" | |
| body: "tfctl now has `tfctl module publish` for publishing VCS-backed private registry modules from existing OAuth or GitHub App connections." |
| if response.Data.Links.Self != "" { | ||
| result.SelfLink, err = resolvePublishSelfLink(opts.Client.BaseURL, response.Data.Links.Self) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to resolve registry module self link: %w", err) |
There was a problem hiding this comment.
We should add a test to publish_test.go for this error case.
| return fields | ||
| } | ||
|
|
||
| func resolvePublishSelfLink(base *url.URL, self string) (string, error) { |
There was a problem hiding this comment.
I think that we could add some tests to publish_test.go, maybe in a new function TestResolvePublishSelfLink, which just tests this function's paths, rather than doing so implicitly via TestRunPublishOutputFormats.
| }) | ||
| }, | ||
| }) | ||
| opts.Quiet = true |
There was a problem hiding this comment.
Does Quiet need to be true for this test?
Description
Adds
tfctl module publishfor publishing VCS private registry modules from existing OAuth or GitHub App connections.The command:
go-tfe/v2does not yet provide a method for this endpoint.For repositories that follow the standard
terraform-<provider>-<name>naming convention, HCP Terraform automatically determines the module name and provider. Custom name/provider overrides and repositories requiring different VCS identifier and display-identifier values are outside this initial scope and can usetfctl api.Validation completed:
go test ./internal/commands/module ./internal/commands/root -count=1make gen/screenshotmake binmake checkgo test ./... -racegit diff --checkExample Output
Tag-based publishing dry run:
Branch-based publishing:
PR Checklist
--json— Forces machine-readable output to stdout.--markdown— Forces Markdown output to stdout.--dry-run— Resolves and validates the request without sending a mutation.--quiet— Suppresses successful output and unessential guidance.make gen/screenshot.PCI review checklist