How to use a condition for AWS Child resource type
- I wanted to create an AWS backup plan with 2 backup rules with a condition (example, if I set create2backup rule as "true", it should create the rule 1 and rule 2, if the condition is false, it should ignore creating the second rule and it should create the rule 1.
Condition - create rule is true --- Creates Rule 1 and Rule 2
Condition - create rule is false --- Creates Rule1 and should ignore creating rule 2 and exit
whatever thee condition is it should create the Rule 1, the condition should only apply to Rule 2.
Try1 :
BackupPlan:
Type: AWS::Backup::BackupPlan
Properties:
BackupPlan:
BackupPlanName: backupplan
BackupPlanRule:
-
RuleName: !Ref RuleName
- <Some condition>
RuleName: !Ref RuleName2
Try2:
StorageBackupPlan:
Type: AWS::Backup::BackupPlan
# DependsOn: StorageBackupVault
Properties:
BackupPlan:
BackupPlanName: !Ref BackupPlanName
BackupPlanRule:
!If
- Createbackuprule2
-
RuleName: !Ref RuleName
-
RuleName: !Ref RuleName2
Error for try 2 - Properties validation failed for resource StorageBackupPlan with message: #/BackupPlan/BackupPlanRule: expected type: JSONArray, found: JSONObject
Try 3 : worked but not as I expected, if condition is true it creates rule 1 if the condition is false it creates rule 2 - got this from below answer
StorageBackupPlan:
Type: AWS::Backup::BackupPlan
# DependsOn: StorageBackupVault
Properties:
BackupPlan:
BackupPlanName: !Ref BackupPlanName
BackupPlanRule:
!If
- Createbackuprule2
-
- RuleName: !Ref RuleName1
-
- RuleName: !Ref RuleName2