How to use the troposphere.FindInMap 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 ClusterHQ / flocker / admin / installer / cloudformation.py View on Github external
# from 0.
flocker_agent_number = 1

# Gather WaitConditions
wait_condition_names = []

for i in range(_get_cluster_size()):
    if i == 0:
        node_name = CONTROL_NODE_NAME
    else:
        node_name = AGENT_NODE_NAME_TEMPLATE.format(index=i)

    # Create an EC2 instance for the {Agent, Control} Node.
    ec2_instance = ec2.Instance(
        node_name,
        ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "FlockerAMI"),
        InstanceType="m3.large",
        KeyName=Ref(keyname_param),
        SecurityGroups=[Ref(instance_sg)],
        AvailabilityZone=zone,
        Tags=Tags(Name=node_name))

    # WaitCondition and corresponding Handler to signal completion
    # of {Flocker, Docker, Swarm} configuration on the node.
    wait_condition_handle = WaitConditionHandle(
        INFRA_WAIT_HANDLE_TEMPLATE.format(node=node_name))
    template.add_resource(wait_condition_handle)
    wait_condition = WaitCondition(
        INFRA_WAIT_CONDITION_TEMPLATE.format(node=node_name),
        Handle=Ref(wait_condition_handle),
        Timeout=NODE_CONFIGURATION_TIMEOUT,
    )
github caktus / aws-web-stacks / stack / database.py View on Github external
template=template,
    GroupDescription="Database security group.",
    Condition=db_condition,
    VpcId=Ref(vpc),
    SecurityGroupIngress=[
        # Rds Port in from web clusters
        ec2.SecurityGroupRule(
            IpProtocol="tcp",
            FromPort=FindInMap("RdsEngineMap", Ref(db_engine), "Port"),
            ToPort=FindInMap("RdsEngineMap", Ref(db_engine), "Port"),
            CidrIp=container_a_subnet_cidr,
        ),
        ec2.SecurityGroupRule(
            IpProtocol="tcp",
            FromPort=FindInMap("RdsEngineMap", Ref(db_engine), "Port"),
            ToPort=FindInMap("RdsEngineMap", Ref(db_engine), "Port"),
            CidrIp=container_b_subnet_cidr,
        ),
    ],
)

db_subnet_group = rds.DBSubnetGroup(
    "DatabaseSubnetGroup",
    template=template,
    Condition=db_condition,
    DBSubnetGroupDescription="Subnets available for the RDS DB Instance",
    SubnetIds=[Ref(container_a_subnet), Ref(container_b_subnet)],
)

db_instance = rds.DBInstance(
    # TODO: rename this resource to something generic along with the next major release
    "PostgreSQL",
github streamlit / streamlit / scripts / create_streamlit_cloudformation_template.py View on Github external
def add_ec2_instance(self):
        self._resources.update({
            'Ec2Instance': ec2.Instance(
                'Ec2Instance',
                ImageId=FindInMap("RegionMap", Ref("AWS::Region"), "AMI"),
                InstanceType=Ref(self._parameters['Ec2InstanceType']),
                KeyName=Ref(self._parameters['SshKeyName']),
                NetworkInterfaces=[
                    ec2.NetworkInterfaceProperty(
                        GroupSet=[
                            Ref(self._resources['Ec2InstanceSecurityGroup']),
                        ],
                        AssociatePublicIpAddress='true',
                        DeviceIndex='0',
                        DeleteOnTermination='true',
                        SubnetId=Ref(self._parameters['SubnetId']),
                    ),
                ],
                UserData=Base64(Join(
                    '',
                    [
github cloudtools / troposphere / examples / ElasticBeanstalk_Nodejs_Sample.py View on Github external
'OpsWorksPrincipal': 'opsworks.amazonaws.com'},
    'us-west-2': {
        'EC2Principal': 'ec2.amazonaws.com',
        'OpsWorksPrincipal': 'opsworks.amazonaws.com'}
    }
)

t.add_resource(Role(
    "WebServerRole",
    AssumeRolePolicyDocument=PolicyDocument(
        Statement=[
            Statement(
                Effect=Allow, Action=[AssumeRole],
                Principal=Principal(
                    "Service", [
                        FindInMap(
                            "Region2Principal",
                            Ref("AWS::Region"), "EC2Principal")
                    ]
                )
            )
        ]
    ),
    Path="/"
))

t.add_resource(IAMPolicy(
    "WebServerRolePolicy",
    PolicyName="WebServerRole",
    PolicyDocument=PolicyDocument(
        Statement=[
            Statement(Effect=Allow, NotAction=Action("iam", "*"),
github DualSpark / cloudformation-environmentbase / src / environmentbase / patterns / base_network.py View on Github external
def create_network_components(self, network_config, nat_config):
        """
        Method creates a network with the specified number of public and private subnets within the
        VPC cidr specified by the networkAddresses CloudFormation mapping.
        @param network_config [dict] collection of network parameters for creating the VPC network
        """

        ## make VPC
        if 'network_name' in network_config:
            network_name = network_config.get('network_name')
        else:
            network_name = self.__class__.__name__

        self._vpc_cidr = FindInMap('networkAddresses', 'vpcBase', 'cidr')
        self.add_output(Output('networkAddresses', Value=str(self.mappings['networkAddresses'])))
        self.add_output(Output('vpcCidr', Value=self.vpc_cidr))

        self._vpc_id = self.add_resource(ec2.VPC('vpc',
                CidrBlock=self._vpc_cidr,
                EnableDnsSupport=True,
                EnableDnsHostnames=True,
                Tags=[ec2.Tag(key='Name', value=network_name)]))

        self.add_output(Output('vpcId', Value=self.vpc_id))

        self._igw = self.add_resource(ec2.InternetGateway('vpcIgw'))
        self.add_output(Output('internetGateway', Value=self.igw))

        ## add IGW
        igw_title = 'igwVpcAttachment'
github DualSpark / VPNJumpbox / src / vpnjumpbox.py View on Github external
startup_vars = []
        startup_vars.append(Join('=', ['EIP_ALLOC_ID', GetAtt(eip, "AllocationId")]))
        startup_vars.append(Join('=', ['REGION', Ref("AWS::Region")]))
        startup_vars.append(Join('=', ['STACKNAME', Ref("AWS::StackName")]))
        startup_vars.append(Join('=', ['ASG_NAME', asg_name]))
        startup_vars.append(Join('=', ['public_hostname', Ref(eip)]))
        startup_vars.append(Join('=', ['admin_user', self.admin_user]))
        user_data = self.build_bootstrap(
            [JUMPBOX_USERDATA],
            prepend_line='#!/bin/bash -x',
            variable_declarations=startup_vars)

        launch_config = self.add_resource(LaunchConfiguration(
            '%sLaunchConfiguration' % self.name,
            IamInstanceProfile=Ref(instance_profile),
            ImageId=FindInMap('RegionMap', Ref('AWS::Region'), AMI_NAME),
            InstanceType=self.instance_type,
            SecurityGroups=[self.common_security_group, Ref(sg)],
            KeyName=self.ec2_key,
            AssociatePublicIpAddress=True,
            InstanceMonitoring=True,
            UserData=user_data))

        return launch_config
github blazing-edge-labs / cloudformation-static-site / templates / static_site.py View on Github external
Name=Join("", [Ref(HostedZoneName), "."]),
            Type="A",
            AliasTarget=AliasTarget(
                FindInMap("RegionMap", "cloudfront", "hostedzoneID"),
                Join(
                    "",
                    [GetAtt(StaticSiteBucketDistribution, "DomainName"), "."]
                ),
            )
        ),
        RecordSet(
            Name=Join("", ["www.", Ref(HostedZoneName), "."]),
            Type="A",
            AliasTarget=AliasTarget(
                FindInMap("RegionMap", Ref("AWS::Region"), "hostedzoneID"),
                FindInMap("RegionMap", Ref("AWS::Region"), "websiteendpoint")
            )
        ),
    ]
else:
    record_sets = [
        RecordSet(
            Name=Join("", [Ref(HostedZoneName), "."]),
            Type="A",
            AliasTarget=AliasTarget(
                FindInMap("RegionMap", Ref("AWS::Region"), "hostedzoneID"),
                FindInMap("RegionMap", Ref("AWS::Region"), "websiteendpoint")
            )
        ),
        RecordSet(
            Name=Join("", ["www.", Ref(HostedZoneName), "."]),
            Type="CNAME",
github cloudreach / sceptre-wordpress-example / src / wordpress.py View on Github external
"--title='Cloudreach Meetup - ", Ref(
                    self.Environment), "' ",
                "--admin_user='root' ",
                "--admin_password='wordpress' ",
                "--admin_email='meetup@cloudreach.com'\n",
                "wget  https://s3-eu-west-1.amazonaws.com/sceptre-meetup-munich/header.jpg -O /var/www/html/wp-content/themes/twentyseventeen/assets/images/header.jpg\n",
                "chown www-data:www-data /var/www/html/wp-content/themes/twentyseventeen/assets/images/header.jpg\n",

                "fi\n",

                "/usr/local/bin/cfn-signal -e $? --stack ", Ref(
                    "AWS::StackName"), "   -r \"Webserver setup complete\" '", Ref(self.WaitHandle), "'\n"

            ]
            )),
            ImageId=FindInMap("AWSRegion2AMI", Ref("AWS::Region"), "AMI"),
            KeyName=Ref(self.KeyName),
            SecurityGroups=[Ref(self.WebSecurityGroup)],
            InstanceType=Ref(self.InstanceType),
            AssociatePublicIpAddress=True,
        ))

        self.WebServerAutoScalingGroup = self.template.add_resource(autoscaling.AutoScalingGroup(
            "WebServerAutoScalingGroup",
            MinSize=Ref(self.WebServerCapacity),
            DesiredCapacity=Ref(self.WebServerCapacity),
            MaxSize=Ref(self.WebServerCapacity),
            VPCZoneIdentifier=[Ref(self.Subnet1), Ref(self.Subnet2)],
            AvailabilityZones=[Ref(self.AvailabilityZone1),
                               Ref(self.AvailabilityZone2)],
            Tags=autoscaling.Tags(
                Name=Join("-", [Ref(self.Project), "web", "asg"]),
github cloudtools / stacker / stacker / blueprints / empire / empire_minion.py View on Github external
def create_autoscaling_group(self):
        t = self.template
        t.add_resource(
            autoscaling.LaunchConfiguration(
                'EmpireMinionLaunchConfig',
                IamInstanceProfile=GetAtt("EmpireMinionProfile",
                                          "Arn"),
                ImageId=FindInMap('AmiMap',
                                  Ref("AWS::Region"),
                                  Ref("ImageName")),
                BlockDeviceMappings=self.build_block_device(),
                InstanceType=Ref("InstanceType"),
                KeyName=Ref("SshKeyName"),
                UserData=self.generate_user_data(),
                SecurityGroups=[Ref("DefaultSG"), Ref(CLUSTER_SG_NAME)]))
        t.add_resource(
            autoscaling.AutoScalingGroup(
                'EmpireMinionAutoscalingGroup',
                AvailabilityZones=Ref("AvailabilityZones"),
                LaunchConfigurationName=Ref("EmpireMinionLaunchConfig"),
                MinSize=Ref("MinSize"),
                MaxSize=Ref("MaxSize"),
                VPCZoneIdentifier=Ref("PrivateSubnets"),
                Tags=[ASTag('Name', 'empire_minion', True)]))