Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change on tf_vars should also trigger a new template version #97

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
michvllni opened this issue Sep 12, 2024 · 3 comments Β· Fixed by #98
Closed

Change on tf_vars should also trigger a new template version #97

michvllni opened this issue Sep 12, 2024 · 3 comments Β· Fixed by #98
Assignees

Comments

@michvllni
Copy link

michvllni commented Sep 12, 2024

Currently, a change in the tf_vars property does not trigger a recreation but a modification of the template.

As the tf_vars effectively change the content of the template, it should trigger a new version.

As an example, it would be possible to change the name of a parameter via tf_var.

A more drastic example to show what would be possible is to base the entire coder parameters on a tf_var:

template.tf

resource "coderd_template" "example" {
  name        = "example"
  description = "example"

  versions = [
    {
      directory = "./template"
      active    = true
      tf_vars = [{
        name = "parameters"
        value = jsonencode([
          "cpu",
          "memory"
        ])
      }]
    }
  ]
}

in the template:

variable "parameters" {
  type = string
}

locals {
  parameters = jsondecode(var.parameters)
}

data "coder_parameter" "parameters" {
  for_each = toset(local.parameters)
  name     = each.key
}

If I change the content of the parameters var via the coderd_template in this scenario, the whole template would change.

@michvllni
Copy link
Author

michvllni commented Sep 12, 2024

Just saw that the vars in coder are defined on the template level, not the project level. What happens if I push two versions with different vars via coderd... which values for the vars will be promoted in the template?

Or is this only on the coder UI?

@ethanndickson
Copy link
Member

Just saw that the vars in coder are defined on the template level, not the project level. What happens if I push two versions with different vars via coderd... which values for the vars will be promoted in the template?

I was also confused by this, but the Terraform variables shown on template settings are populated from the active template version. However, they are applied template-wide. If you created a new version using coder templates push and didn't supply them as CLI args, they'd be populated in that new version using the existing variables.

Regardless, we very much have a bug in the provider, as it needs to be pushing a new template version when tf_vars changes. This is what the Web UI does when saving changes to Template Settings -> Variables.

@ethanndickson ethanndickson self-assigned this Sep 12, 2024
@michvllni
Copy link
Author

michvllni commented Sep 12, 2024

Okay, thank you for the confirmation.

Out of curiosity: if I switch the active template version to an older one, will the vars get overwritten by the vars of the old template?

Edit: Just tried it out, this is exactly what happens. If I promote an older version, the vars get reset to the vars of that version

@ethanndickson ethanndickson changed the title Change on tv_vars should also trigger a new template version Change on tf_vars should also trigger a new template version Sep 12, 2024
@matifali matifali removed the bug label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants