Exemplo n.º 1
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        #
        # ECR Repository
        #

        for ecr_repo_name, ecr_repo_configuration in resource_specs.items():

            # AWS ECR Dynamic Variables
            resource_repo_name = ecr_repo_name
            # resource_repo_version      = eks_repo_configuration["version"]

            resource_repo_tags = None
            resource_repo_tags = ecr_repo_configuration[
                "tags"] if "tags" in ecr_repo_configuration else None

            # Getting list of tags from configuration file
            repo_tags_list = {}

            if resource_repo_tags is not None:
                for each_tag_name, each_tag_value in resource_repo_tags.items(
                ):
                    repo_tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            repo_tags_list.update({"Name": resource_repo_name})
            repo_tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            repo_tags_list.update(resource_mandatory_tags)
Exemplo n.º 2
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for eip_name, eip_configuration in resource_specs.items():

            # AWS Elastic IP Dynamic Variables
            resource_name = eip_name
            resource_tags = eip_configuration["tags"] if "'tags':" in str(
                eip_configuration) else None

            # Lists
            tags_list = {}

            # Getting list of tags from configuration file
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            eip = net.Eip(resource_name, tags=tags_list)

            eip_ids_dict.update({eip._name: eip.id})

            # Exporting each EIP
            pulumi.export(eip._name, eip.id)
Exemplo n.º 3
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()
        aws_vpc_id = VPCs.VPCId()

        for subnet_name, subnet_configuration in resource_specs.items():

            # AWS Subnet Dynamic Variables
            resource_name = subnet_name
            resource_az = subnet_configuration["az"]
            resource_cidr = subnet_configuration["cidr"]
            resource_assign_public_ipv4 = subnet_configuration[
                "assign-public-ipv4"]
            resource_vpc = subnet_configuration["vpc"]

            resource_tags = None
            resource_tags = subnet_configuration["tags"] if "'tags':" in str(
                subnet_configuration) else None

            this_vpc = aws_vpc_id[str(resource_vpc)]

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            subnet = net.Subnet(
                resource_name,
                vpc_id=this_vpc,
                cidr_block=resource_cidr,
                map_public_ip_on_launch=resource_assign_public_ipv4,
                availability_zone=resource_az,
                tags=tags_list

                # FIXME: This needs to be sorted
                # opts = pulumi.ResourceOptions(
                #     parent      = this_vpc,
                #     depends_on  = [this_vpc]
                # )
            )

            subnet_ids_dict.update({subnet._name: subnet.id})
            subnet_cidr_blocks_dict.update({subnet._name: subnet.cidr_block})
            subnet_azs_dict.update({subnet._name: subnet.availability_zone})

            # Exporting each subnet created for future reference
            pulumi.export(subnet._name, subnet.id)
Exemplo n.º 4
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for acm_name, acm_configuration in resource_specs.items():

            # AWS ACM Dynamic Variables
            resource_name = acm_name
            resource_number_of_instances = acm_configuration["domain"]
            resource_namespace = acm_configuration["validation_type"]
Exemplo n.º 5
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()
        aws_subnet_id = Subnets.SubnetId()
        aws_eip_id = ElasticIPs.ElasticIPId()

        for natgw_name, natgw_configuration in resource_specs.items():

            # AWS NAT Gateway Variables
            resource_name = natgw_name
            resource_subnet = natgw_configuration["subnet"]
            resource_eip = natgw_configuration["elastic_ip"]

            resource_tags = None
            resource_tags = natgw_configuration[
                "tags"] if "tags" in natgw_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            this_subnet = aws_subnet_id[str(resource_subnet)]
            this_eip = aws_eip_id[str(resource_eip)]

            aws_natgw = net.NatGateway(resource_name,
                                       subnet_id=this_subnet,
                                       allocation_id=this_eip,
                                       tags=tags_list)

            # Update resource dictionaries
            natgw_ids_dict.update({aws_natgw._name: aws_natgw.id})

            # Export
            pulumi.export(aws_natgw._name, aws_natgw.id)
Exemplo n.º 6
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for vpc_name, vpc_conf in resource_specs.items():

            # AWS VPC Dynamic Variables
            resource_name = vpc_name
            resource_cidr = vpc_conf['cidr']
            resource_dns_resolution = vpc_conf['dns-resolution']
            resource_dns_hostnames = vpc_conf['dns-hostnames']

            resource_tags = None
            resource_tags = vpc_conf["tags"] if "tags" in vpc_conf else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Add mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            # Create resource
            vpc = net.Vpc(resource_name,
                          cidr_block=resource_cidr,
                          enable_dns_support=resource_dns_resolution,
                          enable_dns_hostnames=resource_dns_hostnames,
                          tags=tags_list)

            # Update resource dictionary
            vpc_ids_dict.update({vpc._name: vpc.id})

            # Export the name of each VPC
            pulumi.export(vpc._name, vpc.id)
Exemplo n.º 7
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for s3_bucket_name, s3_bucket_configuration in resource_specs.items():

            # AWS S3 Dynamic Variables
            resource_name = s3_bucket_name

            resource_tags = None
            resource_tags = s3_bucket_configuration[
                "tags"] if "tags" in s3_bucket_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            sse_config = s3_bucket_configuration[
                "serverSideEncryptionConfiguration"] if "serverSideEncryptionConfiguration" in s3_bucket_configuration else None

            # Create S3s
            bucket = s3.Bucket(
                resource_name,
                acl=s3_bucket_configuration["acl"],
                force_destroy=s3_bucket_configuration["force-destroy"],
                tags=tags_list,
                server_side_encryption_configuration=sse_config)

            # Export
            pulumi.export(bucket._name, bucket.id)
Exemplo n.º 8
0
    def __init__(self):

        resource_specs  = ParseYAML(resource_type).getSpecs()
        aws_vpc_id      = VPCs.VPCId()

        for igw_name, igw_configuration in resource_specs.items():

            # AWS Internet Gateway Variables
            resource_name   = igw_name
            resource_vpc    = igw_configuration["vpc"]

            resource_tags   = None
            resource_tags   = igw_configuration["tags"] if "tags" in igw_configuration else None

            this_vpc        = aws_vpc_id[str(resource_vpc)]

            # Getting list of tags from configuration file
            tags_list       = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({"Project/Stack": pulumi.get_project() + "/" + pulumi.get_stack()})
            tags_list.update(resource_mandatory_tags)

            aws_igw     = igw.InternetGateway(

                resource_name,
                vpc_id  = this_vpc,
                tags    = resource_tags

            )

            igw_ids_dict.update({aws_igw._name: aws_igw.id})

            # Export the name of each Internet Gateway
            pulumi.export(aws_igw._name, aws_igw.id)
Exemplo n.º 9
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for keypair_name, keypair_configuration in resource_specs.items():

            # AWS KeyPair Dynamic Variables
            resource_name = keypair_name
            resource_public_key = keypair_configuration['public_key']

            resource_tags = None
            resource_tags = keypair_configuration[
                "tags"] if "tags" in keypair_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            # Create resource
            keypair = am.KeyPair(resource_name,
                                 public_key=resource_public_key,
                                 tags=tags_list)

            # Update resource dictionary
            keypair_ids_dict.update({keypair._name: keypair.id})

            # Exporting each KeyPair ID created for future reference
            pulumi.export(keypair._name, keypair.id)
Exemplo n.º 10
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for lambda_name, config in resource_specs.items():
            config = config if config else {}

            resource_name = lambda_name
            resource_tags = config.get("tags")
            resource_env = config.get("environment")

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Generating ENV vars
            env_list = {}
            if resource_env is not None:
                for each_env_name, each_env_value in resource_env.items():
                    env_list.update({each_env_name: each_env_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            lambda_function = lambda_.Function(
                lambda_name,
                environment=lambda_.FunctionEnvironmentArgs(
                    variables=env_list),
                handler=config.get("handler"),
                s3_bucket=config.get("s3_bucket"),
                s3_key=config.get("s3_key"),
                s3_object_version=config.get("s3_object_version"),
                memory_size=config.get("memory_size"),
                publish=config.get("publish"),
                reserved_concurrent_executions=config.get(
                    "reserved_concurrent_executions"),
                role=IAM.RoleARN()[config.get("role")],
                runtime=config.get("runtime"),
                timeout=config.get("timeout"),
                tags=tags_list)

            # Export
            pulumi.export(lambda_function._name, lambda_function.id)

            # Event source mappings
            for mapping_name, mapping_config in config.get(
                    "event_source_mapping").items():

                event_source = mapping_config["event_source"]
                assert event_source.get(
                    "type"
                ) == "sqs", "Just sqs is currently supported as event source mapping. You're welcome to implement more."

                source_arn = SQS.ByName()[event_source["name"]].arn

                mapping = lambda_.EventSourceMapping(
                    mapping_name,
                    event_source_arn=source_arn,
                    function_name=lambda_function.arn,
                    batch_size=mapping_config.get("batch_size"))
                pulumi.export(mapping_name, mapping.id)

            lambdas_by_name[lambda_name] = lambda_function
Exemplo n.º 11
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()
        aws_vpc_id = VPCs.VPCId()

        for sg_name, sg_configuration in resource_specs.items():

            # AWS Security Groups Dynamic Variables
            resource_name = sg_name
            resource_description = sg_configuration["description"]
            resource_vpc = sg_configuration["vpc"]
            resource_ingress_rules = sg_configuration["ingress"]
            resource_egress_rules = sg_configuration["egress"]

            resource_tags = None
            resource_tags = sg_configuration[
                "tags"] if "tags" in sg_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            this_vpc = aws_vpc_id[str(resource_vpc)]

            # Empty dictionaries that'll be populated with rules
            # coming from each individual security group,
            # being ingress or egress
            ingress_rules_list = {}
            egress_rules_list = {}

            # Gathering all ingress rules and return the results
            # to the right dictionary defined above
            for each_ingress_rule in resource_ingress_rules.items():
                for each_ingress_rule_key, each_ingress_rule_value in [
                        each_ingress_rule
                ]:
                    ingress_rules_list.update(
                        {each_ingress_rule_key: each_ingress_rule_value})
            combined_ingress_rules = list(ingress_rules_list.values())

            # Gathering all egress rules and return the results
            # to the right dictionary defined above
            for each_egress_rule in resource_egress_rules.items():
                for each_egress_rule_key, each_egress_rule_value in [
                        each_egress_rule
                ]:
                    egress_rules_list.update(
                        {each_egress_rule_key: each_egress_rule_value})
            combined_egress_rules = list(egress_rules_list.values())

            # Create Security Group
            security_group = net.SecurityGroup(
                resource_name,
                description=resource_description,
                name=resource_name,
                vpc_id=this_vpc,
                ingress=combined_ingress_rules,
                egress=combined_egress_rules,
                tags=tags_list)

            # Update resource dictionary
            sg_ids_dict.update({security_group._name: security_group.id})

            # Exporting each security group created for future reference
            pulumi.export(security_group._name, security_group.id)
Exemplo n.º 12
0
    def __init__(self):

        resource_specs  = ParseYAML(resource_type).getSpecs()
        aws_subnet_id   = Subnets.SubnetId()
        aws_sg_id       = SecurityGroups.SecurityGroupId()
        # aws_keypair_id  = KeyPairs.KeyPairId()

        for efs_name, efs_configuration in resource_specs.items():

            # Resource Name
            resource_name                           = efs_name

            # File System Configuration and its Default values
            resource_file_system                    = efs_configuration["file-system"]              if "file-system"        in efs_configuration        else None
            resource_file_system_encryption         = resource_file_system["encrypted"]             if "encrypted"          in resource_file_system     else True
            resource_file_system_performance_mode   = resource_file_system["performance_mode"]      if "performance_mode"   in resource_file_system     else "generalPurpose"

            # Target Configuration and its Default values
            resource_target                         = efs_configuration["target"]                   if "target"             in efs_configuration        else None
            resource_target_vpc                     = resource_target["vpc"]                        if "vpc"                in resource_target          else None
            resource_target_subnets                 = resource_target["subnets"]                    if "subnets"            in resource_target          else None
            resource_target_security_groups         = resource_target["security_groups"]            if "security_groups"    in resource_target          else None

            # Resource Tags and its Default values
            resource_tags                           = None
            resource_tags                           = efs_configuration["tags"]                     if "tags"               in efs_configuration        else None

            # Get the list of subnets from the configuration file
            # subnets_list = []
            # for each_subnet_found in resource_target_subnets:
            #     this_subnet = aws_subnet_id[str(each_subnet_found)]
            #     subnets_list.append(this_subnet)

            # Getting the list of security groups found
            security_groups_list = []
            for each_security_group_found in resource_target_security_groups:
                this_security_group = aws_sg_id[str(each_security_group_found)]
                security_groups_list.append(this_security_group)

            # Getting list of tags from configuration file
            tags_list                           = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({"Project/Stack": pulumi.get_project() + "/" + pulumi.get_stack()})
            tags_list.update(resource_mandatory_tags)

            #
            # Create EFS Resource
            #

            # EFS File System
            efs_file_system = efs.FileSystem(
                resource_name,
                encrypted           = resource_file_system_encryption,
                performance_mode    = resource_file_system_performance_mode,
                tags                = tags_list,
            )

            # Return a list of all EFSs created
            efs_ids_dict.update({efs_file_system._name: efs_file_system.id})

            # Create Target(s) based on the number of
            # Subnets found in the configuration file
            target_index = 0

            for each_subnet in resource_target_subnets:

                target_index = target_index + 1

                this_subnet = aws_subnet_id[str(each_subnet)]
                target_name = (resource_name+str("-target-" + str(target_index).zfill(2)))

                efs_target = efs.MountTarget(
                    target_name,
                    file_system_id          = efs_file_system.id,
                    subnet_id               = this_subnet,
                    security_groups         = security_groups_list
                )
Exemplo n.º 13
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()
        aws_vpc_id = VPCs.VPCId()
        aws_igw_id = InternetGateways.InternetGatewayId()
        aws_natgw_id = NATGateways.NATGatewayId()
        aws_subnet_id = Subnets.SubnetId()

        for rtb_name, rtb_configuration in resource_specs.items():

            # AWS Route Table Variables
            resource_name = rtb_name
            resource_vpc = rtb_configuration["vpc"]

            resource_tags = None
            resource_tags = rtb_configuration[
                "tags"] if "tags" in rtb_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            this_vpc = aws_vpc_id[str(resource_vpc)]

            #
            # Create Route Table
            #
            aws_rtb = rtb.RouteTable(resource_name,
                                     vpc_id=this_vpc,
                                     tags=tags_list)

            rtb_ids_dict.update({aws_rtb._name: aws_rtb.id})

            # Export the name of each Route Table
            pulumi.export(aws_rtb._name, aws_rtb.id)

            #
            # Route Table Routes
            #

            # Routes list
            routes_list = []

            for each_route_entry, each_route_entry_configuration in rtb_configuration[
                    "routes"].items():

                # NAT Gateways
                if each_route_entry_configuration[
                        "target_type"] == "nat_gateway":

                    this_natgw = aws_natgw_id[str(
                        each_route_entry_configuration["target"])]
                    routes_list.append(
                        rtb.Route(
                            (each_route_entry + "-route"),
                            route_table_id=aws_rtb.id,
                            destination_cidr_block=
                            each_route_entry_configuration["destination"],
                            nat_gateway_id=this_natgw))

                # Internet Gateways
                elif each_route_entry_configuration[
                        "target_type"] == "internet_gateway":

                    this_igw = aws_igw_id[str(
                        each_route_entry_configuration["target"])]
                    routes_list.append(
                        rtb.Route(
                            (each_route_entry + "-route"),
                            route_table_id=aws_rtb.id,
                            destination_cidr_block=
                            each_route_entry_configuration["destination"],
                            gateway_id=this_igw), )

                else:

                    print("ERROR | Unsupported 'target_type' found")

                for each_route_type in routes_list:

                    # print(each_route_entry)

                    rtb_route = (
                        each_route_type
                        # opts = pulumi.ResourceOptions(depends_on=[aws_rtb[resource_name]])
                    )

            #
            # Subnet Associations
            #

            # Checking if route-table: key is present
            resource_associated_subnet = None
            resource_associated_subnet = rtb_configuration[
                "associated_subnets"] if "associated_subnets" in rtb_configuration else None

            # If the key is present then we'll get the value
            # and we'll invoke the association
            if resource_associated_subnet is not None:

                subnets_count = 0

                for each_associated_subnet in resource_associated_subnet:

                    subnets_count = subnets_count + 1

                    this_subnet = aws_subnet_id[str(each_associated_subnet)]

                    route_table_association = rtb.RouteTableAssociation(
                        (resource_name + "-rtb-as-" +
                         str(subnets_count).zfill(2)),
                        subnet_id=this_subnet,
                        route_table_id=aws_rtb.id)

                    # Export the name of each Route Table Association
                    pulumi.export(route_table_association._name,
                                  route_table_association.id)
Exemplo n.º 14
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for sqs_queue_name, sqs_queue_configuration in resource_specs.items():
            sqs_queue_configuration = sqs_queue_configuration if sqs_queue_configuration else {}

            resource_name = sqs_queue_name

            resource_tags = None
            resource_tags = sqs_queue_configuration[
                "tags"] if "tags" in sqs_queue_configuration else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            fifo_queue = sqs_queue_configuration[
                "fifo_queue"] if "fifo_queue" in sqs_queue_configuration else None
            content_based_deduplication = sqs_queue_configuration[
                "content_based_deduplication"] if "content_based_deduplication" in sqs_queue_configuration else None
            delay_seconds = sqs_queue_configuration[
                "delay_seconds"] if "delay_seconds" in sqs_queue_configuration else None
            max_message_size = sqs_queue_configuration[
                "max_message_size_bytes"] if "max_message_size_bytes" in sqs_queue_configuration else None
            message_retention_seconds = sqs_queue_configuration[
                "message_retention_seconds"] if "message_retention_seconds" in sqs_queue_configuration else None
            receive_wait_time_seconds = sqs_queue_configuration[
                "receive_wait_time_seconds"] if "receive_wait_time_seconds" in sqs_queue_configuration else None
            visibility_timeout_seconds = sqs_queue_configuration[
                "visibility_timeout_seconds"] if "visibility_timeout_seconds" in sqs_queue_configuration else None
            source_sns_topic_arn = sqs_queue_configuration[
                "source_sns_topic_arn"] if "source_sns_topic_arn" in sqs_queue_configuration else None

            # Create SQSs
            queue = sqs.Queue(
                resource_name,
                fifo_queue=fifo_queue,
                content_based_deduplication=content_based_deduplication,
                delay_seconds=delay_seconds,
                max_message_size=max_message_size,
                message_retention_seconds=message_retention_seconds,
                receive_wait_time_seconds=receive_wait_time_seconds,
                visibility_timeout_seconds=visibility_timeout_seconds,
                tags=tags_list)

            sqs_queue_by_name[resource_name] = queue

            # Export
            pulumi.export(queue._name, queue.id)

            if source_sns_topic_arn is not None:
                arn = sqs_queue_by_name[resource_name].arn
                sqs_policy = iam.get_policy_document(
                    policy_id="__default_policy_ID",
                    statements=[
                        iam.GetPolicyDocumentStatementArgs(
                            actions=["sqs:SendMessage"],
                            resources=[arn],
                            effect="Allow",
                            principals=[
                                iam.GetPolicyDocumentStatementPrincipalArgs(
                                    type="Service",
                                    identifiers=["sns.amazonaws.com"])
                            ],
                            conditions=[
                                iam.GetPolicyDocumentStatementConditionArgs(
                                    test="ArnEquals",
                                    variable="aws:SourceArn",
                                    values=source_sns_topic_arn,
                                )
                            ],
                        )
                    ])

                policy = sqs.QueuePolicy(resource_name,
                                         queue_url=queue.id,
                                         policy=sqs_policy.json)

                pulumi.export(resource_name + "-policy", policy.policy)
Exemplo n.º 15
0
    def __init__(self):

        resource_specs = ParseYAML(resource_type).getSpecs()

        for cloudfront_distribution_name, cloudfront_distribution_configuration in resource_specs.items(
        ):
            cloudfront_distribution_configuration = cloudfront_distribution_configuration if cloudfront_distribution_configuration else {}

            resource_name = cloudfront_distribution_name

            resource_tags = None
            resource_tags = cloudfront_distribution_name[
                "tags"] if "tags" in cloudfront_distribution_name else None

            # Getting list of tags from configuration file
            tags_list = {}
            if resource_tags is not None:
                for each_tag_name, each_tag_value in resource_tags.items():
                    tags_list.update({each_tag_name: each_tag_value})

            # Adding mandatory tags
            tags_list.update({"Name": resource_name})
            tags_list.update({
                "Project/Stack":
                pulumi.get_project() + "/" + pulumi.get_stack()
            })
            tags_list.update(resource_mandatory_tags)

            aliases = cloudfront_distribution_configuration[
                "aliases"] if "aliases" in cloudfront_distribution_configuration else None
            default_cache_behavior = cloudfront_distribution_configuration[
                "default_cache_behavior"] if "default_cache_behavior" in cloudfront_distribution_configuration else None
            enabled = cloudfront_distribution_configuration[
                "enabled"] if "enabled" in cloudfront_distribution_configuration else None
            ordered_cache_behaviors = cloudfront_distribution_configuration[
                "ordered_cache_behaviors"] if "ordered_cache_behaviors" in cloudfront_distribution_configuration else None
            origins = cloudfront_distribution_configuration[
                "origins"] if "origins" in cloudfront_distribution_configuration else None
            price_class = cloudfront_distribution_configuration[
                "price_class"] if "price_class" in cloudfront_distribution_configuration else None
            viewer_certificate = cloudfront_distribution_configuration[
                "viewer_certificate"] if "viewer_certificate" in cloudfront_distribution_configuration else None
            custom_error_responses = cloudfront_distribution_configuration[
                "custom_error_responses"] if "custom_error_responses" in cloudfront_distribution_configuration else None
            restrictions = cloudfront_distribution_configuration[
                "restrictions"] if "restrictions" in cloudfront_distribution_configuration else {
                    "geoRestriction": {
                        "restrictionType": "none"
                    }
                }

            # Create Cloudfront Distribution
            distribution = cloudfront.Distribution(
                resource_name,
                aliases=aliases,
                default_cache_behavior=default_cache_behavior,
                enabled=enabled,
                ordered_cache_behaviors=ordered_cache_behaviors,
                origins=origins,
                price_class=price_class,
                viewer_certificate=viewer_certificate,
                tags=tags_list,
                restrictions=restrictions,
                default_root_object="index.html",
                custom_error_responses=custom_error_responses,
                is_ipv6_enabled=True)

            # Export
            pulumi.export(distribution._name, distribution.id)