简体   繁体   中英

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. 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. I can't just use a string type as I want the user to select from AWS-supplied SubnetIds.

How to get around this?

  1. Is there a way to bypass validation, allowing an AWS type chosen to be empty?
  2. Any way to add another option like "None" to the Subnet::Id list?
  3. Is there a way to hide the inlineSubnetId parameter only if the mode is inline?
  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::* ). 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.

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.

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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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