Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pulumi/templates into blampe/dock…
Browse files Browse the repository at this point in the history
…er-build
  • Loading branch information
blampe committed Aug 21, 2024
2 parents eb4ad53 + d1c1ed3 commit b7d5636
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ jobs:
id-token: write

steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/[email protected]
with:
tool-cache: false
swap-storage: false

- name: Install ${{ matrix.java-version }} (${{ matrix.java-distribution }})
uses: actions/setup-java@v4
with:
Expand Down
99 changes: 46 additions & 53 deletions vm-gcp-python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,36 @@
# Create a new network for the virtual machine.
network = gcp.compute.Network(
"network",
gcp.compute.NetworkArgs(
auto_create_subnetworks=False,
),
auto_create_subnetworks=False,
)

# Create a subnet on the network.
subnet = gcp.compute.Subnetwork(
"subnet",
gcp.compute.SubnetworkArgs(
ip_cidr_range="10.0.1.0/24",
network=network.id,
),
ip_cidr_range="10.0.1.0/24",
network=network.id,
)

# Create a firewall allowing inbound access over ports 80 (for HTTP) and 22 (for SSH).
firewall = gcp.compute.Firewall(
"firewall",
gcp.compute.FirewallArgs(
network=network.self_link,
allows=[
gcp.compute.FirewallAllowArgs(
protocol="tcp",
ports=[
"22",
service_port,
],
),
],
direction="INGRESS",
source_ranges=[
"0.0.0.0/0",
],
target_tags=[
instance_tag,
],
),
network=network.self_link,
allows=[
{
"protocol": "tcp",
"ports": [
"22",
service_port,
],
},
],
direction="INGRESS",
source_ranges=[
"0.0.0.0/0",
],
target_tags=[
instance_tag,
],
)

# Define a script to be run when the VM starts up.
Expand All @@ -68,38 +62,37 @@
# Create the virtual machine.
instance = gcp.compute.Instance(
"instance",
gcp.compute.InstanceArgs(
machine_type=machine_type,
boot_disk=gcp.compute.InstanceBootDiskArgs(
initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
image=os_image,
),
),
network_interfaces=[
gcp.compute.InstanceNetworkInterfaceArgs(
network=network.id,
subnetwork=subnet.id,
access_configs=[
{},
],
),
],
service_account=gcp.compute.InstanceServiceAccountArgs(
scopes=[
"https://www.googleapis.com/auth/cloud-platform",
machine_type=machine_type,
boot_disk={
"initialize_params": {
"image": os_image,
},
},
network_interfaces=[
{
"network": network.id,
"subnetwork": subnet.id,
"access_configs": [
{},
],
),
allow_stopping_for_update=True,
metadata_startup_script=metadata_startup_script,
tags=[
instance_tag,
},
],
service_account={
"scopes": [
"https://www.googleapis.com/auth/cloud-platform",
],
),
pulumi.ResourceOptions(depends_on=firewall),
},
allow_stopping_for_update=True,
metadata_startup_script=metadata_startup_script,
tags=[
instance_tag,
],
opts=pulumi.ResourceOptions(depends_on=firewall),
)

instance_ip = instance.network_interfaces.apply(
lambda interfaces: interfaces[0].access_configs[0].nat_ip
lambda interfaces: interfaces[0].access_configs
and interfaces[0].access_configs[0].nat_ip
)

# Export the instance's name, public IP address, and HTTP URL.
Expand Down

0 comments on commit b7d5636

Please sign in to comment.