Hey! I am new to Pulumi and trying to create new i...
# python
c
Hey! I am new to Pulumi and trying to create new infra using Python. This is my folder structure
Copy code
pulumi new azure-python --force
 pulumi up
My current working directory has these all files:
Copy code
Pulumi$ ls -larth
total 8.0K
drwxrwxrwx 1 aagashe aagashe  512 May  8 20:30 ..
-rwxrwxrwx 1 aagashe aagashe 1.8K May  8 20:31 create-infra.py
drwxrwxrwx 1 aagashe aagashe  512 May  8 20:39 venv
-rwxrwxrwx 1 aagashe aagashe   41 May  8 21:02 Pulumi.dev.yaml
-rwxrwxrwx 1 aagashe aagashe   41 May  8 22:55 Pulumi.dev2.yaml
-rwxrwxrwx 1 aagashe aagashe   12 May  9 09:46 .gitignore
-rwxrwxrwx 1 aagashe aagashe   55 May  9 09:46 requirements.txt
-rwxrwxrwx 1 aagashe aagashe  855 May  9 09:46 __main__.py
-rwxrwxrwx 1 aagashe aagashe  204 May  9 09:46 Pulumi.yaml
-rwxrwxrwx 1 aagashe aagashe   47 May  9 09:47 Pulumi.dev11.yaml
drwxrwxrwx 1 aagashe aagashe  512 May  9 09:50 .
drwxrwxrwx 1 aagashe aagashe  512 May  9 09:50 __pycache__
However the infra created is one RG with a storage account. However, Python files does describe to create rg, vnet, pub ip, Vm etc
Copy code
import pulumi
from pulumi_azure import core, compute, network

# Create an Azure Resource Group
resource_group = core.ResourceGroup('myresourcegroup')

# Create a Virtual Network
vnet = network.VirtualNetwork('myvnet',
    resource_group_name=resource_group.name,
    address_spaces=['10.0.0.0/16'],
    subnets=[{
        'name': 'default',
        'addressPrefix': '10.0.1.0/24',
    }])

# Create a Public IP
public_ip = network.PublicIp('mypublicip',
    resource_group_name=resource_group.name,
    allocation_method='Dynamic')

# Create a Network Interface
network_iface = network.NetworkInterface('mynic',
    resource_group_name=resource_group.name,
    ip_configurations=[{
        'name': 'webserveripcfg',
        'subnet_id': vnet.subnets.apply(lambda subnets: subnets[0]['id']),
        'private_ip_address_allocation': 'Dynamic',
        'public_ip_address_id': public_ip.id,
    }])

# Create a Virtual Machine
vm = compute.VirtualMachine('myvm',
    resource_group_name=resource_group.name,
    network_interface_ids=[network_iface.id],
    vm_size='Standard_DS1_v2',
    delete_data_disks_on_termination=True,
    delete_os_disk_on_termination=True,
    os_profile={
        'computer_name': 'hostname',
        'admin_username': 'testadmin',
        'admin_password': 'Password1234!',
    },
    os_profile_linux_config={
        'disable_password_authentication': False,
    },
    storage_os_disk={
        'create_option': 'FromImage',
        'name': 'myosdisk',
    },
    storage_image_reference={
        'publisher': 'Canonical',
        'offer': 'UbuntuServer',
        'sku': '16.04-LTS',
        'version': 'latest',
    })

# Export the connection string for the storage account
pulumi.export('public_ip_address', public_ip.ip_address)