Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] - Terrenetes Download #1589

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/cmd/tnctl/create/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type RevisionCommand struct {
File string
// Provider is the name of the provider to use
Provider string
// DeleteDownload indicates we should retain the download
DeleteDownload bool
}

var revisionCommandDesc = `
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewRevisionCommand(factory cmd.Factory) *cobra.Command {

flags := c.Flags()
flags.BoolVar(&o.EnableDefaultVariables, "enable-default-variables", true, "Indicates if include variables which have defaults from the terraform module")
flags.BoolVar(&o.DeleteDownload, "delete-download", true, "Indicates if we should delete the download after the command has completed")
flags.StringVar(&o.Description, "description", "", "A human readable description of the revision and what is provides")
flags.StringVarP(&o.Name, "name", "n", "", "This name of the revision")
flags.StringVarP(&o.Revision, "revision", "r", "", "The semvar version of this revision")
Expand All @@ -128,7 +131,14 @@ func (o *RevisionCommand) Run(ctx context.Context) (err error) {
}
defer func() {
if delete {
err = os.RemoveAll(path)
retain := err

if o.DeleteDownload {
err = os.RemoveAll(path)
}
if retain != nil {
err = retain
}
}
}()
o.Println("%s Successfully downloaded module to: %s", cmd.IconGood, path)
Expand All @@ -139,7 +149,6 @@ func (o *RevisionCommand) Run(ctx context.Context) (err error) {
return fmt.Errorf("failed to load terraform module: %w", diag.Err())
}

// @step: ask the user about using the current kubeconfig to retrieve any contexts
if err := o.retrieveConfiguration(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -315,6 +324,11 @@ func (o *RevisionCommand) retrieveInputs(module *tfconfig.Module) error {
}
}

// @step: if we have nothing to select from, we can skip
if len(required) == 0 && len(optional) == 0 {
return nil
}

var selected []string
if err := survey.AskOne(&survey.MultiSelect{
Message: "What variables should be exposed to the developers?",
Expand Down
29 changes: 16 additions & 13 deletions pkg/utils/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,28 @@ func Download(ctx context.Context, source, destination string) error {
return err
}

if strings.HasPrefix(source, "http") {
source = strings.TrimPrefix(source, "http://")
source = strings.TrimPrefix(source, "https://")
// @step: just to keep the same behaviour as the previous version
if strings.HasPrefix(source, "https://github.com") {
source = strings.Replace(source, "https://github.com", "git::https://github.com", 2)
}

client := &getter.Client{
Ctx: ctx,
Dst: destination,
Detectors: []getter.Detector{
new(getter.GitHubDetector),
new(getter.GitLabDetector),
new(getter.GitDetector),
new(getter.BitBucketDetector),
new(getter.GCSDetector),
new(getter.S3Detector),
new(getter.FileDetector),
Options: []getter.ClientOption{
getter.WithMode(getter.ClientModeAny),
getter.WithDecompressors(getter.LimitedDecompressors(0, 0)),
getter.WithContext(ctx),
getter.WithDetectors([]getter.Detector{
new(getter.GitHubDetector),
new(getter.GitLabDetector),
new(getter.GitDetector),
new(getter.BitBucketDetector),
new(getter.GCSDetector),
new(getter.S3Detector),
new(getter.FileDetector),
}),
},
Mode: getter.ClientModeAny,
Options: []getter.ClientOption{},
Pwd: pwd,
Src: source,
}
Expand Down
Loading