diff --git a/pkg/cmd/tnctl/create/revision.go b/pkg/cmd/tnctl/create/revision.go index e991a5c5b..be4b49ecc 100644 --- a/pkg/cmd/tnctl/create/revision.go +++ b/pkg/cmd/tnctl/create/revision.go @@ -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 = ` @@ -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") @@ -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) @@ -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 } @@ -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?", diff --git a/pkg/utils/download.go b/pkg/utils/download.go index 97d2c25df..dd88567dc 100644 --- a/pkg/utils/download.go +++ b/pkg/utils/download.go @@ -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, }