aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap

Fn::If inside Fn::Contains in Assert block of Rule fails template validation

Open
#921 0 comments 0 reactions 0 assignees View on GitHub
enhancement Platform
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 Rules Block

### Issue Description

Rule-specific intrinsic function "Fn::If" cannot be used under Rules block of CloudFormation template.
Feature Request Description:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/rules-section-structure.html#rules-specific-intrinsic-section-structure .

This document specifies that the "Fn::If" can be used inside the Rule Block and it states that, you can nest functions, but the final result of a rule condition or assertion must be either true or false.

But this does not seem to be possible in this case as it fails at template validation step.

### Expected Behavior

Intrinsic function in the Rules block should get evaluated.

### Observed Behavior

Template Fails Validation

### Test Cases

Sample Template:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"Environment": {
"Type": "String"
},
"Cluster":{
"Type": "String"
}
},
"Rules": {
"FargateCluster": {
"Assertions": [
{
"Assert": {
"Fn::Contains": [
[
"fargate-production",
"fargate-staging"
],
{
"Fn::If": [
"IsProduction",
"fargate-production",
"fargate-staging"
]
}
]
},
"AssertDescription": "For Fargate Spot services, Cluster must be one of fargate-production, fargate-staging"
}
]
}
},
"Resources": {
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "somesamplebucket"
}
}
}
}

Error Message: Template format error: Following functions are not supported in the Rules block of the template: [Fn::If]

This contradicts what is said in the following link:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/rules-section-structure.html

"You can use the following rule-specific intrinsic functions to define rule conditions and assertions: "

### Other Details

N/A

Contributor guide

Open the contributing guide

Research direction

Start with the sample template in the issue and the linked CloudFormation Rules documentation. Reproduce the validation error showing that Fn::If is rejected inside Fn::Contains in an Assert block, then determine whether the documented behavior or the service validation should change; done means the discrepancy is resolved and the sample validates as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.