Пример #1
0
    def __init__(self,
                 name: str,
                 args: ServerArgs,
                 opts: ResourceOptions = None):

        super().__init__("my:modules:Server", name, {}, opts)

        firewall = compute.Firewall(name,
                                    network=args.subnet.network,
                                    allows=[
                                        compute.FirewallAllowArgs(
                                            protocol="tcp",
                                            ports=args.ports,
                                        )
                                    ],
                                    target_tags=[args.service_name],
                                    opts=ResourceOptions(parent=self))

        addr = compute.address.Address(name, opts=ResourceOptions(parent=self))

        self.instance = compute.Instance(
            name,
            machine_type=args.machine_type,
            boot_disk=compute.InstanceBootDiskArgs(
                initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
                    image="ubuntu-os-cloud/ubuntu-1804-lts")),
            network_interfaces=[
                compute.InstanceNetworkInterfaceArgs(
                    subnetwork=args.subnet.self_link,
                    access_configs=[
                        compute.InstanceNetworkInterfaceAccessConfigArgs(
                            nat_ip=addr.address)
                    ])
            ],
            tags=[args.service_name],
            metadata=args.metadata,
            metadata_startup_script=args.metadata_startup_script,
            opts=ResourceOptions(parent=self))

        self.register_outputs({})
Пример #2
0
import pulumi
from pulumi_gcp import compute

#
# network and firewall for both virtual machines
#
network = compute.Network("poc")

firewall = compute.Firewall("poc",
                            network=network.self_link,
                            allows=[
                                compute.FirewallAllowArgs(protocol="tcp",
                                                          ports=["22"]),
                                compute.FirewallAllowArgs(protocol="tcp",
                                                          ports=["80"]),
                            ])

#
# virtual machine running nginx via a [startup script](https://cloud.google.com/compute/docs/startupscript)
#
script = """#!/bin/bash
apt -y update
apt -y install nginx
"""

instance_addr = compute.address.Address("poc")
instance = compute.Instance(
    "poc",
    machine_type="f1-micro",
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
Пример #3
0
import pulumi
from pulumi import ResourceOptions
from pulumi_gcp import compute

compute_network = compute.Network(
    "network",
    auto_create_subnetworks=True,
)

compute_firewall = compute.Firewall(
    "firewall",
    network=compute_network.self_link,
    allows=[compute.FirewallAllowArgs(
        protocol="tcp",
        ports=["22", "80"],
    )]
)

# A simple bash script that will run when the webserver is initalized
startup_script = """#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &"""

instance_addr = compute.address.Address("address")
compute_instance = compute.Instance(
    "instance",
    machine_type="f1-micro",
    metadata_startup_script=startup_script,
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
            image="debian-cloud/debian-9-stretch-v20181210"
Пример #4
0
region_zone = config.zone
project_name = config.project

compute_network = compute.Network(
    "network",
    project=project_name,
    auto_create_subnetworks=True,
)

compute_firewall = compute.Firewall(
    "firewall",
    project=project_name,
    network=compute_network.self_link,
    allows=[
        compute.FirewallAllowArgs(protocol="icmp"),
        compute.FirewallAllowArgs(
            protocol="tcp",
            ports=["22", "80"],
        ),
    ],
)

compute_instance = compute.Instance(
    "instance",
    project=project_name,
    machine_type="f1-micro",
    zone=region_zone,
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
            image="debian-cloud/debian-9", ), ),