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

Support for complex in templates rendering in values #491

Closed
akselleirv opened this issue Jan 6, 2023 · 3 comments
Closed

Support for complex in templates rendering in values #491

akselleirv opened this issue Jan 6, 2023 · 3 comments

Comments

@akselleirv
Copy link
Collaborator

I want to being allowed to use complex structures in the values field from another job's output.

Example

Given these two modules:
job-a:

output "my_list" {
  value = [
    "entry-1",
    "entry-2"
  ]
}

job-b:

variable "values" {
  type = object({
    my_list = set(string)
  })
}

Where job-b uses the output of job-a as its variable inputs.

My Terraform CRDs looks like the following:

apiVersion: infra.contrib.fluxcd.io/v1alpha1
kind: Terraform
metadata:
  name: job-a
  namespace: flux-system
spec:
  interval: 10m
  retryInterval: 10s
  approvePlan: auto
  path: ./modules/job-a
  sourceRef:
    kind: GitRepository
    name: my-repo
    namespace: flux-system
  destroyResourcesOnDeletion: true
  writeOutputsToSecret:
    name: job-a-outputs
    outputs:
      - my_list
---
apiVersion: infra.contrib.fluxcd.io/v1alpha1
kind: Terraform
metadata:
  name: job-b
  namespace: flux-system
spec:
  interval: 10m
  retryInterval: 10s
  approvePlan: auto
  path: ./modules/job-b
  sourceRef:
    kind: GitRepository
    name: my-repo
    namespace: flux-system
  destroyResourcesOnDeletion: true
  readInputsFromSecrets:
    - name: job-a-outputs
      as: job_a
  dependsOn:
    - name: job-a
  values:
    my_list: ${{ .job_a.my_list }}

If I try this now then I get this error: "logger":"runner.terraform","msg":"unable to marshal the data","instance-id":"ea32bfa5-0d76-4083-8ff4-d71552285c66","error":"json: error calling Marshal JSON for type *v1.JSON: invalid character 'e' after object key:value pair"

Would it be feasible to add this feature?

@chanwit
Copy link
Collaborator

chanwit commented Jan 30, 2023

@akselleirv I landed #504 in v0.14.0-rc.4 which can be used with the chat v0.10.0.
It's a fundamental fix which added type information for outputs, so that they are now serialized back to correct data type when being referenced by inputs of the dependent objects.

Could you check if it's able to fix your issue here please?

@akselleirv
Copy link
Collaborator Author

@chanwit that's looks great! Thank you for prioritizing my feature request that quickly!!

@LappleApple
Copy link
Contributor

Looks like we resolved this request, so closing.

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

No branches or pull requests

3 participants