Skip to content

Edit template variables after creation #1886

Closed

Description

@bpmct

What is your suggestion?

If I create a template with var1=foo as a sensitive (template) variable, I have no way to update the template and change the template to var1=bar. Coder does not support reading from .tfvars files, or TF_VAR environment variables during coder templates create or coder templates update.

Related #1751, but also encompasses updating an existing variable. #1541 allows you to specify vars from a file, but does no work for updating workspaces.

Why do you want this feature?

Editing template variables is a key part of iterating on a template. To name specific workflows:

  • patching/updating base container images for Docker and K8s workspaces
  • rotating/updating the API key for a cloud provider
  • migrating docker host for workspaces
  • fixing broken templates due to invalid (or dynamic) var

Are there any workarounds to get this functionality today?

Hardcoding (and committing) secret variables and environment information.

Some type of sed magic to inject variables into .tf via CLI scripts. Yikes

Are you interested in submitting a PR for this?

No

Activity

  1. changed the title [-]Feat: edit template variables after creation[/-] [+]Edit template variables after creation[/+] on Jun 7, 2022
  2. Emyrk commented on Jun 13, 2022

    @Emyrk
    Member

    I think I am seeing this too. Just to clarify, the bug is you cannot add variables with coder template update?

  3. bpmct commented on Jun 13, 2022

    @bpmct
    MemberAuthor

    Correct

  4. added this to the Community MVP milestone on Jun 14, 2022
  5. self-assigned this
    on Jun 14, 2022
  6. Emyrk commented on Jun 14, 2022

    @Emyrk
    Member

    This seems important, I'm going to take a look

  7. misskniss commented on Jun 14, 2022

    @misskniss

    @Emyrk will you add your notes from the slack convo into this issue?

  8. Emyrk commented on Jun 14, 2022

    @Emyrk
    Member

    Notes from slack:

    Param values are currently associated to Templates, not the versions. This causes an issue for past template versions as if you upload new param values for a template, it also updates old template versions. So we should scope values to the version only

    Decision:

    • Remove template parameter scope so all param values are scoped to the template version job
  9. Emyrk commented on Jun 14, 2022

    @Emyrk
    Member

    @kylecarbs @bpmct

    There was some convo in slack for UX on this. It would be nice to grab the last template_version values.

    However this implies some assumptions. The first being, would I grab the "current" value for the same param from the active template version? Or the most recent template version? (These can be different)

    UX wise, this also requires fetching params that are intentionally secrets to show the user what the "current" value is. The alternative is just do something like "Use previous value", but don't show what that value is (?).


    For the first iteration, to simplify everything and fix the bug, does anyone object to copying the current coder template create flow of prompting the user for each parameter value?

    I know @kylecarbs mentioned having to re-input secrets could be awkward, but I think requiring the user that updates the template active version to have the secret is ok. And from a security POV, if you don't have the secret, you could use the "current" value syntax to leak the secret by uploading a terraform file that exposes the secret to the workspace somehow.

    EDIT: We can update the UX in the future

  10. kylecarbs commented on Jun 14, 2022

    @kylecarbs
    Member

    I'm not opposed, but I'd defer to @bpmct's POV.

  11. bpmct commented on Jun 14, 2022

    @bpmct
    MemberAuthor

    For the first iteration, to simplify everything and fix the bug, does anyone object to copying the current coder template create flow of prompting the user for each parameter value?

    IMO, this would not be super ideal. Since there is no .tfvars support in Coder, I would have to manually add the vars each time I'm debugging a template (or hardcode them during the "buildout" phase of a template). e.g

    for broken_or_wip_template
       vim main.tf # edit terraform
       coder templates update my-template # add new template version
       # copy/paste all vars, even if specified in previous version
       coder workspace <create/update> my-test-workspace
       if (fixed) break;

    If 0 new variable names are introduced in a version, I think skipping the variable screen is a sane default.

    $ coder templates update ben-linux
    # Using template parameters from previous template version. To
    # always prompt for params, use --always-prompt

    For editing/adding new values, would it be difficult to mimic the aws configure behavior? Specifically, it

    • iterates through all variables, shows a tiny bit of the parameter
    • easy UX for overriding or using existing parameter
    • indicates whether a parameter is empty

    https://asciinema.org/a/lESUYiOkdV0VJk1hu8g2M0any

    Will this also apply for workspaces when new parameters are added to a template? For workspaces, it seems saner to only prompt when new variables are introduced and have an --edit-params flag to iterate through everything, like aws configure.

  12. Emyrk commented on Jun 14, 2022

    @Emyrk
    Member

    @bpmct do you think using the parameters files is a valid workflow?

    Showing part of the secret still means exporting the secret which I would like to avoid. I could replace the characters with *'s?

  13. Emyrk commented on Jun 14, 2022

    @Emyrk
    Member

    I think I am just confused on the aws configure behavior. Is that editing an existing template?

    So the flow is this?

    coder templates update ben-linux
    coder templates configure ben-linux
    # Reinset params
    

    I can do this now:

    $ coder templates update ben-linux
    # Using template parameters from previous template version. To
    # always prompt for params, use --always-prompt
    # All new params are always prompted.
    # All removed params will just paste some informational log line
    
  14. bpmct commented on Jun 14, 2022

    @bpmct
    MemberAuthor

    do you think using the parameters files is a valid workflow?

    Yep. Just like .tfvars :)

    So the flow is this?

    coder templates update ben-linux
    coder templates configure ben-linux
    # Reinset params

    Ah, I just meant the way aws configure works. I was not suggesting add a coder configure command.

    Showing part of the secret still means exporting the secret which I would like to avoid. I could replace the characters with *'s?

    Makes sense to me 👍🏼

    $ coder templates update ben-linux
    # Using template parameters from previous template version. To
    # always prompt for params, use --always-prompt
    # All new params are always prompted.
    # All removed params will just paste some informational log line

    Yeah sounds fantastic

  15. Emyrk commented on Jun 17, 2022

    @Emyrk
    Member

    #2397 done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apiArea: HTTP APIcliArea: CLI

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions