Fn::Sub accepts two parameters, a first string-only parameter and a second object containing named substitutions.
The second argument allows the use of other CloudFormation intrinsic functions, such as !ImportValue. However, the first does not. For example, the following breaks syntax:
- !Sub
- !Sub ""
- a: "b"
When building complex values, for example a JSON object with certain parts of the structure dependent on conditions, disallowing the expansion (as now) forces a more complex approach, such as:
As there isn't an equivalent for Terraform's local variables, there aren't really many options in these cases. You are forced to choose between:
Creating multiple resources (which is not always appropriate)
Complex branching logic with a lot of repetition
Textual joins as demonstrated above
Nesting substitutions or applying other transformations on the first string parameter could simplify these. It's not clear or obvious why the first string parameter does not support expansion using intrinsic functions.
Name of the resource
Other
Resource name
CloudFormation intrinsic function Fn::Sub
Description
Fn::Sub
accepts two parameters, a first string-only parameter and a second object containing named substitutions.The second argument allows the use of other CloudFormation intrinsic functions, such as
!ImportValue
. However, the first does not. For example, the following breaks syntax:When building complex values, for example a JSON object with certain parts of the structure dependent on conditions, disallowing the expansion (as now) forces a more complex approach, such as:
As there isn't an equivalent for Terraform's
local
variables, there aren't really many options in these cases. You are forced to choose between:Nesting substitutions or applying other transformations on the first string parameter could simplify these. It's not clear or obvious why the first string parameter does not support expansion using intrinsic functions.
Other Details
No response