gruntwork-io / boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
https://www.gruntwork.io
Mozilla Public License 2.0
157 stars 12 forks source link

Execution fail with map containing boolean #174

Open Dudesons opened 3 months ago

Dudesons commented 3 months ago

Describe the bug

I'm trying to create a template with the possibility to toggle some folders, where each folder have a map which contains all required informations.

the boilerplate.yml file looks like that:

variables:
  - name: project

  - name: serviceA
    type: map
    default:
      length: 8

  - name: serviceB
    type: map
    default:
      length: 56

  - name: serviceC
    type: map
    default:
      enabled: true
      length: 56

skip_files:
  - path: serviceC
    if: {{ not .serviceC.enabled }}

the answer file is:

project: eustaging
serviceA:
  length: 79
serviceC:
  enabled: false
  length: 789

Then when I'm running this command: boilerplate --template-url platform --output-folder dev/eu/ --var-file dev/eu/eustaging-boilerplate.yml I have this error:

[boilerplate] 2024/03/25 07:42:50 Loading boilerplate config from platform/boilerplate.yml                                                     
ERROR: yaml: invalid map key: map[interface {}]interface {}{".serviceC.enabled":interface {}(nil)}   

I also tried to switch to a map which contains all my toggles, but I have the same error.

variables:
  - name: project

  - name: serviceA
    type: map
    default:
      length: 8

  - name: serviceB
    type: map
    default:
      length: 56

  - name: serviceC
    type: map
    default:
      length: 56

  - name: toggles
    type: map
    default:
      serviceC: true

skip_files:
  - path: serviceC
    if: {{ not .toggles.serviceC }}

To Reproduce Steps to reproduce the behavior including the relevant Terraform/Terragrunt/Packer version number and any code snippets and module inputs you used.

version: boilerplate version v0.5.12

Expected behavior I'm expecting the execution could work when I want or not a directory according to the var file when this one has a bool in a map containing informations about the service or in a toggle map

brikis98 commented 3 months ago

Yes, the map type is currently limited to values of type string. A PR to improve this is very welcome!

Dudesons commented 3 months ago

Yes, the map type is currently limited to values of type string. A PR to improve this is very welcome!

Ok thank you for the information. Not sure if I will have the time to do the contribution and I tried to read the code but I'm not sure where changes have to be done. I imagine if I want to do the contribution I have to update the variable parsing but also the template rendering

brikis98 commented 3 months ago

Changes to parsing I believe are here: https://github.com/gruntwork-io/boilerplate/blob/master/variables/variables.go#L282-L292. Which is used here in rendering: https://github.com/gruntwork-io/boilerplate/blob/master/config/get_variables.go#L103-L118.

I don't recall off the top of my head what else would have to change. TDD would be a good approach to follow here!