Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AWSHelperFn for Tags properties #2271

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from troposphere import If, Sub, Tag, Tags
from troposphere import GetAtt, If, Sub, Tag, Tags
from troposphere.autoscaling import Tags as ASTags


Expand Down Expand Up @@ -88,6 +88,18 @@ def test_json_tags(self):
Tags={"foo": "bar"},
)

JobDefinition(
"myjobdef",
Type="container",
ContainerProperties=ContainerProperties(
Image="image",
Vcpus=2,
Memory=2000,
Command=["echo", "foobar"],
),
Tags=GetAtt("resource", "tags"),
)

with self.assertRaises(TypeError):
JobDefinition(
"myjobdef",
Expand All @@ -114,6 +126,39 @@ def test_json_tags(self):
Tags="string",
)

def test_object_tags(self):
from troposphere.dynamodb import KeySchema, Table

Table(
"mytable",
KeySchema=[KeySchema(KeyType="HASH", AttributeName="id")],
BillingMode="PAY_PER_REQUEST",
Tags=Tags(Name="Example"),
)

Table(
"mytable",
KeySchema=[KeySchema(KeyType="HASH", AttributeName="id")],
BillingMode="PAY_PER_REQUEST",
Tags=GetAtt("resource", "tags"),
)

with self.assertRaises(TypeError):
Table(
"mytable",
KeySchema=[KeySchema(KeyType="HASH", AttributeName="id")],
BillingMode="PAY_PER_REQUEST",
Tags={"Name": "Example"},
)

with self.assertRaises(TypeError):
Table(
"mytable",
KeySchema=[KeySchema(KeyType="HASH", AttributeName="id")],
BillingMode="PAY_PER_REQUEST",
Tags="string",
)


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion troposphere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __setattr__(self, name: str, value: Any) -> None:
# to deal with this that we'll come up with eventually
#
# Don't do this for Tags since we can validate the assigned type below
if isinstance(value, AWSHelperFn) and name != "Tags":
if isinstance(value, AWSHelperFn) and not isinstance(value, Tags):
return self.properties.__setitem__(name, value)

# If it's a function, call it...
Expand Down
Loading