如果已经有“可用”卷,我正在尝试设置" if“条件,以跳过在启动配置中添加新的EBS卷。因此,我试图实现的逻辑是,如果下面的检查变量为空,则添加新卷,否则跳过,因为我将从用户数据中添加“可用”卷。$check =Get-EC2卷-Filter @{ Name=“状态”;Values=“可用”}
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeType: gp2
VolumeSize: '100'
!if $check --> not sure how to put if condition here
- DeviceName: /dev/sdb
Ebs:
DeleteOnTermination: "false"
VolumeSize: '50'
VolumeType: gp2
- DeviceName: /dev/sdc
Ebs:
DeleteOnTermination: "false"
VolumeSize: '50'
VolumeType: gp2
发布于 2017-10-14 10:45:16
下面是如何添加条件的示例代码
BlockDeviceMappings:
- !If
- IsNeedVoume
- DeviceName: "/dev/xvdcz"
Ebs:
VolumeSize: !Ref InstanceDockerVolume
VolumeType: 'gp2'
- !Ref AWS::NoValue
发布于 2018-10-15 15:29:01
您可以创建一个条件,即AddEDrive,用于检查是否指定了参数EDriveSize。如果是,则创建BlockDeviceMapping,否则不执行任何操作。
/dev/sda1
是C:\
的推荐DeviceName
对于所有其他附加驱动器,建议使用DeviceName
/dev/xvd[f-z]
。
AWSTemplateFormatVersion: '2010-09-09'
Conditions:
AddCDrive: !Not [!Equals [!Ref CDriveSize, '']]
AddDDrive: !Not [!Equals [!Ref DDriveSize, '']]
AddEDrive: !Not [!Equals [!Ref EDriveSize, '']]
Parameters:
CDriveSize: {Default: '', Type: String}
DDriveSize: {Default: '', Type: String}
EDriveSize: {Default: '', Type: String}
Resources:
Instance:
Properties:
BlockDeviceMappings:
- !If
- AddCDrive
- DeviceName: '/dev/sda1'
Ebs:
VolumeSize: !Ref CDriveSize
VolumeType: gp2
- !Ref AWS::NoValue
- !If
- AddDDrive
- DeviceName: '/dev/xvdf'
Ebs:
VolumeSize: !Ref DDriveSize
VolumeType: gp2
- !Ref AWS::NoValue
- !If
- AddEDrive
- DeviceName: '/dev/xvdg'
Ebs:
VolumeSize: !Ref EDriveSize
VolumeType: gp2
- !Ref AWS::NoValue
https://stackoverflow.com/questions/46508191
复制