ysj
ysj

Reputation: 75

CloudFormation Parameter Reference inside Fn::If inside Fn::Sub

I'm trying to substitute two variables in a string using Fn::Sub. The problem is the variable value is based on conditional statement. How can this be written correctly?

"Fn::Sub":["https://${QS}.${CUR}.website.com, 
           {"QS": {"Fn::If": ["condition1", ${abc}-${AWS::Region}, ${abcq}]}},
           {"CUR": {"Fn::If": ["condition1", ${AWS::Region}, ${abcq}]}}
          ]

Here, condition1 is one of the Conditions, and abc and abcq are Parameters.

Upvotes: 1

Views: 847

Answers (1)

Marcin
Marcin

Reputation: 238497

You can try the following. It may need some adjustment as I'm not able to run the actual code to verify it.

I think the following should be the way to do what you want to achieve:

"Fn::Sub":
[
    "https://${QS}.${CUR}.website.com, 
    {"QS":  
        {
            "Fn::If": [
                "condition1", 
                {"Fn::Sub": "${abc}-${AWS::Region}"}, 
                {"Fn::Ref": "abcq"}    
            ]
        }
    },
    {"CUR": 
        {
        "Fn::If": [
                "condition1", 
                {"Fn::Ref": "AWS::Region"},    
                {"Fn::Ref": "abcq"}    
            ]
        }
    }
]

Upvotes: 1

Related Questions