Skip to content

Conversation

@johnstcn
Copy link
Member

@johnstcn johnstcn commented Dec 9, 2024

Relates to #15795

Previously we had not been evaluating the default value of a coder_parameter before extracting the tags. This PR adds support for dynamic default values from a variable.
It does not add support for 'chaining' parameter default values, as I could imagine us ending up in a situation where we have a cyclic dependency.

@johnstcn johnstcn requested review from mafredri and mtojek December 9, 2024 16:19
@johnstcn johnstcn self-assigned this Dec 9, 2024
@johnstcn johnstcn requested a review from angrycub December 9, 2024 17:18
defaultsM[dataResource.Name] = strings.Trim(value, `"`)
// Issue #15795: the "default" value could also be an expression we need
// to evaluate.
// TODO: should we support coder_parameter default values that reference other coder_parameter data sources?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has there been an ask? If not, we can probably defer it until such a time. It's best to be careful how much we expand the scope of these expressions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware of any ask for this just yet. I'd much prefer to defer it as it opens up several cans of worms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is sort of a FIXME :)

resource "foo_bar" "baz" {}
variable "region" {
type = string
default = "us"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember the current bevahior, so let me ask -
how this solution will perform if we have a variable without a default value? AFAIR Coder should require to input the value for variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, if there is no default value we will fail this 'preflight' check with an error. This only happens if you're using the coder_workspace_tags data source.

defaultsM[dataResource.Name] = strings.Trim(value, `"`)
// Issue #15795: the "default" value could also be an expression we need
// to evaluate.
// TODO: should we support coder_parameter default values that reference other coder_parameter data sources?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is sort of a FIXME :)

@johnstcn johnstcn merged commit 7dc3ad9 into main Dec 10, 2024
33 checks passed
@johnstcn johnstcn deleted the cj/gh15795-tfparse-dynamic-default-value branch December 10, 2024 10:58
stirby pushed a commit that referenced this pull request Dec 11, 2024
… with variables (#15800)

- adds support for dynamic default values in coder_parameter data source

(cherry picked from commit 7dc3ad9)
aslilac pushed a commit that referenced this pull request Dec 11, 2024
… with variables (#15800)

- adds support for dynamic default values in coder_parameter data source
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 this pull request may close these issues.

4 participants