aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
Allow Fn::Sub to expand intrinsic functions in the first parameter (currently only supports string)
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### 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:
```
- !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:
```
- Fn::Join:
- ""
- - "{"
- Fn::If
- SomeCondition
- !Sub
- |
"a": "${lookup}",
- lookup: !ImportValue "my-lookup"
- ""
- !Sub
- |
"b": "${value2}",
"c": "a fixed value"
- value2: !If [ SomeOtherCondition, enabled, disabled ]
- "}"
```
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:
1. Creating multiple resources (which is not always appropriate)
2. Complex branching logic with a lot of repetition
3. 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.
### Other Details
_No response_
Contributor guide
Research direction
No source files or tests are named in the issue. Start by reviewing the Fn::Sub description and its YAML examples, then determine where first-parameter parsing is defined. Done means the first parameter accepts nested intrinsic functions without the reported syntax failure, with the documented examples behaving as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100