mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Update CLI to handle managed variables (#6220)
* WIP * hcl * useManagedVariables * fix * Fix * Fix * fix * go:build * Fix * fix: bool flag * Insert template variables * API * fix * Expose via API * More wiring * CLI for testing purposes * WIP * Delete FIXME * planVars * WIP * WIP * UserVariableValues * no dry run * Dry run * Done FIXME * Fix * Fix: CLI * Fix: migration * API tests * Test info * Tests * More tests * fix: lint * Fix: authz * Address PR comments * Fix * fix * fix * CLI: create * unit tests: create templates with variables * Use last variables * Fix * Fix * Fix * Push tests * fix: variable is required if Default is nil * WIP * Redact sensitive values * Fixes * Fixes * Fix: arg description * Fix * Variable param * Fix: gen * Fix * Fix: goldens
This commit is contained in:
+17
-4
@@ -25,6 +25,8 @@ func templateCreate() *cobra.Command {
|
||||
provisioner string
|
||||
provisionerTags []string
|
||||
parameterFile string
|
||||
variablesFile string
|
||||
variables []string
|
||||
defaultTTL time.Duration
|
||||
|
||||
uploadFlags templateUploadFlags
|
||||
@@ -76,6 +78,8 @@ func templateCreate() *cobra.Command {
|
||||
FileID: resp.ID,
|
||||
ParameterFile: parameterFile,
|
||||
ProvisionerTags: tags,
|
||||
VariablesFile: variablesFile,
|
||||
Variables: variables,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -113,6 +117,8 @@ func templateCreate() *cobra.Command {
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(¶meterFile, "parameter-file", "", "", "Specify a file path with parameter values.")
|
||||
cmd.Flags().StringVarP(&variablesFile, "variables-file", "", "", "Specify a file path with values for Terraform-managed variables.")
|
||||
cmd.Flags().StringArrayVarP(&variables, "variable", "", []string{}, "Specify a set of values for Terraform-managed variables.")
|
||||
cmd.Flags().StringArrayVarP(&provisionerTags, "provisioner-tag", "", []string{}, "Specify a set of tags to target provisioner daemons.")
|
||||
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 24*time.Hour, "Specify a default TTL for workspaces created from this template.")
|
||||
uploadFlags.register(cmd.Flags())
|
||||
@@ -133,7 +139,10 @@ type createValidTemplateVersionArgs struct {
|
||||
Provisioner database.ProvisionerType
|
||||
FileID uuid.UUID
|
||||
ParameterFile string
|
||||
ValuesFile string
|
||||
|
||||
VariablesFile string
|
||||
Variables []string
|
||||
|
||||
// Template is only required if updating a template's active version.
|
||||
Template *codersdk.Template
|
||||
// ReuseParameters will attempt to reuse params from the Template field
|
||||
@@ -146,13 +155,17 @@ type createValidTemplateVersionArgs struct {
|
||||
func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVersionArgs, parameters ...codersdk.CreateParameterRequest) (*codersdk.TemplateVersion, []codersdk.CreateParameterRequest, error) {
|
||||
client := args.Client
|
||||
|
||||
// FIXME(mtojek): I will iterate on CLI experience in the follow-up.
|
||||
// see: https://github.com/coder/coder/issues/5980
|
||||
variableValues, err := loadVariableValues(args.ValuesFile)
|
||||
variableValues, err := loadVariableValuesFromFile(args.VariablesFile)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
variableValuesFromKeyValues, err := loadVariableValuesFromOptions(args.Variables)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
variableValues = append(variableValues, variableValuesFromKeyValues...)
|
||||
|
||||
req := codersdk.CreateTemplateVersionRequest{
|
||||
Name: args.Name,
|
||||
StorageMethod: codersdk.ProvisionerStorageMethodFile,
|
||||
|
||||
Reference in New Issue
Block a user