简体   繁体   English

AWS Cloudformation参数依赖项

[英]AWS Cloudformation parameter dependency

I'm trying to do the following: 我正在尝试执行以下操作:

"Parameters": {
    "InterfaceMode" : {
        "Description": "Configure instance to run in onearm or inline mode",
        "Type": "String",
        "Default": "onearm",
        "AllowedValues": [ "onearm", "inline" ], 
    }
    "InlineSubnetId" : {
        "Description": "Name of a subnet assigned to the VPC to use for second interface in inline mode.", 
        "Type": "AWS::EC2::Subnet::Id",
        "Default": "None"
    },

Now if the user selects onearm, only one interface is needed and the InlineSubnetId is not needed. 现在,如果用户选择onearm,则只需要一个接口,不需要InlineSubnetId。 Usually the user would leave the "InlineSubnetId" drop down empty, but this doesn't work with cloudformation validation since it requires a value for AWS types. 通常,用户会将“InlineSubnetId”下拉列表保留为空,但这不适用于云形式验证,因为它需要AWS类型的值。 I can't just use a string type as I want the user to select from AWS-supplied SubnetIds. 我不能只使用字符串类型,因为我希望用户从AWS提供的SubnetId中进行选择。

How to get around this? 怎么解决这个问题?

  1. Is there a way to bypass validation, allowing an AWS type chosen to be empty? 有没有办法绕过验证,允许选择的AWS类型为空?
  2. Any way to add another option like "None" to the Subnet::Id list? 有没有办法在Subnet :: Id列表中添加“None”等其他选项?
  3. Is there a way to hide the inlineSubnetId parameter only if the mode is inline? 有没有办法在模式内联时隐藏inlineSubnetId参数?
  4. How about a second page of parameters, that depends on the output of the first page of paramters? 第二页参数怎么样,这取决于第一页参数的输出?

Thanks for the help. 谢谢您的帮助。

Unfortunately, if you want a Parameter to be optional, you can not use any of the AWS-specific parameter types (ie AWS::* ). 不幸的是,如果您希望Parameter是可选的,则不能使用任何特定于AWS的参数类型(即AWS::* )。 None of your hoped-for workarounds will work, either. 您希望的解决方案也不会起作用。 I'd recommend a type String with an AllowedPattern set to something like ^(subnet-[0-9a-fA-F]{8})?$ , but this will not meet your requirement of making the drop-down prepopulated with existing subnet values. 我建议使用一个类型的String ,其AllowedPattern设置为^(subnet-[0-9a-fA-F]{8})?$ ,但这不符合您使用现有预先填充的下拉列表的要求子网值。

I do not think there is a good solution to your problem. 我不认为你的问题有一个很好的解决方案。 One thing that you could try is to use AWS::NoValue as default default value, but I doubt it will work. 您可以尝试的一件事是使用AWS :: NoValue作为默认默认值,但我怀疑它是否有效。

I've been looking for this type of conditional parameter as well and as far as I can tell it doesn't exist. 我一直在寻找这种类型的条件参数,据我所知,它不存在。 The closest you can come is an AWS Condition. 您最接近的是AWS Condition。

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-conditions html的

This will allow you to define conditions that evaluate to true or false based on input parameters that you can then use along with Fn:If statements to inject different values into resources. 这将允许您根据输入参数定义评估为true或false的条件,然后可以将这些条件与Fn:If语句一起使用以将不同的值注入资源。

So for your above scenario you may want to default the value to a known subnet id, but use Conditions to ignore this value if not needed. 因此,对于上面的场景,您可能希望将值默认为已知的子网ID,但如果不需要,则使用条件忽略此值。 Unfortunately this falls a bit short if you are trying to use the same CloudFormation template across different VPCs as the default subnet wouldn't exist. 不幸的是,如果您尝试在不同的VPC上使用相同的CloudFormation模板,这会有点短暂,因为默认子网不存在。

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

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