简体   繁体   English

Cloud Formation 条件资源属性 AWS Backup Resource

[英]Cloud Formation conditional resource property AWS Backup Resource

Working with Cloud Formation template for AWS Backup and trying to make my backup plan flexible使用 AWS Backup 的 Cloud Formation 模板并尝试使我的备份计划灵活

BackupPlanProd:
Type: "AWS::Backup::BackupPlan"
Properties:
  BackupPlan:
    BackupPlanName: !Sub 'BACKUP-PLAN-PROD-${AWS::StackName}'
    AdvancedBackupSettings:
    - ResourceType: EC2
      BackupOptions: 
        WindowsVSS: !Ref VSSConsistent
    BackupPlanRule:
      - RuleName: !Sub Daily-${DailyBackupsRetentionProd}d-retention
        TargetBackupVault: !Ref BackupVaultProd
        ScheduleExpression: "cron(0 4 ? * 2,3,4,6,1,5 *)"
        StartWindowMinutes: 60
        Lifecycle: 
          DeleteAfterDays: !Ref DailyBackupsRetentionProd
        CopyActions:
          - DestinationBackupVaultArn: !If 
            - HasDisasterRecoveryDailyProd
            - !If
              - HasDisasterRecoveryCrossAccount
              - !Sub 'arn:aws:backup:${DisasterRecoveryRegion}:${DisasterRecoveryAccountId}:backup-vault:Default'
              - !Sub 'arn:aws:backup:${DisasterRecoveryRegion}:${AWS::AccountId}:backup-vault:Default'
            - !Ref "AWS::NoValue"
            Lifecycle:
              DeleteAfterDays: !If [HasDisasterRecoveryDailyProd, !Ref DisasterRecoveryDailyBackupsRetentionProd, !Ref "AWS::NoValue"]

Here is a problem with Property " CopyActions " where " DestinationBackupVaultArn " is a Required property according to documentation and using AWS::NoValue is not acceptable in this case will result in error:这是属性“ CopyActions ”的问题,其中“ DestinationBackupVaultArn ”根据文档是必需的属性,在这种情况下使用 AWS::NoValue 是不可接受的将导致错误:

Properties validation failed for resource BackupPlanProd with message: #/BackupPlan/BackupPlanRule/0/CopyActions/0: required key [DestinationBackupVaultArn] not found资源 BackupPlanProd 的属性验证失败,并显示消息:#/BackupPlan/BackupPlanRule/0/CopyActions/0:找不到所需的密钥 [DestinationBackupVaultArn]

Is there any workaround to make a property "CopyActions" conditional in this case without duplicating the whole resource in the template?在这种情况下,是否有任何解决方法可以在不复制模板中的整个资源的情况下使属性“CopyActions”成为条件? eg If I don`t want to enable backups replication depends to my conditions.例如,如果我不想启用备份复制取决于我的条件。

Thanks:)谢谢:)

Put your If one level higher , so that entire CopyActions gets removed if your condition is not satisfied.把你的If提高一级,这样如果你的条件不满足,整个CopyActions就会被删除。

Properties:
  BackupPlan:
    BackupPlanName: !Sub 'BACKUP-PLAN-PROD-${AWS::StackName}'
    AdvancedBackupSettings:
    - ResourceType: EC2
      BackupOptions: 
        WindowsVSS: !Ref VSSConsistent
    BackupPlanRule:
      - RuleName: !Sub Daily-${DailyBackupsRetentionProd}d-retention
        TargetBackupVault: !Ref BackupVaultProd
        ScheduleExpression: "cron(0 4 ? * 2,3,4,6,1,5 *)"
        StartWindowMinutes: 60
        Lifecycle: 
          DeleteAfterDays: !Ref DailyBackupsRetentionProd
        CopyActions: !If
          - HasDisasterRecoveryDailyProd
          - - DestinationBackupVaultArn
              # 
              # other properties    
              # 
              Lifecycle:
                DeleteAfterDays: !If [HasDisasterRecoveryDailyProd, !Ref DisasterRecoveryDailyBackupsRetentionProd, !Ref "AWS::NoValue"]
          - !Ref "AWS::NoValue"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM