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

Implement variable-level validations for gruntwork cli #105

Closed zackproser closed 1 year ago

zackproser commented 2 years ago

Closes https://github.com/gruntwork-io/company/issues/460

These changes implement variable-level validations that can be defined in boilerplate.yml. For example:

 - name: CompanyName
    description: Your company name is used as a prefix when naming resources like your S3 Buckets and Load Balancers. It must remain short, so that it does not exceed AWS name length limits.
    type: string
    validations:
      - required
      - length-5-22
      - alphanumeric

Will result in the user being presented with a prompt that will only accept a value that passes all three of the defined validation rules:

Note that, while we're planning on using this branch in the updated gruntwork CLI experience we're shipping as part of the Spring 2022 Ref Arch Moratorium, we're not necessarily planning on merging this into boilerplate permanently, as-written.

Ultimately, It's important that we get a working CLI experience with validations that can be completed quickly by our users, but we don't want to overly invest in this interim solution, either, because it only needs to bridge the current gap until our next offering is ready.

Description

Documentation

TODOs

Please ensure all of these TODOs are completed before asking for a review.

Related Issues

zackproser commented 2 years ago

Mostly LGTM! I think we should also make sure to run through the validations in getValueForVariable after the call to getVariable, so that we also run through the validations on inputs passed through with --var-file or in the boilerplate.yml config.

The other comments are all nits.

Thanks, Yori! Modified getValueForVariable to also run validations in ebee1ae

zackproser commented 2 years ago

A few thoughts:

1. If we are going to merge this into `boilerplate`, we need to add validations to the docs in the `README`.

2. From a UX perspective, I think encoding parameters into the name of the validation is going to be hard to maintain/scale and will hit weird corner cases. I think using a list of objects for `validations` is probably closer to what you want. Here's the same example from the PR description:
   ```yaml
    - name: CompanyName
       description: Your company name is used as a prefix when naming resources like your S3 Buckets and Load Balancers. It must remain short, so that it does not exceed AWS name length limits.
       type: string
       validations:
         - name: required
         - name: length
           min: 5
           max: 22
         - name: alphanumeric
   ```

I understand this branch might only be used temporarily for gruntwork CLI stuff, so feel free to ignore this feedback until we're considering merging it into boilerplate "for real."

Thanks, Jim! I agree with you about the UX for the validations. While I do like this validation library and find it very useful, I was currently planning on only using this branch to support the updated Gruntwork CLI experience. I feel there's more work to be done before we could ship a proper validations update to boilerplate for its own sake.

oredavids commented 1 year ago

@zackproser closing this as part of efforts to declutter and remove older PRs. If this change is still required, kindly re-open.