cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

[Fn::ImportValue] - [Enhancement] - Fn::ImportValue returns String when CommaDelimitedList needed for Fn::ForEach collection

Open LUKEALDRED opened this issue 1 year ago • 0 comments

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.

LUKEALDRED avatar Jan 17 '25 10:01 LUKEALDRED