Пример #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
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(
            image="ubuntu-os-cloud/ubuntu-1804-bionic-v20200414"), ),
    network_interfaces=[
        compute.InstanceNetworkInterfaceArgs(
            network=network.id,
            access_configs=[
                compute.InstanceNetworkInterfaceAccessConfigArgs(
                    nat_ip=instance_addr.address)
            ])
    ],
    metadata_startup_script=script,
)

pulumi.export("instance_name", instance.name)
pulumi.export("instance_external_ip", instance_addr.address)

#
# virtual machine with Google's [Container-Optimized OS](https://cloud.google.com/container-optimized-os/docs) running nginx as a Docker container
#
container_instance_addr = compute.address.Address("poc-container-instance")
container_instance_metadata_script = """
spec:
Пример #3
0
# 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"
        )
    ),
    network_interfaces=[compute.InstanceNetworkInterfaceArgs(
            network=compute_network.id,
            access_configs=[compute.InstanceNetworkInterfaceAccessConfigArgs(
                nat_ip=instance_addr.address
            )],
    )],
    service_account=compute.InstanceServiceAccountArgs(
        scopes=["https://www.googleapis.com/auth/cloud-platform"],
    ),
    opts=ResourceOptions(depends_on=[compute_firewall]),
)

pulumi.export("instanceName", compute_instance.name)
pulumi.export("instanceIP", instance_addr.address)
Пример #4
0
#setup the policy server and init it with the script
instance_srvaddr=compute.Address("addr-4-demoserver",network_tier="STANDARD")
instance_srv=compute.Instance(
    "instance-4-policyserver",
    machine_type="e2-small",
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
            image="ubuntu-os-cloud/ubuntu-1804-bionic-v20200414"
        ),
    ),
    network_interfaces=[
        compute.InstanceNetworkInterfaceArgs(
            network=network.id,
            access_configs=[compute.InstanceNetworkInterfaceAccessConfigArgs(
                nat_ip=instance_srvaddr.address,
                network_tier="STANDARD"
            )]
        )
    ],
    metadata_startup_script=init_scripts.init_server,
    opts=ResourceOptions(delete_before_replace=True),
    zone="asia-east1-a",
)

#setup the client instance and setup the key
instance_clientaddr=compute.Address("addr-4-democlient",network_tier="STANDARD")
instance_client=compute.Instance(
    "instance-4-policyclient",
    machine_type="e2-small",
    boot_disk=compute.InstanceBootDiskArgs(
Пример #5
0
)

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", ), ),
    network_interfaces=[
        compute.InstanceNetworkInterfaceArgs(
            network=compute_firewall.network, )
    ],
    service_account=compute.InstanceServiceAccountArgs(
        scopes=["https://www.googleapis.com/auth/cloud-platform"], ),
)