I have a requirement to conditionally tag resources based on user response to the downtime parameter and the value of environment defined in map. This tag is later used by the lambda function to turn off the instances at night.
I tried it like this with no luck -
Conditions -
"EnvCheck": {
"Fn::Not": [
{"Fn::Equals": [{"Ref": "EnvironmentType"}, "prod"]}
]
},
"EnableDowntimeTag": {
"Fn::And": [
{"Fn::Equals": [{"Ref": "CustodianDowntime"}, "true"]},
{"Condition": "EnvCheck"}
]
}
Tags section
"Tags": [
{
"Key": "OwnerContact",
"PropagateAtLaunch": "true",
"Value": {
"Ref": "OwnerContact"
}
},
{
"Condition" : "EnableDowntimeTag",
"Key": "custodian_downtime",
"PropagateAtLaunch": "true",
"Value": "Offhours tz=ET"
}
],
Any idea on how to add a conditional tag?
Thanks!
And if you're using YAML
Tags:
- 'Fn::If':
- MyCondition
-
Key: MyKey
Value: MyValue
- !Ref AWS::NoValue
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"}
]
}
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With