|
| 1 | +"""An OpenStack Python Pulumi program""" |
| 2 | + |
| 3 | +import pulumi |
| 4 | +import pulumi_openstack as openstack |
| 5 | + |
| 6 | + |
| 7 | +fedora_image = openstack.images.Image( |
| 8 | + "fedora", |
| 9 | + name="fedora", |
| 10 | + container_format="bare", |
| 11 | + disk_format="qcow2", |
| 12 | + image_source_url="https://ftp.plusline.net/fedora/linux/releases/34/Cloud/x86_64/images/Fedora-Cloud-Base-34-1.2.x86_64.qcow2", |
| 13 | + visibility="public", |
| 14 | +) |
| 15 | + |
| 16 | +default_keypair = openstack.compute.keypair.Keypair( |
| 17 | + "default", |
| 18 | + name="default", |
| 19 | + public_key="ssh-ed25519 <public key>", |
| 20 | +) |
| 21 | + |
| 22 | +secgroup_default = openstack.networking.get_sec_group(name="default") |
| 23 | + |
| 24 | +secgroup_rule_ssh = openstack.networking.SecGroupRule( |
| 25 | + "secgroupRule1", |
| 26 | + direction="ingress", |
| 27 | + ethertype="IPv4", |
| 28 | + port_range_max=22, |
| 29 | + port_range_min=22, |
| 30 | + protocol="tcp", |
| 31 | + remote_ip_prefix="0.0.0.0/0", |
| 32 | + description="Allow ssh", |
| 33 | + security_group_id=secgroup_default.id, |
| 34 | +) |
| 35 | + |
| 36 | +secgroup_rule_python_server = openstack.networking.SecGroupRule( |
| 37 | + "secgroupRule2", |
| 38 | + direction="ingress", |
| 39 | + ethertype="IPv4", |
| 40 | + port_range_max=8000, |
| 41 | + port_range_min=8000, |
| 42 | + protocol="tcp", |
| 43 | + remote_ip_prefix="0.0.0.0/0", |
| 44 | + description="Allow python http server", |
| 45 | + security_group_id=secgroup_default.id, |
| 46 | +) |
| 47 | + |
| 48 | +secgroup_rule_icmp = openstack.networking.SecGroupRule( |
| 49 | + "secgroupRule3", |
| 50 | + direction="ingress", |
| 51 | + ethertype="IPv4", |
| 52 | + protocol="icmp", |
| 53 | + remote_ip_prefix="0.0.0.0/0", |
| 54 | + description="Allow ping", |
| 55 | + security_group_id=secgroup_default.id, |
| 56 | +) |
| 57 | + |
| 58 | +network_public = openstack.networking.get_network(name="public") |
| 59 | + |
| 60 | +user_data = """ |
| 61 | +#!/bin/bash |
| 62 | +echo "Hello, World!" > index.html |
| 63 | +nohup python3 -m http.server & |
| 64 | +""" |
| 65 | + |
| 66 | +fedora = openstack.compute.Instance( |
| 67 | + "test_fedora", |
| 68 | + name="test_fedora", |
| 69 | + flavor_name="m1.small", |
| 70 | + image_id=fedora_image.id, |
| 71 | + key_pair=default_keypair.id, |
| 72 | + security_groups=["default"], |
| 73 | + networks=[ |
| 74 | + openstack.compute.InstanceNetworkArgs(uuid=network_public.id), |
| 75 | + ], |
| 76 | + user_data=user_data, |
| 77 | +) |
| 78 | + |
| 79 | +# Export the IP of the instance |
| 80 | +pulumi.export("instance_ip", fedora.access_ip_v4) |
0 commit comments