예제 #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
                            ])

#
# 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(
            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)

#
예제 #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)
예제 #4
0
sudo apt-get -y install snap snapd
source /etc/environment
sudo snap install docker --classic
source /etc/environment
sleep 60; sudo docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /root/docker/rancher:/var/lib/rancher rancher/rancher:stable
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove
"""

instance_addr = compute.address.Address("template-rancher")
instance = compute.Instance(
    "template-rancher",
    name="template-rancher",
    machine_type="e2-medium",
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
            image="ubuntu-os-cloud/ubuntu-2004-lts"), ),
    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)
# Create firewall rules to VPC network
compute_firewall = compute.Firewall(
    "firewall",
    network=compute_network.name,
    allows=[compute.FirewallAllowArgs(protocol="tcp", ports=["22", "80"])])

# Create IP address
instance_addr = compute.Address("demo-instance-address", region="asia-east1")

# Create Instance
compute_instance = compute.Instance(
    "demo-instance",
    zone="asia-east1-a",
    boot_disk=compute.InstanceBootDiskArgs(
        initialize_params=compute.InstanceBootDiskInitializeParamsArgs(
            image="ubuntu-1804-bionic-v20210211")),
    machine_type="e2-medium",
    network_interfaces=[
        compute.InstanceNetworkInterfaceArgs(
            network=compute_network.name,
            access_configs=[
                compute.InstanceNetworkInterfaceAccessConfigArgs(
                    nat_ip=instance_addr.address)
            ],
        )
    ],
    opts=ResourceOptions(depends_on=[compute_firewall]),
    metadata_startup_script=script,
    metadata={"ssh-keys": sshkey},
    tags=["demo", "dev"])
예제 #6
0
        compute.FirewallAllowArgs(
            protocol="tcp",
            ports=["80"]
        )
    ]
)


#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",
)
예제 #7
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"], ),
)