1
votes

I'm trying to create a conditional block using the Fn::GetAtt intrinsic function but it is failing with below error -

"Template validation error: Template format error: Unresolved dependencies. Cannot reference resources in the Conditions block of the template."

My condition - 
"SomeCondition":{  
        "Fn::Equals":[  
            {  
                "Fn::GetAtt":[  
                    "CustomResource",
                    "ID"
                ]
            },
            "SOME-UUID"
        ]
    }

Can someone suggest a workaround for this? I wanted to use the condition to dynamically select a script in my user-data section.

1
What's the response of CustomResource look like? It has ID in it?Daniel Farrell
@Sandeep can you able to resolve this problem ? Because i am also got struck with this thingPrivate

1 Answers

1
votes

The "Cannot reference resources in the Conditions block of the template" error message is explained in the Condition Functions documentation:

Note

You can only reference other conditions and values from the Parameters and Mappings sections of a template. For example, you can reference a value from an input parameter, but you cannot reference the logical ID of a resource in a condition.

As for a workaround for dynamically selecting a script in your user-data section, you could move your conditional logic from CloudFormation into your user-data script directly, e.g., using a Bash conditional construct and the Fn::Sub intrinsic function:

UserData:
  "Fn::Base64":
    !Sub |
      #!/bin/bash -xe
      if [[ ${CustomResource.ID} == "SOME-UUID" ]]; then
        # some commands
      else
        # other commands
      fi