Suggestions for writing an allowed_values line to pull multiple values from a registry file

198 views
Skip to first unread message

Jay

unread,
Jan 2, 2017, 9:04:29 AM1/2/17
to SparkleFormation
Hi All,

I'm looking for a suggestion to rewrite this 'allowed_values' line in my sparkleformation template to accept more than just one of the allowed default subnet values from a registry file.  It only will allow one subnet from the allowed list instead of two.  If I comment that line out, the aws stack builds successfully with the two subnets defined in the 'default registry' line.  

If I uncomment the 'allowed_values' line, the stack build fails with:

$ bundle exec sfn create Redmine-Lab1 --file redmine 
... 
ERROR: Miasma::Error::ApiError::RequestError: Bad Request - ValidationError: Parameter 'PublicSubnetIds' must be one of AllowedValues


Currently I have lines like this that pull the subnets from a registry file:

    set!(:public_subnet_ids) do
      description 'Comma-delimited list of 2 Public Subnets.'
      type 'CommaDelimitedList'
      default registry!(:vpc_subnets)['lab1_a'] + "," + registry!(:vpc_subnets)['lab1_b']
      allowed_values registry!(:vpc_subnets).values


The registry file looks like:

SfnRegistry.register(:vpc_subnets) do
  {
    'lab1_a' => 'subnet-0xxxxxxx',
    'lab1_b' => 'subnet-1xxxxxxx',
    'lab2_a' => 'subnet-2xxxxxxx',
    'lab2_b' => 'subnet-3xxxxxxx',
    'lab3_a' => 'subnet-4xxxxxxx',
    'lab3_b' => 'subnet-5xxxxxxx',
  }
end


Thanks!

Aaron Baer

unread,
Jan 18, 2017, 2:54:15 AM1/18/17
to SparkleFormation
You are sort of up against a limitation of AWS CloudFormation Parameters. 

allowed_values can only be a list of strings. So what you are trying to compare is in fact not in your list of allowed values. Your Default value is valid if your registry looks like this. Including zed you have a valid match and template.

SfnRegistry.register(:vpc_subnets) do
  {
    'lab1_a' => 'subnet-0xxxxxxx',
    'lab1_b' => 'subnet-1xxxxxxx',
    'lab2_a' => 'subnet-2xxxxxxx',
    'lab2_b' => 'subnet-3xxxxxxx',
    'lab3_a' => 'subnet-4xxxxxxx',
    'lab3_b' => 'subnet-5xxxxxxx',
    'zed' =>  'subnet-0xxxxxxx,subnet-1xxxxxxx'
  }
end

This is a valid parameter's allowed_values and it produces this CloudFormation json.

    "MyParam": {
      "Type": "CommaDelimitedList",
      "Default": "subnet-0xxxxxxx,subnet-1xxxxxxx",
      "AllowedValues": [
        "subnet-0xxxxxxx",
        "subnet-1xxxxxxx",
        "subnet-2xxxxxxx",
        "subnet-3xxxxxxx",
        "subnet-4xxxxxxx",
        "subnet-5xxxxxxx",
        "subnet-0xxxxxxx,subnet-1xxxxxxx"
      ]
    }

Without zed you can see that it would not have a valid match in your original registry. CommaDelimitedList isn't really evaluated as an array or List until it's ref! is used. And allowed_values is only allowed to be a List of Strings

If you're just trying to source a registry of subnet ids and use them for a resource's 'Subnet' property then maybe something list this would work for you.

Your registry could be an array instead of a hash:

SfnRegistry.register(:vpc_subnets_as_array) do
  [
    'subnet-0xxxxxxx',
    'subnet-1xxxxxxx',
    'subnet-2xxxxxxx',
    'subnet-3xxxxxxx',
    'subnet-4xxxxxxx',
    'subnet-5xxxxxxx'
  ]
end

Your template can gather information from the registry

  thesubnets = registry!(:vpc_subnets_as_array)
  mysub = [ thesubnets[0], thesubnets[1] ]

or even

  mysub = [ registry!(:vpc_subnets_as_array)[0], registry!(:vpc_subnets_as_array)[1] ]

Then because I don't know your use case here I'll make one up. Let's say you were using an Elastic Load Balancing Load Balancer.

  dynamic!(:elastic_load_balancing_load_balancer, :elb) do
    properties do
      subnets mysub
    end
  end


You would end up with the following valid CloudFormation

    "ElbElasticLoadBalancingLoadBalancer": {
      "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
      "Properties": {
        "Subnets": [
          "subnet-0xxxxxxx",
          "subnet-1xxxxxxx"
        ]
      }
    }


A-

Jayson Roland

unread,
Jan 18, 2017, 5:34:41 PM1/18/17
to sparklef...@googlegroups.com
Hey Aaron,
Thanks so much.  That's exactly what I was looking for!

--
You received this message because you are subscribed to a topic in the Google Groups "SparkleFormation" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sparkleformation/-eb269jcwb0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sparkleformation+unsubscribe@googlegroups.com.
To post to this group, send email to sparkleformation@googlegroups.com.
Visit this group at https://groups.google.com/group/sparkleformation.
To view this discussion on the web visit https://groups.google.com/d/msgid/sparkleformation/0fcb937b-3d75-4788-b028-de0bd04165ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages