Exemplo n.º 1
0
def emit_configuration():
    vpc = cfn.vpcs[0]

    dbname = template.add_parameter(
        Parameter('RedshiftDatabaseName',
                  Description='The name of database to create within redshift',
                  Type="String",
                  Default="farragut",
                  AllowedPattern="[a-z0-9]*",
                  ConstraintDescription="Must be alphanumeric"))

    clustertype = template.add_parameter(
        Parameter('RedshiftClusterType',
                  Description="The type of cluster to build",
                  Type="String",
                  Default="single-node",
                  AllowedValues=["single-node", "multi-node"]))

    numberofnodes = template.add_parameter(
        Parameter(
            "RedshiftNumberOfNodes",
            Description="The number of compute nodes in the redshift cluster. "
            "When cluster type is specified as: 1) single-node, the NumberOfNodes "
            "parameter should be specified as 1, 2) multi-node, the NumberOfNodes "
            "parameter should be greater than 1",
            Type="Number",
            Default="1",
        ))

    nodetype = template.add_parameter(
        Parameter(
            "RedshiftNodeType",
            Description=
            "The node type to be provisioned for the redshift cluster",
            Type="String",
            Default="dw2.large",
        ))

    masterusername = template.add_parameter(
        Parameter("RedshiftMasterUsername",
                  Description=
                  "The user name associated with the master user account for "
                  "the redshift cluster that is being created",
                  Type="String",
                  Default="sa",
                  AllowedPattern="([a-z])([a-z]|[0-9])*"))

    masteruserpassword = template.add_parameter(
        Parameter(
            "RedshiftMasterUserPassword",
            Description=
            "The password associated with the master user account for the "
            "redshift cluster that is being created.",
            Type="String",
            NoEcho=True,
            Default="LeafLeaf123"))

    ingress_rules = [
        SecurityGroupRule(IpProtocol=p[0],
                          CidrIp=DEFAULT_ROUTE,
                          FromPort=p[1],
                          ToPort=p[1]) for p in [('tcp', 5439)]
    ]

    rs_security_group = template.add_resource(
        SecurityGroup(
            "RedshiftSecurityGroup",
            GroupDescription="SecurityGroup for the {0} Redshift cluster".
            format(CLOUDENV),
            VpcId=Ref(vpc),
            SecurityGroupIngress=ingress_rules,
            DependsOn=vpc.title))

    cluster_subnet_group = template.add_resource(
        ClusterSubnetGroup(
            "RedshiftClusterSubnetGroup",
            Description="Redshift {0} cluster subnet group".format(CLOUDENV),
            SubnetIds=[
                Ref(sn)
                for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)
            ],
            DependsOn=[
                sn.title
                for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)
            ]))

    conditions = {
        "IsMultiNodeCluster": Equals(Ref("RedshiftClusterType"), "multi-mode"),
    }

    for k in conditions:
        template.add_condition(k, conditions[k])

    redshiftcluster = template.add_resource(
        Cluster("RedshiftCluster",
                ClusterType=Ref("RedshiftClusterType"),
                NumberOfNodes=If("IsMultiNodeCluster",
                                 Ref("RedshiftNumberOfNodes"),
                                 Ref("AWS::NoValue")),
                NodeType=Ref("RedshiftNodeType"),
                DBName=Ref("RedshiftDatabaseName"),
                MasterUsername=Ref("RedshiftMasterUsername"),
                MasterUserPassword=Ref("RedshiftMasterUserPassword"),
                ClusterParameterGroupName=Ref("RedshiftClusterParameterGroup"),
                DeletionPolicy="Snapshot",
                ClusterSubnetGroupName=Ref(cluster_subnet_group),
                VpcSecurityGroupIds=[Ref("RedshiftSecurityGroup")],
                DependsOn=[
                    cluster_subnet_group.title, rs_security_group.title
                ]))

    log_activity_parameter = AmazonRedshiftParameter(
        "AmazonRedshiftParameterEnableUserLogging",
        ParameterName="enable_user_activity_logging",
        ParameterValue="true",
    )

    redshiftclusterparametergroup = template.add_resource(
        ClusterParameterGroup(
            "RedshiftClusterParameterGroup",
            Description="Cluster parameter group",
            ParameterGroupFamily="redshift-1.0",
            Parameters=[log_activity_parameter],
        ))

    template.add_output(
        Output(
            "RedshiftClusterEndpoint",
            Value=Join(":", [
                GetAtt(redshiftcluster, "Endpoint.Address"),
                GetAtt(redshiftcluster, "Endpoint.Port")
            ]),
        ))
Exemplo n.º 2
0
def emit_configuration():
    vpc = cfn.vpcs[0]
    region = Ref("AWS::Region")

    dbname = template.add_parameter(
        Parameter(
            "RDSDatabaseInstanceName",
            Default="reporting{0}".format(CLOUDENV),
            Description="Postgres Instance Name",
            Type="String",
            MinLength="1",
            MaxLength="63",
            AllowedPattern="[a-zA-Z][a-zA-Z0-9]*",
            ConstraintDescription=
            "Must begin with a letter and contain only alphanumeric characters"
        ))

    dbuser = template.add_parameter(
        Parameter(
            "RDSDatabaseUser",
            Default="sa",
            Description="The database admin account username",
            Type="String",
            MinLength="1",
            MaxLength="63",
            AllowedPattern="[a-zA-Z][a-zA-Z0-9]*",
            ConstraintDescription="Must being with a letter and be alphanumeric"
        ))

    dbpassword = template.add_parameter(
        Parameter(
            "RDSDatabasePassword",
            NoEcho=True,
            Description="The database admin account password",
            Type="String",
            MinLength="1",
            MaxLength="41",
            AllowedPattern="[a-zA-Z0-9]*",
            ConstraintDescription="Must contain only alphanumeric characters.",
            Default="LeafLeaf123"))

    dbclass = template.add_parameter(
        Parameter("RDSInstanceClass",
                  Default="db.t2.medium",
                  Description="Database instance size",
                  Type="String",
                  AllowedValues=[
                      "db.t2.small", "db.t2.medium", "db.m3.medium",
                      "db.m3.large", "db.m3.xlarge", "db.m3.2xlarge",
                      "db.r3.large", "db.r3.xlarge", "db.r3.2xlarge",
                      "db.r3.4xlarge", "db.r3.8xlarge"
                  ]))

    allocated_storage = template.add_parameter(
        Parameter("RDSAllocatedStorage",
                  Default="100",
                  Description="The size of the Postgres Database (GB)",
                  Type="Number",
                  MinValue="5",
                  MaxValue="512",
                  ConstraintDescription="Must be between 5 and 512 GB"))

    db_subnet_group = template.add_resource(
        DBSubnetGroup(
            "RDSSubnetGroup",
            DBSubnetGroupDescription="Subnets available for RDS in {0}".format(
                CLOUDNAME),
            SubnetIds=[
                Ref(sn)
                for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)
            ],
            DependsOn=[
                sn.title
                for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)
            ]))

    ingress_rules = [
        SecurityGroupRule(IpProtocol=p[0],
                          CidrIp=DEFAULT_ROUTE,
                          FromPort=p[1],
                          ToPort=p[1]) for p in [('tcp', 5432)]
    ]

    security_group = template.add_resource(
        SecurityGroup("RDSDatabaseSecurityGroup",
                      GroupDescription="Security group for Postgres Instances",
                      VpcId=Ref(vpc),
                      SecurityGroupIngress=ingress_rules,
                      DependsOn=vpc.title))

    database = template.add_resource(
        DBInstance(
            "RDSPostgresInstance",
            DBInstanceIdentifier=Ref(dbname),
            AllocatedStorage=Ref(allocated_storage),
            DBInstanceClass=Ref(dbclass),
            Engine="postgres",
            EngineVersion="9.3.6",
            MasterUsername=Ref(dbuser),
            MasterUserPassword=Ref(dbpassword),
            DBSubnetGroupName=Ref(db_subnet_group),
            VPCSecurityGroups=[Ref(security_group)],
            DependsOn=[
                sn.title
                for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)
            ]))

    template.add_output(
        Output("ConnectionString",
               Description="JDBC connection string for Postgres",
               Value=Join("", [
                   GetAtt("RDSPostgresInstance", "Endpoint.Address"),
                   GetAtt("RDSPostgresInstance", "Endpoint.Port")
               ])))
Exemplo n.º 3
0
def emit_configuration():
    vpc = cfn.vpcs[0]
    region = Ref("AWS::Region")

    dbname = template.add_parameter(
        Parameter(
            "RDSDatabaseInstanceName",
            Default="reporting{0}".format(CLOUDENV),
            Description="Postgres Instance Name",
            Type="String",
            MinLength="1",
            MaxLength="63",
            AllowedPattern="[a-zA-Z][a-zA-Z0-9]*",
            ConstraintDescription="Must begin with a letter and contain only alphanumeric characters"
        )
    )

    dbuser = template.add_parameter(
        Parameter(
            "RDSDatabaseUser",
            Default="sa",
            Description="The database admin account username",
            Type="String",
            MinLength="1",
            MaxLength="63",
            AllowedPattern="[a-zA-Z][a-zA-Z0-9]*",
            ConstraintDescription="Must being with a letter and be alphanumeric"
        )
    )

    dbpassword = template.add_parameter(
        Parameter(
            "RDSDatabasePassword",
            NoEcho=True,
            Description="The database admin account password",
            Type="String",
            MinLength="1",
            MaxLength="41",
            AllowedPattern="[a-zA-Z0-9]*",
            ConstraintDescription="Must contain only alphanumeric characters.",
            Default="LeafLeaf123"
        )
    )

    dbclass = template.add_parameter(
        Parameter(
            "RDSInstanceClass",
            Default="db.t2.medium",
            Description="Database instance size",
            Type="String",
            AllowedValues=[
                "db.t2.small", "db.t2.medium", "db.m3.medium", "db.m3.large",
                "db.m3.xlarge", "db.m3.2xlarge", "db.r3.large", "db.r3.xlarge",
                "db.r3.2xlarge", "db.r3.4xlarge", "db.r3.8xlarge"
            ]
        )
    )

    allocated_storage = template.add_parameter(
        Parameter(
            "RDSAllocatedStorage",
            Default="100",
            Description="The size of the Postgres Database (GB)",
            Type="Number",
            MinValue="5",
            MaxValue="512",
            ConstraintDescription="Must be between 5 and 512 GB"
        )
    )

    db_subnet_group = template.add_resource(
        DBSubnetGroup(
            "RDSSubnetGroup",
            DBSubnetGroupDescription="Subnets available for RDS in {0}".format(CLOUDNAME),
            SubnetIds=[Ref(sn) for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)],
            DependsOn=[sn.title for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)]
        )
    )

    ingress_rules = [
        SecurityGroupRule(
            IpProtocol=p[0], CidrIp=DEFAULT_ROUTE, FromPort=p[1], ToPort=p[1]
        ) for p in [('tcp', 5432)]]

    security_group = template.add_resource(
        SecurityGroup(
            "RDSDatabaseSecurityGroup",
            GroupDescription="Security group for Postgres Instances",
            VpcId=Ref(vpc),
            SecurityGroupIngress=ingress_rules,
            DependsOn=vpc.title
        )
    )

    database = template.add_resource(
        DBInstance(
            "RDSPostgresInstance",
            DBInstanceIdentifier=Ref(dbname),
            AllocatedStorage=Ref(allocated_storage),
            DBInstanceClass=Ref(dbclass),
            Engine="postgres",
            EngineVersion="9.3.6",
            MasterUsername=Ref(dbuser),
            MasterUserPassword=Ref(dbpassword),
            DBSubnetGroupName=Ref(db_subnet_group),
            VPCSecurityGroups=[Ref(security_group)],
            DependsOn=[sn.title for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)]
        )
    )

    template.add_output(
        Output(
            "ConnectionString",
            Description="JDBC connection string for Postgres",
            Value=Join("", [
                GetAtt("RDSPostgresInstance", "Endpoint.Address"),
                GetAtt("RDSPostgresInstance", "Endpoint.Port")
            ])
        )
    )
Exemplo n.º 4
0
def emit_configuration():
    vpc = cfn.vpcs[0]

    dbname = template.add_parameter(
        Parameter(
            'RedshiftDatabaseName',
            Description='The name of database to create within redshift',
            Type="String",
            Default="farragut",
            AllowedPattern="[a-z0-9]*",
            ConstraintDescription="Must be alphanumeric"
        )
    )

    clustertype = template.add_parameter(
        Parameter(
            'RedshiftClusterType',
            Description="The type of cluster to build",
            Type="String",
            Default="single-node",
            AllowedValues=["single-node", "multi-node"]
        )
    )

    numberofnodes = template.add_parameter(
        Parameter(
            "RedshiftNumberOfNodes",
            Description="The number of compute nodes in the redshift cluster. "
            "When cluster type is specified as: 1) single-node, the NumberOfNodes "
            "parameter should be specified as 1, 2) multi-node, the NumberOfNodes "
            "parameter should be greater than 1",
            Type="Number",
            Default="1",
        )
    )

    nodetype = template.add_parameter(
        Parameter(
            "RedshiftNodeType",
            Description="The node type to be provisioned for the redshift cluster",
            Type="String",
            Default="dw2.large",
        )
    )

    masterusername = template.add_parameter(Parameter(
        "RedshiftMasterUsername",
        Description="The user name associated with the master user account for "
        "the redshift cluster that is being created",
        Type="String",
        Default="sa",
        AllowedPattern="([a-z])([a-z]|[0-9])*"
    ))

    masteruserpassword = template.add_parameter(Parameter(
        "RedshiftMasterUserPassword",
        Description="The password associated with the master user account for the "
        "redshift cluster that is being created.",
        Type="String",
        NoEcho=True,
        Default="LeafLeaf123"
    ))

    ingress_rules = [
        SecurityGroupRule(
            IpProtocol=p[0], CidrIp=DEFAULT_ROUTE, FromPort=p[1], ToPort=p[1]
        ) for p in [('tcp', 5439)]
    ]

    rs_security_group = template.add_resource(
        SecurityGroup(
            "RedshiftSecurityGroup",
            GroupDescription="SecurityGroup for the {0} Redshift cluster".format(CLOUDENV),
            VpcId=Ref(vpc),
            SecurityGroupIngress=ingress_rules,
            DependsOn=vpc.title
        )
    )

    cluster_subnet_group = template.add_resource(
        ClusterSubnetGroup(
            "RedshiftClusterSubnetGroup",
            Description="Redshift {0} cluster subnet group".format(CLOUDENV),
            SubnetIds=[Ref(sn) for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)],
            DependsOn=[sn.title for sn in cfn.get_vpc_subnets(vpc, cfn.SubnetTypes.DATABASE)]
        )
    )

    conditions = {
        "IsMultiNodeCluster": Equals(
            Ref("RedshiftClusterType"),
            "multi-mode"
        ),
    }

    for k in conditions:
        template.add_condition(k, conditions[k])

    redshiftcluster = template.add_resource(Cluster(
        "RedshiftCluster",
        ClusterType=Ref("RedshiftClusterType"),
        NumberOfNodes=If("IsMultiNodeCluster",
                         Ref("RedshiftNumberOfNodes"), Ref("AWS::NoValue")),
        NodeType=Ref("RedshiftNodeType"),
        DBName=Ref("RedshiftDatabaseName"),
        MasterUsername=Ref("RedshiftMasterUsername"),
        MasterUserPassword=Ref("RedshiftMasterUserPassword"),
        ClusterParameterGroupName=Ref("RedshiftClusterParameterGroup"),
        DeletionPolicy="Snapshot",
        ClusterSubnetGroupName=Ref(cluster_subnet_group),
        VpcSecurityGroupIds=[Ref("RedshiftSecurityGroup")],
        DependsOn=[cluster_subnet_group.title, rs_security_group.title]
    ))

    log_activity_parameter = AmazonRedshiftParameter(
        "AmazonRedshiftParameterEnableUserLogging",
        ParameterName="enable_user_activity_logging",
        ParameterValue="true",
    )

    redshiftclusterparametergroup = template.add_resource(ClusterParameterGroup(
        "RedshiftClusterParameterGroup",
        Description="Cluster parameter group",
        ParameterGroupFamily="redshift-1.0",
        Parameters=[log_activity_parameter],
    ))

    template.add_output(Output(
        "RedshiftClusterEndpoint",
        Value=Join(":", [GetAtt(redshiftcluster, "Endpoint.Address"),
                   GetAtt(redshiftcluster, "Endpoint.Port")]),
    ))