cfn-lint
cfn-lint copied to clipboard
Custom rule: Check that an object value is in a list
Is this feature request related to a new rule or cfn-lint capabilities?
New capability
Describe the feature you'd like to request
Customizable check for "match item in a list (regardless of index of occurance)"
Describe the solution you'd like
Have tried override spec, so far can only do
{
"ResourceTypes": {
"AWS::Lambda::Function": {
"Properties": {
"Tags": {
"Required": true
}
}
}
}
}
The above mandate adding tags, but not able to confirm the tag with specific name is added, e.g. for cost-center attribution.
Considering custom rule
# this rule is PASS if Tags is a list, and one of its element has subset of attribute matching provided json value.
# this rule is FAIL if Tags is not a list, or none of its element contains all attributes provided by the json value.
AWS::Lambda::Function Tags LIST_CONTAINS {"Key":"service-name"} ERROR "Please set cost-center tag"
Additional context
Use case is to make sure some tags / properties are added as required.
SomeLambda:
Properties:
Tags:
- Key: 'serivce-name'
Value: !Ref 'StackName'
- Key: 'stage-name'
Value: !Ref 'StackSet'
VpcConfig:
SubnetIds:
- !Sub '{{resolve:ssm:/${StackSet}/infra/vpc/az/0/subnet/private/id}}'
- !Sub '{{resolve:ssm:/${StackSet}/infra/vpc/az/1/subnet/private/id}}'
Type: AWS::Lambda::Function
Is this something that you'd be interested in working on?
- [X] 👋 I may be able to implement this feature request
Would this feature include a breaking change?
- [ ] ⚠️ This feature might incur a breaking change