AWS CloudFormation conditional tagging
I have a similar need and don't want unused tags lying around either. I've gotten it working using the following snippet:
"Tags": [
...,
{
"Fn::If": [
"MyCondition",
{"Key": "MyKey", "Value": "MyValue"},
{"Ref": "AWS::NoValue"}
]
}
],
And if you're using YAML
Tags:
- 'Fn::If':
- MyCondition
-
Key: MyKey
Value: MyValue
- !Ref AWS::NoValue