cloudtools / cloudtools/troposphere
TemplateGenerator: TypeError when CustomResource string property is an expression
- Dominant language
- Python
- Stars
- 4.9k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
(Troposphere version 2.5.3)
I have a custom resource, and I'd like to set the service token on a conditional for compliance reasons; however, I get an error because `TemplateGenerator` seems to require string literals and forbids conditionals. I've also tested by creating an `AWS::S3::Bucket` with a conditional `BucketName` property; however, `TemplateGenerator` happily accepts the conditional there, leading me to think it's an issue particular to custom resources.
```py
from troposphere.template_generator import TemplateGenerator
TemplateGenerator(
{
"AWSTemplateVersion": "2010-09-09",
"Parameters": {"Environment": {"Type": "String"}},
"Conditions": {"Production": {"Equals": [{"Ref": "Environment"}, "prod"]}},
"Resources": {
"MyResource": {
"Type": "Custom::Resource",
"Properties": {
"ServiceToken": {"If": ["Production", "prod", "nonprod"]}
},
}
},
}
)
```
produces:
```
Traceback (most recent call last):
File "example.py", line 12, in
"ServiceToken": {"If": ["Production", "prod", "nonprod"]}
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/template_generator.py", line 72, in __init__
self._get_resource_type_cls(k, v)
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/template_generator.py", line 178, in _convert_definition
return self._create_instance(expected_type, args, ref)
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/template_generator.py", line 297, in _create_instance
return cls(title=ref, **args)
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/__init__.py", line 127, in __init__
self.__setattr__(k, v)
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/__init__.py", line 214, in __setattr__
self._raise_type(name, value, expected_type)
File "/Users/cweber/.pyenv/versions/3.6.8/lib/python3.6/site-packages/troposphere/__init__.py", line 232, in _raise_type
expected_type))
TypeError: : MyResource.ServiceToken is , expected
```
Contributor guide
Assessment
This issue has not been assessed yet.