How to use troposphere - 10 common examples

To help you get started, we’ve selected a few troposphere examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudtools / troposphere / tests / test_template.py View on Github external
def test_eq(self):
        metadata = 'foo'
        description = 'bar'
        resource = Bucket('Baz')
        output = Output('qux', Value='qux')

        t1 = Template(Description=description, Metadata=metadata)
        t1.add_resource(resource)
        t1.add_output(output)

        t2 = Template(Description=description, Metadata=metadata)
        t2.add_resource(resource)
        t2.add_output(output)

        self.assertEqual(t1, t2)
github cloudtools / troposphere / tests / test_awslambda.py View on Github external
def test_check_zip_file(self):
        positive_tests = [
            'a'*4096,
            Join('', ['a'*4096]),
            Join('', ['a', 10]),
            Join('', ['a'*4096, Ref('EmptyParameter')]),
            Join('ab', ['a'*2047, 'a'*2047]),
            GetAtt('foo', 'bar'),
        ]
        for z in positive_tests:
            Code.check_zip_file(z)
        negative_tests = [
            'a'*4097,
            Join('', ['a'*4097]),
            Join('', ['a'*4097, Ref('EmptyParameter')]),
            Join('abc', ['a'*2047, 'a'*2047]),
        ]
        for z in negative_tests:
            with self.assertRaises(ValueError):
                Code.check_zip_file(z)
github cloudtools / troposphere / tests / test_int_type.py View on Github external
def get_aws_objects(self):
        result = []
        modules = self._import_all_modules()
        for module in modules:
            for name in dir(module):
                obj = getattr(module, name)
                if (
                        isinstance(obj, type) and
                        obj != AWSObject and
                        issubclass(obj, AWSObject)
                ):
                    result.append(obj)
        return result
github cloudtools / troposphere / tests / test_implicit_ref.py View on Github external
def test_implicit_ref_in_a_tuple(self):
        t = Template()
        r1 = FakeAWSObject('r1')
        t.add_resource(r1)
        r2 = FakeAWSObject('r2', listproperty=[1, (2, r1)])
        t.add_resource(r2)
        self.assertJsonEquals(t, {
            'Resources': {
                'r1': {
                    'Type': "Fake::AWS::Object",
                    },
                'r2': {
                    'Type': "Fake::AWS::Object",
                    'Properties': {
                        'listproperty': [
                            1,
                            [
                                2,
github cloudtools / troposphere / tests / test_template.py View on Github external
def test_parameter_group(self):
        t = Template()
        p1 = t.add_parameter(Parameter("Foo"))
        t.add_parameter(Parameter("Bar"))
        t.add_parameter_to_group(p1, "gr")
        t.add_parameter_to_group("Bar", "gr")

        self.assertEqual(t.metadata, {
            "AWS::CloudFormation::Interface": {
                "ParameterGroups": [
                    {
                        "Label": {"default": "gr"},
                        "Parameters": ["Foo", "Bar"],
                    },
github rackerlabs / jetstream / test_templates / ec2_instance.py View on Github external
def __init__(self):
        self.name = 'ec2.template'
        self.template = Template()

        self.template.add_version("2010-09-09")
        self.test_parameter_groups = TestParameterGroups()
        default_test_params = TestParameterGroup()
        self.test_parameter_groups.add(default_test_params)

        Environment = self.template.add_parameter(Parameter(
            "Environment",
            Default="Development",
            Type="String",
            Description="Application environment",
            AllowedValues=["Development", "Integration",
                           "PreProduction", "Production", "Staging", "Test"],
        ))
        default_test_params.add(TestParameter("Environment", "Integration"))
github cloudtools / troposphere / tests / test_ec2.py View on Github external
def test_securitygroupegress(self):
        egress = ec2.SecurityGroupEgress(
            'egress',
            ToPort='80',
            FromPort='80',
            IpProtocol="tcp",
            GroupId="id",
            CidrIp="0.0.0.0/0",
        )
        egress.to_dict()

        egress = ec2.SecurityGroupEgress(
            'egress',
            ToPort='80',
            FromPort='80',
            IpProtocol="tcp",
            GroupId="id",
            DestinationPrefixListId='id',
github couchbaselabs / mobile-testkit / libraries / provision / cloudformation_template.py View on Github external
def createCouchbaseSecurityGroups(t):

        # Couchbase security group
        secGrpCouchbase = ec2.SecurityGroup('CouchbaseSecurityGroup')
        secGrpCouchbase.GroupDescription = "Allow access to Couchbase Server"
        secGrpCouchbase.SecurityGroupIngress = [
            ec2.SecurityGroupRule(
                IpProtocol="tcp",
                FromPort="22",
                ToPort="22",
                CidrIp="0.0.0.0/0",
            ),
            ec2.SecurityGroupRule(
                IpProtocol="tcp",
                FromPort="8091",
                ToPort="8096",
                CidrIp="0.0.0.0/0",
            ),
            ec2.SecurityGroupRule(
                IpProtocol="tcp",
github cloudtools / troposphere / tests / test_tags.py View on Github external
def test_TagConditional(self):
        tags = Tags(
            {'foo': 'foo'},
            If('MyCondition', Tag('bar', 'bar'), Tag('baz', 'baz'))
        )
        result = [
            {"Fn::If": ["MyCondition",
                        {"Key": "bar", "Value": "bar"},
                        {"Key": "baz", "Value": "baz"}]},
            {'Value': 'foo', 'Key': 'foo'},
        ]
        self.assertEqual(tags.to_dict(), result)
github cloudtools / troposphere / tests / test_tags.py View on Github external
def test_Formats(self):
        result = [
            {'Value': 'bar', 'Key': 'bar'},
            {'Value': 'baz', 'Key': 'baz'},
            {'Value': 'foo', 'Key': 'foo'},
        ]
        tags = Tags(bar='bar', baz='baz', foo='foo')
        self.assertEqual(tags.to_dict(), result)
        tags = Tags({'bar': 'bar', 'baz': 'baz', 'foo': 'foo'})
        self.assertEqual(tags.to_dict(), result)
        tags = Tags(**{'bar': 'bar', 'baz': 'baz', 'foo': 'foo'})
        self.assertEqual(tags.to_dict(), result)
        result = [{'Key': 'test-tag', 'Value': '123456'}]
        tags = Tags({'test-tag': '123456'})
        self.assertEqual(tags.to_dict(), result)

        with self.assertRaises(TypeError):
            Tags(1)
        with self.assertRaises(TypeError):
            Tags("tag")
        with self.assertRaises(TypeError):
            Tags("key", "value")
        with self.assertRaises(TypeError):