cfn-pyplates
cfn-pyplates copied to clipboard
select (mal)function
Please consider the following scenario:
CFT.parameters.add(Parameter('AWS_EC2_Instance-Volume1', 'CommaDelimitedList', {'Default': options['AWS_EC2_Instance-Volume1']})) CFT.conditions.add(Condition('AWS_EC2_Instance-Volume1UsesIops', c_and(c_ref('AWS_EC2_Instance-NeedsVolume1'), c_equals(select('1', ref('AWS_EC2_Instance-Volume1')), 'io1'))))
The YAML: AWS_EC2_Instance-Volume1: 0, standard, none, none, 0
The error I end up with is: raise IntrinsicFuncInputError(select._errmsg_index) IntrinsicFuncInputError: Provided index is invalid!
My guess would be the problem lies in validating if the index exists. Cloudformation will treat the string like an array when ref is used on the run time. So, index 0 would work in pyplates, because it's just a one string, index >0 won't work, because they're out of scope.
It's not clear to me what exactly is going wrong here.
Can you show me the JSON that pyplates is making, and also the JSON that pyplates should be making to fix this?
I've encountered the same issue.
The following returns a IntrinsicFuncInputError: Provided index is invalid!
exception.
template.resources.add(
Resource(public_subnet_name,
'AWS::EC2::Subnet',
{
'AvailabilityZone': select(options['availabilityZoneIndex'], get_azs(ref('AWS::Region'))),
'CidrBlock': options['publicSubnet'],
'VpcId': ref(vpc_name),
}
)
)
availabilityZoneIndex
is set to '1' in my yaml. Here I'm not passing a list, but a get_azs(ref()) to select(): 'AvailabilityZone': select(options['availabilityZoneIndex'], get_azs(ref('AWS::Region'))),
. So the select function in cfn_pyplates.functions
is blowing up here:
try:
args[index]
except IndexError:
raise IntrinsicFuncInputError(select._errmsg_index)