()
| 16 | ) |
| 17 | |
| 18 | func (r *RootCmd) templateCreate() *serpent.Command { |
| 19 | var ( |
| 20 | provisioner string |
| 21 | provisionerTags []string |
| 22 | variablesFile string |
| 23 | commandLineVariables []string |
| 24 | disableEveryone bool |
| 25 | requireActiveVersion bool |
| 26 | |
| 27 | defaultTTL time.Duration |
| 28 | failureTTL time.Duration |
| 29 | dormancyThreshold time.Duration |
| 30 | dormancyAutoDeletion time.Duration |
| 31 | |
| 32 | uploadFlags templateUploadFlags |
| 33 | orgContext = NewOrganizationContext() |
| 34 | ) |
| 35 | cmd := &serpent.Command{ |
| 36 | Use: "create [name]", |
| 37 | Short: "DEPRECATED: Create a template from the current directory or as specified by flag", |
| 38 | Middleware: serpent.Chain( |
| 39 | serpent.RequireRangeArgs(0, 1), |
| 40 | cliui.DeprecationWarning( |
| 41 | "Use `coder templates push` command for creating and updating templates. \n"+ |
| 42 | "Use `coder templates edit` command for editing template settings. ", |
| 43 | ), |
| 44 | ), |
| 45 | Handler: func(inv *serpent.Invocation) error { |
| 46 | client, err := r.InitClient(inv) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | isTemplateSchedulingOptionsSet := failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 |
| 51 | |
| 52 | if isTemplateSchedulingOptionsSet || requireActiveVersion { |
| 53 | entitlements, err := client.Entitlements(inv.Context()) |
| 54 | if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound { |
| 55 | return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags") |
| 56 | } else if err != nil { |
| 57 | return xerrors.Errorf("get entitlements: %w", err) |
| 58 | } |
| 59 | |
| 60 | if isTemplateSchedulingOptionsSet { |
| 61 | if !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled { |
| 62 | return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, or --inactivity-ttl") |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if requireActiveVersion { |
| 67 | if !entitlements.Features[codersdk.FeatureAccessControl].Enabled { |
| 68 | return xerrors.Errorf("your license is not entitled to use enterprise access control, so you cannot set --require-active-version") |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | organization, err := orgContext.Selected(inv, client) |
| 74 | if err != nil { |
| 75 | return err |
no test coverage detected