diff --git a/cmd/pro/provider/list/templates.go b/cmd/pro/provider/list/templates.go index df9135cd7..556f6cbd6 100644 --- a/cmd/pro/provider/list/templates.go +++ b/cmd/pro/provider/list/templates.go @@ -100,24 +100,50 @@ func (cmd *TemplatesCmd) Run(ctx context.Context) error { return cmp.Compare(a.Value, b.Value) }) - return printOptions(&OptionsFormat{ - Options: map[string]*types.Option{ - loft.RunnerEnv: { - DisplayName: "Runner", - Description: "The DevPod Pro runner to use for a new workspace.", - Enum: runners, - Required: true, - Mutable: false, - }, - loft.TemplateOptionEnv: { - DisplayName: "Template", - Description: "The template to use for a new workspace.", - Required: true, - Enum: templates, - Default: templateList.DefaultDevPodWorkspaceTemplate, - SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable), - Mutable: true, - }, + //collect environments + environmentsList, err := managementClient.Loft().ManagementV1().DevPodEnvironmentTemplates().List(ctx, metav1.ListOptions{}) + if err != nil { + return fmt.Errorf("list environments: %w", err) + } + + environments := []types.OptionEnum{} + for _, env := range environmentsList.Items { + environments = append(environments, types.OptionEnum{ + Value: env.Name, + DisplayName: loft.DisplayName(env.Name, env.Spec.DisplayName), + }) + } + + options := map[string]*types.Option{ + loft.RunnerEnv: { + DisplayName: "Runner", + Description: "The DevPod Pro runner to use for a new workspace.", + Enum: runners, + Required: true, + Mutable: false, }, + loft.TemplateOptionEnv: { + DisplayName: "Template", + Description: "The template to use for a new workspace.", + Required: true, + Enum: templates, + Default: templateList.DefaultDevPodWorkspaceTemplate, + SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable), + Mutable: true, + }, + } + + if len(environments) > 0 { + options[loft.EnvironmentTemplateOptionEnv] = &types.Option{ + DisplayName: "Environment Template", + Description: "The template to use for creating environment", + Enum: environments, + Required: true, + Mutable: false, + } + } + + return printOptions(&OptionsFormat{ + Options: options, }) } diff --git a/cmd/pro/provider/up.go b/cmd/pro/provider/up.go index 888ee2700..252216609 100644 --- a/cmd/pro/provider/up.go +++ b/cmd/pro/provider/up.go @@ -207,6 +207,8 @@ func createWorkspace(ctx context.Context, baseClient client.Client, log log.Logg templateVersion = "" } + environmentName := os.Getenv(loft.EnvironmentTemplateOptionEnv) + // find parameters resolvedParameters, err := getParametersFromEnvironment(ctx, managementClient, workspaceInfo.ProjectName, template, templateVersion) if err != nil { @@ -239,6 +241,9 @@ func createWorkspace(ctx context.Context, baseClient client.Client, log log.Logg Name: template, Version: templateVersion, }, + EnvironmentRef: storagev1.EnvironmentRef{ + Name: environmentName, + }, }, }, } diff --git a/pkg/loft/env.go b/pkg/loft/env.go index 67e6850f7..8a9493bed 100644 --- a/pkg/loft/env.go +++ b/pkg/loft/env.go @@ -13,5 +13,7 @@ const ( TemplateOptionEnv = "LOFT_TEMPLATE" TemplateVersionOptionEnv = "LOFT_TEMPLATE_VERSION" + EnvironmentTemplateOptionEnv = "LOFT_ENVIRONMENT_TEMPLATE" + TimeoutEnv = "LOFT_TIMEOUT" )