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

Parse CLI vars using specified var types rather than YAML defaults #137

Open ellisonc opened 10 months ago

ellisonc commented 10 months ago

Describe the bug When parsing inputs on the cli given by --var, boilerplate will use default YAML parsing rules to guess the type rather than using the type provided in the boilerplate.yml file

To Reproduce

Suppose we have a boilerplate.yml file like this:

  - name: AwsLogsAccountId
    order: 4
    description: Enter the AWS account ID for the logs account
    type: string

You would expect to be able to use a command like the following to provide the AWS account ID:

boilerplate ... --var AwsLogsAccountId=1234567890

This will throw an error saying an integer cannot be treated as a string:

ERROR: Value '9.87654321e+08' is not a valid value for variable 'AwsLogsAccountId' with type 'string'.

Expected behavior When type is ambiguous, default to the type specified by the user in the boilerplate.yml file

Additional context Based on an inspection of the code, I suspect this would happen with other yaml types as well, but haven't verified.

As a workaround you can provide the value as a YML string, but this is not expected unless the user knows yaml parsing is being used under the hood:

boilerplate  ... --var AwsLogsAccountId="'1234567890'"
ozbillwang commented 5 months ago

Appreciate it, @ellisonc The workaround you suggested is effective, even it starts with "0"

boilerplate  ... --var AwsLogsAccountId="'01234567890'"
jasonyoung-pearl commented 1 month ago

Same issue here:

  - name: AwsVersion
    description: Version of the AWS provider required in the module
    default: "5.0"
boilerplate ... --var AwsVersion='5.0'
# results in:
ERROR: Value '5' is not a valid value for variable 'AwsVersion' with type 'string'.

This workaround fixes it:

boilerplate ... --var AwsVersion="'5.0'"