aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.4k stars 576 forks source link

v1: E3027 'minute' is not one of ['minutes', 'hours', 'days'] when 'Fn::Sub' is resolved #3380

Closed cbernander closed 1 week ago

cbernander commented 1 week ago

CloudFormation Lint Version

1.3.3

What operating system are you using?

Ubuntu

Describe the bug

When using a parameter for setting the rate expression unit, specifying any of the following values as part of the AllowedValues property fails validation:

Expected behavior

Using one of the values specified above should pass validation.

Reproduction template

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  Frequency:
    Description: Value of frequency
    Type: Number
    Default: 5
  FrequencyUnit:
    Description: Unit of frequency
    Type: String
    Default: minutes
    AllowedValues:
      - minute
      - minutes
      - hour
      - hours
      - day
      - days
Resources:
  EventsRule:
    Type: AWS::Events::Rule
    Properties:
      ScheduleExpression: !Sub "rate(${Frequency} ${FrequencyUnit})"
      State: ENABLED
kddejong commented 1 week ago

I think what makes sense here is when we used the resolved values that if one is correct we don't alert. The other option would be to use the Default values together and not mix and match Default and AllowedValues.

Since the default is 5 we are validating the scenario of rate(5 minute) so any of the singular values are wrong.

kddejong commented 1 week ago

I have a fix for this to basically say if at least one of the values are valid we won't return an error. Need to add some tests but PR coming soon.