aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
[Fn::ImportValue] - [Enhancement] - Fn::ImportValue returns String when CommaDelimitedList needed for Fn::ForEach collection
- 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
Fn::ImportValue
### Description
I've happened upon an issue where I need a collection for the Fn::ForEach function. I've attempted to use Fn::ImportValue to bring in a list of items for the collection but Fn::ImportValue is returning a String rather than a CommaDelimitedList.
A bit more detail:
I've got a CloudFormation stack that creates an ElastiCache Replication Group. The number of nodes created depends on the number of Availability Zones selected by the user. I have an Output that lists the reader endpoints. If the user selects 1 Availability Zone the output provides 1 reader endpoint. If the user selects 2 Availability Zones the output provides 2 reader endpoints and so on.
Example:
1 AZ
[test-001-replication-group-001.xxxxxx.0001.euw2.cache.amazonaws.com]
2 AZs
[prod-001-replication-group-001.xxxxxx.0001.euw2.cache.amazonaws.com, prod-001-replication-group-002.xxxxxx.0001.euw2.cache.amazonaws.com]
I was hoping to use this output from my ElastiCache CloudFormation stack so that I could the create a CloudWatch alarm for each node using Fn::ForEach. I couldn't work out why I kept getting `'Transform AWS::LanguageExtensions failed with: Could not find a collection or could not be resolved for Fn::ForEach'`. AWS support were able to advise me that Fn::ImportValue is returning a String, not a list as I was hoping.
I'd like to be able to use a CloudFormation Output as a list. For now I'm just using a Parameter of type CommaDelimitedList in my CloudWatch CloudFormation template and providing a list of ElastiCache Reader Endpoints manually.
### Other Details
I'm aware that when using `Fn::GetAtt: ElastiCacheRedisReplicationGroup.ReadEndPoint.Addresses` for the Output the value is enclosed in square brackets. I've been using a combination of Fn::Split and Fn::Select to get around this.
Contributor guide
Research direction
Start with the Fn::ImportValue and Fn::ForEach behavior described in the issue, including the Fn::GetAtt output and the current Fn::Split/Fn::Select workaround. Done means a CloudFormation Output can be consumed as a collection for Fn::ForEach instead of requiring a manually supplied CommaDelimitedList parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100