flux-iac / tofu-controller

A GitOps OpenTofu and Terraform controller for Flux
https://flux-iac.github.io/tofu-controller/
Apache License 2.0
1.26k stars 136 forks source link

Consuming an output which is a map #642

Open Smana opened 1 year ago

Smana commented 1 year ago

Hello,

I'd like to retrieve the domain_name and the zone_id from a hosted zone created with the controller. However I'm struggling getting the proper format. Actually when I use that

  writeOutputsToSecret:
    name: route53-cloud-hostedzone
    outputs:
      - route53_zone_name:domain_name
      - route53_zone_zone_id:zone_id

I don't get the expected string format

apiVersion: v1                                                                                                                                                                                                                                
data:                                                                                                                                                                                                                                         
  domain_name: ewogICAgICAiY2xvdWQub2dlbmtpLmlvIjogImNsb3VkLm9nZW5raS5pbyIKICAgIH0=                                                                                                                                                           
...                                                                                                                         
kind: Secret                                                                                                                                                                                                                                  
metadata:                                                                                                                                                                                                                                     
  name: route53-cloud-hostedzone                                                                                                                                                                                                              
  namespace: flux-system
{
      "my.domain.tld": "my.domain.tld"
    }

From my understanding I should parse the output within the resource that consumes the secret but I don't know how to proceed.

the module expects the string domain_name and zone_id

kind: Terraform
metadata:
  name: acm-cloud
spec:
  approvePlan: auto
  destroyResourcesOnDeletion: false
  interval: 8m
  path: ./
  sourceRef:
    kind: GitRepository
    name: terraform-aws-acm
    namespace: flux-system
  vars:
    - name: subject_alternative_names
      value:
        - "*.my.domain.tld"
    - name: wait_for_validation
      value: true
    - name: tags
      value:
        Name: "my.domain.tld"
  varsFrom:
    - kind: Secret
      name: route53-cloud-hostedzone

========

User Story:

As a user of Terraform Controller, I'd like to retrieve and format the domain_name and zone_id from a hosted zone created with the controller, so that I can use them as input for other resources without having to create custom modules.

Acceptance Criteria:

Smana commented 1 year ago

I ended up building my own module in order to properly format the outputs. But still, if we want to use community modules that would be cool to be able to do that and somewhat related to this issue I guess?