-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
50 lines (45 loc) · 1.48 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
TcheLinux 2021 - Pulumi - Modern Infrastructure as Code
"""
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"
)
),
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)