Search code examples
aws-cloudformationrds

Use Iops property in cloudformation when StorageType : io1 and donot use when Storage type : gp2


I created a template to provision RDS using Cloudformation. While creating RDS we have two options io1,gp2 when we use gp2 we do not need to define iops but when using io1 we need to define iops. I am able to use io1 but gp2 it show error:-

Encountered non numeric value for property Iops

Snippet of my template

  StorageType:

    Description: choose the storage type gp2 for 'General purpose SSD' & io1 for 'IOPS SSD'. 

    Default: "gp2"

    Type: String

    AllowedValues: ["gp2","io1"]

  Conditions:

      iops: !Equals [!Ref StorageType, "io1"]

      gp2: !Equals [!Ref StorageType, "gp2"]

  DB:

    Type: AWS::RDS::DBInstance

    Properties:

      DBInstanceIdentifier: !Sub ${AWS::StackName} 

      DBName: !Ref 'DBName'

      AllocatedStorage: !Ref 'Storage'

      DBInstanceClass: !Ref 'InstanceType'

      StorageType: !Ref StorageType

      ****Iops: !If [iops, !Ref iops, "AWS::NoValue"]****  

      StorageEncrypted: !Ref Encryption 

      Engine: postgres

      EngineVersion: 11.2

      Port: !Ref PortNo

      MasterUsername: !Ref DBUser

      MasterUserPassword: !Ref DBPassword

      DBSubnetGroupName: !Ref RDSSubnetGroup

      VPCSecurityGroups: [!Ref SecurityGroup]

      DBParameterGroupName: !Ref RDSParamGroup

      MultiAZ: !Ref MultiAz

      PubliclyAccessible: !Ref PublicAccessibelity

Thank you in advance


Solution

  • Correct syntax would be:

    Iops: !If [iops, !Ref iops, !Ref "AWS::NoValue"]
    

    Documentation: