Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudFormation YAML !Or function

Error: "Template validation error: Template format error: Conditions can only be boolean operations on parameters and other conditions"

Working JSON conditions block:

"Conditions" : {
    "CreateBetaResources" : {"Fn::Or" : [ {"Fn::Equals" : [{"Ref" : "Environment"}, "beta"]}, {"Fn::Equals" : [{"Ref" : "Environment"}, "eubeta"]} ]},
    "CreateStagingResources" : {"Fn::Equals" : [{"Ref" : "Environment"}, "staging"]},
    "CreateProdResources" : { "Fn::Or": [ {"Fn::Equals" : [{"Ref" : "Environment"}, "prod"]}, {"Fn::Equals" : [{"Ref" : "Environment"}, "euprod"]} ] }
  },

YAML block which isn't working:

Conditions:
  CreateBetaResources:
    !Or [!Equals [!Ref "Environment", beta], !Equals [!Ref "Environment", eubeta]]
  CreateStagingResources:
    - !Equals [!Ref "Environment", staging]
  CreateProdResources:
    !Or [!Equals [!Ref "Environment", prod], !Equals [!Ref "Environment", euprod]]

Why is this error happening? I've scoured the documentation on "Fn::Or" and conditionals... It seems as though the syntax is correct. I've also tried many, many other formats, but this is the one closest to the documentation example.

like image 269
troz Avatar asked Jun 25 '26 15:06

troz


1 Answers

The proper way to instantiate !Or/!Equals inside a condition block with YAML is as follows:

Conditions:
 CreateBetaResources: !Or [!Equals [!Ref "Environment", beta], !Equals [!Ref "Environment", eubeta]]
 CreateStagingResources: !Equals [!Ref "Environment", staging]
 CreateProdResources: !Or [!Equals [!Ref "Environment", prod], !Equals [!Ref "Environment", euprod]]

Do not include the list identifier before calling the !Equals function (-).

like image 115
troz Avatar answered Jun 28 '26 04:06

troz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!