Skip to content
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

tfe_variable doesn't support complex objects #433

Closed
rorychatterton opened this issue Feb 12, 2022 · 1 comment
Closed

tfe_variable doesn't support complex objects #433

rorychatterton opened this issue Feb 12, 2022 · 1 comment

Comments

@rorychatterton
Copy link

rorychatterton commented Feb 12, 2022

The tfe_variable object only supports strings as a valid input today. This means that we can't output complex objects (for example, a map of objects) as a variable without going through an intermediary like jsonencode() to convert it to a string. This means that you can't do input type validation on the consuming workspace.

Use-cases

Our workspace factory generates a set of standard variables on creation of workspace. This includes some nested maps. Today, we must convert these to json, then accept them as strings on the incoming variable definition.

Attempted Solutions

resource "tfe_workspace" "test" {
  name         = "my-workspace-name"
  organization = "my_cool_org"
}

resource "tfe_variable" "test" {
  key          = "my_cool_var"
  value        = {  key1 = "value1", key2 = "value2" }
  category     = "terraform"
  workspace_id = tfe_workspace.test.id
}

output:

│ Error: Incorrect attribute value type
│
│   on ptfe.tf line 8, in resource "tfe_variable" "fff":
│   8:   value        = {  key1 = "value1", key2 = "value2" }
│
│ Inappropriate value for attribute "value": string required.

Proposal

Some options I thought about:

Update the SDK to allow a dynamic type?
I am not familiar enough with the SDK for development, but it seems that it might require a more flexible .any type in the SDK to be able to encode the input type of the variable properly?

** tfvars encode/decode?**
Another option might require changes on the core side to allow a tfvarsdecode/tfvarsencode like function to enable output of hcl compatible variables? In that case, it'd be a documentation side in the provider to give an example on how to handle that use case.

** Enable parsing of .tfvars.json style in TFE **
Enable a flag on the TFE side to allow parsing of JSON natively as an input, rather than needing to convert to HCL or Strings for complex types

Any other ideas of how this could be done would be well appreciated.

@rorychatterton
Copy link
Author

Just noticed there is a duplicate Here and workaround here: https://github.com/hashicorp/terraform-provider-tfe/issues/40. There has been no movement on that issue for > 12 months so closing.

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

No branches or pull requests

1 participant