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

Sanitize structural types fixing file generated.auto.tfvars.json #812

Open
3 tasks
marccortinas opened this issue Jul 27, 2023 · 0 comments
Open
3 tasks
Labels
area/api kind/bug Something isn't working severity/low critical > high > medium > low

Comments

@marccortinas
Copy link

marccortinas commented Jul 27, 2023

Hello,

My team are trying to migrate to tf-controller Terraform Jobs using Terrafom Complex types such as objectS

Object - https://developer.hashicorp.com/terraform/language/expressions/type-constraints#structural-types

I'm not sure but I think there are some bug reading the values from ConfigMap or Secrets.
Let me share a little example....

Terraform YAML

kind: Terraform
metadata:
  name: basic1
spec:
  varsFrom:
  - kind: ConfigMap
    name: vars
    varsKeys:
    - triangle

ConfigMap

metadata:
  name: vars
apiVersion: v1
data:
  triangle: |
    triangle={
    s_one=1,
    s_two=2.5,
    s_three=2.5,
    description="this is a triangle"
    }

This is the vars file generated

{"triangle":"triangle={\ns_one=1,\ns_two=2.5,\ns_three=2.5,\ndescription=\"this is a triangle\"\n}\n"}

This is the error

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
╷                                         
│ Error: Invalid value for input variable
│                                     
│   on generated.auto.tfvars.json line 1:
│    1: {"triangle":"triangl
e={\ns_one=1,\ns_two=2.5,\ns_three=2.5,\ndescription=\"this is a triangle\"\n}\n"}

Maybe I'm doing something wrong but I gues we should sanitize this json file, if i'm not wrong the value used in configmap is in the properly format?

Do you know some workaround in order to migrate Terraform jobs to tf-controller?
I'm thinking in apply this workaround commented by akselleirv

Do you think this is a bug and maybe tf-controller should manage this value ?
I also tried maps, list with complex structures and I have the same issue, the generated.auto.tfvars.json file is not in the properly format

Let me share some more troubleshooting, If I launch break-the-glass and I use this vars file testing.tfvars

s_one=1,
s_two=2.5,
s_three=2.5,
description="this is a triangle"
}

It works fine if i remove from generated.auto.tfvars.json and I run this command terraform apply -auto-approve -var-file="testing.tfvars" . I read this example from https://www.educative.io/answers/what-are-complex-types-objects-in-terraform

========

User Story

As a Terraform Controller user,
I'd like to have support for complex Terraform types such as objects in ConfigMaps and Secrets,
so that I can use these types in my Terraform Jobs without requiring workarounds.

Acceptance Criteria

  • Properly read and parse Terraform complex types from ConfigMaps and Secrets
  • Generate valid generated.auto.tfvars.json when using complex types like objects
  • Ensure that the Terraform apply process works correctly when using complex types from ConfigMaps and Secrets
@chanwit chanwit added kind/bug Something isn't working severity/medium critical > high > medium > low area/api labels Aug 1, 2023
@lasomethingsomething lasomethingsomething added severity/low critical > high > medium > low and removed severity/medium critical > high > medium > low labels Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api kind/bug Something isn't working severity/low critical > high > medium > low
Projects
None yet
Development

No branches or pull requests

3 participants