gpt4 book ai didi

amazon-web-services - BlockdeviceMapping 中的 if 条件

转载 作者:行者123 更新时间:2023-12-03 07:11:43 26 4
gpt4 key购买 nike

如果已经有“可用”卷,我尝试添加“if”条件以跳过在启动配置中添加新的 EBS 卷。因此,我想要实现的逻辑是,如果下面的检查变量为空,则添加新卷,否则跳过,因为我要从用户数据添加“可用”卷。$check = Get-EC2Volume -Filter @{ Name="status";值=“可用”}

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

最佳答案

您可以创建一个条件,即 AddEDrive,检查是否指定了参数 EDriveSize。如果是,则创建 BlockDeviceMapping,否则不执行任何操作。

根据 documentation :

/dev/sda1C:\ 的推荐 DeviceName

对于所有其他附加驱动器,建议使用

/dev/xvd[f-z] DeviceName


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

关于amazon-web-services - BlockdeviceMapping 中的 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46508191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com