Skip to content

E3012 false positive when Fn::If guards a String-typed parameter used in an integer context #4577

Description

@hoganbr-amzn

CloudFormation Lint Version

1.52.1

What operating system are you using?

Mac

Describe the bug

Rule E3012 reports a type error when a Ref to a String-typed parameter is used where an integer is expected, even when the code path is guarded by an Fn::If condition that ensures the value is only evaluated when it contains a numeric string. CloudFormation accepts numeric strings in integer-typed properties and deploys successfully.

This pattern is common when a parameter serves dual purpose, with Fn::If + AWS::NoValue removing the property entirely when active.

Expected behavior

No error should be reported in this case as the condition prevents a non-integer value.

Reproduction template

Parameters:
  MyCapacity:
    Type: String
    AllowedPattern: "\\d+|auto"
    Default: "auto"

Conditions:
  UseProvisionedCapacity:
    !Not [!Equals [!Ref MyCapacity, "auto"]]

Resources:
  MyTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: Example
      KeySchema:
        - { AttributeName: id, KeyType: HASH }
      AttributeDefinitions:
        - { AttributeName: id, AttributeType: S }
      ProvisionedThroughput:
        !If
          - UseProvisionedCapacity
          - ReadCapacityUnits: !Ref MyCapacity
            WriteCapacityUnits: !Ref MyCapacity
          - !Ref "AWS::NoValue"

cfn-lint output:

E3012 'auto' is not of type 'integer'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions