-
Notifications
You must be signed in to change notification settings - Fork 877
fix(provisioner/terraform/tfparse): evaluate coder_parameter defaults with variables #15800
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,73 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) { | |
expectTags: map[string]string{"platform": "kubernetes", "cluster": "developers", "region": "us", "az": "a"}, | ||
expectError: "", | ||
}, | ||
{ | ||
name: "main.tf with parameter that has default value from dynamic value", | ||
files: map[string]string{ | ||
"main.tf": ` | ||
provider "foo" {} | ||
resource "foo_bar" "baz" {} | ||
variable "region" { | ||
type = string | ||
default = "us" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember the current bevahior, so let me ask - There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
variable "az" { | ||
type = string | ||
default = "${""}${"a"}" | ||
} | ||
data "base" "ours" { | ||
all = true | ||
} | ||
data "coder_parameter" "az" { | ||
name = "az" | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type = "string" | ||
default = var.az | ||
} | ||
data "coder_workspace_tags" "tags" { | ||
tags = { | ||
"platform" = "kubernetes", | ||
"cluster" = "${"devel"}${"opers"}" | ||
"region" = var.region | ||
"az" = data.coder_parameter.az.value | ||
} | ||
}`, | ||
}, | ||
expectTags: map[string]string{"platform": "kubernetes", "cluster": "developers", "region": "us", "az": "a"}, | ||
expectError: "", | ||
}, | ||
{ | ||
name: "main.tf with parameter that has default value from another parameter", | ||
files: map[string]string{ | ||
"main.tf": ` | ||
provider "foo" {} | ||
resource "foo_bar" "baz" {} | ||
variable "region" { | ||
type = string | ||
default = "us" | ||
} | ||
data "base" "ours" { | ||
all = true | ||
} | ||
data "coder_parameter" "az" { | ||
type = string | ||
default = "${""}${"a"}" | ||
} | ||
data "coder_parameter" "az2" { | ||
name = "az" | ||
type = "string" | ||
default = data.coder_parameter.az.value | ||
} | ||
data "coder_workspace_tags" "tags" { | ||
tags = { | ||
"platform" = "kubernetes", | ||
"cluster" = "${"devel"}${"opers"}" | ||
"region" = var.region | ||
"az" = data.coder_parameter.az2.value | ||
} | ||
}`, | ||
}, | ||
expectError: "Unknown variable; There is no variable named \"data\".", | ||
}, | ||
{ | ||
name: "main.tf with multiple valid workspace tags", | ||
files: map[string]string{ | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)