How to use the troposphere.Tags function in troposphere

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_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):
github awslabs / aws-cfn-control / troposhpere / NFS_Server.py View on Github external
),
        ]
    ))

    RootInstanceProfile = t.add_resource(InstanceProfile(
        "RootInstanceProfile",
        Roles=[Ref(RootRole)]
    ))

    EIPAddress = t.add_resource(EIP(
        'EIPAddress',
        Domain='vpc',
        Condition="create_elastic_ip"
    ))

    tags = Tags(Name=Ref("AWS::StackName"))

    NFSInstance = t.add_resource(ec2.Instance(
        'NFSInstance',
        ImageId=FindInMap("AWSRegionAMI", Ref("AWS::Region"), Ref(OperatingSystem)),
        KeyName=Ref(EC2KeyName),
        InstanceType=(Ref(NFSInstanceType)),
        NetworkInterfaces=[
            NetworkInterfaceProperty(
                SubnetId=Ref(Subnet),
                GroupSet=If(
                    "not_existing_sg",
                    [Ref(NFSSecurityGroup), Ref(SshSecurityGroup)],
                    [Ref(NFSSecurityGroup), Ref(SshSecurityGroup), Ref(ExistingSecurityGroup)]
                ),
                AssociatePublicIpAddress=Ref(UsePublicIp),
                DeviceIndex='0',
github cloudtools / troposphere / troposphere / certificatemanager.py View on Github external
class DomainValidationOption(AWSProperty):
    props = {
        'DomainName': (basestring, True),
        'ValidationDomain': (basestring, True),
    }


class Certificate(AWSObject):
    resource_type = "AWS::CertificateManager::Certificate"

    props = {
        'DomainName': (basestring, True),
        'DomainValidationOptions': ([DomainValidationOption], False),
        'SubjectAlternativeNames': ([basestring], False),
        'Tags': ((Tags, list), False),
        'ValidationMethod': (basestring, False),
    }
github cloudtools / troposphere / examples / Dlm.py View on Github external
lifecycle_policy = t.add_resource(LifecyclePolicy(
    "LifecyclePolicy",
    Description="Daily backup",
    State="ENABLED",
    ExecutionRoleArn=GetAtt(dlm_role, 'Arn'),
    PolicyDetails=PolicyDetails(
        ResourceTypes=[
            "VOLUME"
        ],
        TargetTags=Tags(
            Backup="True",
        ),
        Schedules=[
            Schedule(
                Name="Daily Snapshots",
                TagsToAdd=Tags(
                    type="DailySnapshot",
                ),
                CreateRule=CreateRule(
                    Interval=12,
                    IntervalUnit="HOURS",
                    Times=[
                        "13:00"
                    ]
                ),
                RetainRule=RetainRule(
                    Count=1
                ),
                CopyTags=True
            )
        ]
    )
github CCSI-Toolset / FOQUS / cloud / aws / cloudformation / FOQUS_SLM_instance_in_subnet.py View on Github external
})

    # Windows_Server-2016-English-Full-Base-2018.09.15
    t.add_mapping('AWSRegionArch2AMI', {
        'us-east-1': {'HVM64': 'ami-01945499792201081'}
    })

    ref_stack_id = Ref('AWS::StackId')
    ref_region = Ref('AWS::Region')
    ref_stack_name = Ref('AWS::StackName')

    routeTable = t.add_resource(
        RouteTable(
            'RouteTable',
            VpcId=vpc_id,
            Tags=Tags(
                Application=ref_stack_id)))

    route = t.add_resource(
        Route(
            'Route',
            #DependsOn='AttachGateway',
            GatewayId=internetgateway_id,
            DestinationCidrBlock='0.0.0.0/0',
            RouteTableId=Ref(routeTable),
        ))

    subnetRouteTableAssociation = t.add_resource(
        SubnetRouteTableAssociation(
            'SubnetRouteTableAssociation',
            SubnetId=subnet_public_id,
            RouteTableId=Ref(routeTable),
github cloudreach / sceptre-wordpress-example / src / wordpress.py View on Github external
"LoadBalancerPort": "80", "Protocol": "HTTP"}],
            CrossZone="true",
            LoadBalancerName=Join("-", ["elb", Ref(self.Project)]),
            SecurityGroups=[Ref(self.ElbSecurityGroup)],
            ConnectionDrainingPolicy=elb.ConnectionDrainingPolicy(
                Enabled=True,
                Timeout=300,
            ),
            HealthCheck=elb.HealthCheck(
                HealthyThreshold="3",
                Interval="30",
                Target="HTTP:80/",
                Timeout="5",
                UnhealthyThreshold="5",
            ),
            Tags=Tags(
                Name=Join("-", ["ELB", Ref(self.Project)]),
                Environment=Ref(self.Environment),
            ),
        ))

        self.ELBcname = self.template.add_resource(route53.RecordSetType(
            "ELBcname",
            HostedZoneName=Join("", [Ref(self.Domain), "."]),
            Comment="CNAME to Web ELB",
            Name=Join(".", [Ref(self.Hostname), Ref(self.Domain)]),
            Type="CNAME",
            TTL="60",
            ResourceRecords=[GetAtt(self.ElasticLoadBalancer, "DNSName")]
        ))
github cloudtools / stacker / stacker / blueprints / vpc.py View on Github external
zones = []
        for i in range(self.local_parameters["AZCount"]):
            az = Select(i, GetAZs(""))
            zones.append(az)
            name_suffix = i
            for net_type in net_types:
                name_prefix = net_type.capitalize()
                subnet_name = "%sSubnet%s" % (name_prefix, name_suffix)
                subnets[net_type].append(subnet_name)
                t.add_resource(ec2.Subnet(
                    subnet_name,
                    AvailabilityZone=az,
                    VpcId=vpc_id,
                    DependsOn=GW_ATTACH,
                    CidrBlock=Select(i, Ref("%sSubnets" % name_prefix)),
                    Tags=Tags(type=net_type)))
                route_table_name = "%sRouteTable%s" % (name_prefix,
                                                       name_suffix)
                t.add_resource(ec2.RouteTable(
                    route_table_name,
                    VpcId=vpc_id,
                    Tags=[ec2.Tag('type', net_type)]))
                t.add_resource(ec2.SubnetRouteTableAssociation(
                    "%sRouteTableAssociation%s" % (name_prefix, name_suffix),
                    SubnetId=Ref(subnet_name),
                    RouteTableId=Ref(route_table_name)))
                if net_type == 'public':
                    # the public subnets are where the NAT instances live,
                    # so their default route needs to go to the AWS
                    # Internet Gateway
                    t.add_resource(ec2.Route(
                        "%sRoute%s" % (name_prefix, name_suffix),
github cloudtools / troposphere / troposphere / codebuild.py View on Github external
props = {
        'Artifacts': (Artifacts, True),
        'BadgeEnabled': (boolean, False),
        'Cache': (ProjectCache, False),
        'Description': (basestring, False),
        'EncryptionKey': (basestring, False),
        'Environment': (Environment, True),
        "LogsConfig": (LogsConfig, False),
        'Name': (basestring, False),
        'SecondaryArtifacts': ([Artifacts], False),
        'SecondarySourceVersions': ([ProjectSourceVersion], False),
        'SecondarySources': ([Source], False),
        'ServiceRole': (basestring, True),
        'Source': (Source, True),
        'SourceVersion': (basestring, False),
        'Tags': (Tags, False),
        'TimeoutInMinutes': (integer, False),
        'Triggers': (ProjectTriggers, False),
        'VpcConfig': (VpcConfig, False),
    }


class S3ReportExportConfig(AWSProperty):
    props = {
        'Bucket': (basestring, True),
        'EncryptionDisabled': (boolean, False),
        'EncryptionKey': (basestring, False),
        'Packaging': (basestring, False),
        'Path': (basestring, False),
    }
github cloudtools / troposphere / troposphere / cloudformation.py View on Github external
# All rights reserved.
#
# See LICENSE file for full license.

from . import AWSHelperFn, AWSObject, AWSProperty, BaseAWSObject, Tags
from . import encode_to_dict
from .validators import boolean, check_required, encoding, integer


class Stack(AWSObject):
    resource_type = "AWS::CloudFormation::Stack"

    props = {
        'NotificationARNs': ([basestring], False),
        'Parameters': (dict, False),
        'Tags': ((Tags, list), False),
        'TemplateURL': (basestring, True),
        'TimeoutInMinutes': (integer, False),
    }


class AWSCustomObject(BaseAWSObject):
    dictname = 'Properties'


class CustomResource(AWSCustomObject):
    resource_type = "AWS::CloudFormation::CustomResource"

    props = {
        'ServiceToken': (basestring, True)
    }