Skip to content

Push, but create if does not exist: coder templates push --create #6851

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

Closed
bpmct opened this issue Mar 28, 2023 · 5 comments · Fixed by #8454
Closed

Push, but create if does not exist: coder templates push --create #6851

bpmct opened this issue Mar 28, 2023 · 5 comments · Fixed by #8454
Assignees

Comments

@bpmct
Copy link
Member

bpmct commented Mar 28, 2023

Would be great to either push or create with one command. Good for CI

@bpmct
Copy link
Member Author

bpmct commented Jun 15, 2023

I've heard roughly ~6 users ask for this in calls who plan on automating Coder with CI. Of course, a bash conditional can be used, but this would be a good quick win. Kind of like helm upgrade --install

@bpmct bpmct added this to the ❓Sprint 2 milestone Jun 15, 2023
@matifali matifali assigned matifali and unassigned matifali Jun 18, 2023
@ammario ammario removed this from the ❓Sprint 2 milestone Jun 29, 2023
@matifali
Copy link
Member

I have spent quite well time and effort on this in #8068 but it isn't as straightforward as it looks.

Original Idea

My original idea was to just create an alias for coder template create when a --create flag is passed to the coder template push command.

It turns out that many of the flags are different for both of the commands and simple aliasing will not work.

2nd approach

Try to reuse the minimum possible code from the templatecreate.go in templatepush.go to create a template with default create templates flag values. It will have a drawback that create flags can not be customized.

Also, it turns out that to create a new template we first need to create a version and then create a template, while for updating an existing template we just need to create a new version of the existing template

I ended up creating 2 versions if I use this approach.

Way forward

Maybe a better approach will be to refactor the common functionality of create and push in a new file and then use them as required to allow using the full set of supported flags for each subcommand.

P.S.
I am not a Go developer.
Leaving these notes for anyone taking on this issue in the future.

Thanks, @johnstcn for your help when I was stuck.

@mtojek mtojek self-assigned this Jul 12, 2023
@mtojek
Copy link
Member

mtojek commented Jul 12, 2023

I'm looking around the CLI now, so I can spend some time here.

@TamaMcGlinn
Copy link

Did this get removed again later? I tried adding this flag to my coder push command but the flag was rejected. Help output shows I'm up-to-date with coder's release recent release, but the flag is not mentioned at all:

$ coder template push --help
coder v2.13.0+56bf386

USAGE:
  coder templates push [flags] [template]

  Create or update a template from the current directory or as specified by flag

OPTIONS:
      --activate bool (default: true)
          Whether the new template will be marked active.

      --always-prompt bool
          Always prompt all parameters. Does not pull parameter values from active template version.

  -d, --directory string (default: .)
          Specify the directory to create from, use '-' to read tar from stdin.

      --ignore-lockfile bool (default: false)
          Ignore warnings about not having a .terraform.lock.hcl file present in the template.

  -m, --message string
          Specify a message describing the changes in this version of the template. Messages longer than 72 characters will be displayed as truncated.

      --name string
          Specify a name for the new template version. It will be automatically generated if not provided.

      --provisioner-tag string-array
          Specify a set of tags to target provisioner daemons.

      --var string-array
          Alias of --variable.

      --variable string-array
          Specify a set of values for Terraform-managed variables.

      --variables-file string
          Specify a file path with values for Terraform-managed variables.

  -y, --yes bool
          Bypass prompts.

———
Run `coder --help` for a list of global options.

Any ideas?

@matifali
Copy link
Member

matifali commented Jul 8, 2024

Hi @TamaMcGlinn are you trying to add --create flag? If yes this is now not required and a template push always creates a template if it doesn't exist already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants