terraform-provider-coder icon indicating copy to clipboard operation
terraform-provider-coder copied to clipboard

DNM: hack: terraform-plugin-framework and dynamic types

Open johnstcn opened this issue 9 months ago • 4 comments

  • using mux server to serve both old and new provider implementations
  • some mucking around with dynamic types for coder parameter

johnstcn avatar Feb 28 '25 18:02 johnstcn

I see type constraint values might still not be supported? So

data "coder_parameter" "test" {
  type = string // Not allowed
  type = "string" // is allowed

It treats string as a reference, rather than a type constraint. This does check out though, as type constraints are treated as keywords. And keywords in expressions are just traversals.

See traversal to keyword: https://github.com/hashicorp/hcl/blob/main/traversal_for_expr.go#L70-L127 And how they parse the keyword to a type: https://github.com/hashicorp/terraform/blob/main/internal/stacks/stackconfig/typeexpr/typeexpr.go#L27-L31

And on the input value: https://github.com/hashicorp/terraform/blob/main/internal/stacks/stackconfig/input_variable.go#L20-L21 (var blocks are input variables)

So type constraints are just references. We might have to keep our types as quoted strings? :cry:

Traversals less than 2 are considered invalid too? I am not sure where this error is raised, but it is raised somewhere by the tests. I do see where this is enforce in tflint, which I assume has some parity with terraform.

A reference to a resource type must be followed by at least one attribute
        access, specifying the resource name.

TFLint: https://github.com/terraform-linters/tflint-plugin-sdk/blob/master/terraform/addrs/parse_ref.go#L231

Emyrk avatar Mar 03 '25 15:03 Emyrk

Traversals less than 2 are considered invalid too?

I think that's just for a resource, which is always resource_type.name. See parseRef for other kinds of traversals https://github.com/terraform-linters/tflint-plugin-sdk/blob/master/terraform/addrs/parse_ref.go#L66

johnstcn avatar Mar 03 '25 15:03 johnstcn

Another issue with the current sdk.

https://github.com/coder/terraform-provider-coder/pull/123

The current does not support pointer types? So we have to compute some helper fields?

Emyrk avatar Mar 05 '25 15:03 Emyrk

Relevent: https://github.com/coder/preview/issues/94

Emyrk avatar Mar 17 '25 15:03 Emyrk