{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "adminPassword": {
            "type": "SecureString",
            "defaultValue": "JSystems!",
			"metadata": {
				"description": "Hasło do konta jsystems, domyślnie: JSystems!"
			}
        }
    },
    "variables": {
        "nsgId": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', 'szkolenie-nsg')]",
        "vnetName": "szkolenie-vnet",
        "vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', variables('vnetName'))]",
        "subnetRef": "[concat(variables('vnetId'), '/subnets/', 'subnet1')]"
    },
    "resources": [
        {
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2022-11-01",
            "name": "pg1-nic",
            "location": "polandcentral",
            "dependsOn": [
                "[concat('Microsoft.Network/networkSecurityGroups/', 'szkolenie-nsg')]",
                "[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]",
                "[concat('Microsoft.Network/publicIpAddresses/', 'pg1-ip')]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Static",
                            "privateIPAddress": "10.0.0.10",
                            "publicIpAddress": {
                                "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', 'pg1-ip')]",
                                "properties": {
                                    "deleteOption": "Delete"
                                }
                            }
                        }
                    }
                ],
                "networkSecurityGroup": {
                    "id": "[variables('nsgId')]"
                }
            }
        },
        {
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2022-11-01",
            "name": "pg2-nic",
            "location": "polandcentral",
            "dependsOn": [
                "[concat('Microsoft.Network/networkSecurityGroups/', 'szkolenie-nsg')]",
                "[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]",
                "[concat('Microsoft.Network/publicIpAddresses/', 'pg2-ip')]"
            ],
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Static",
                            "privateIPAddress": "10.0.0.20",
                            "publicIpAddress": {
                                "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', 'pg2-ip')]",
                                "properties": {
                                    "deleteOption": "Delete"
                                }
                            }
                        }
                    }
                ],
                "networkSecurityGroup": {
                    "id": "[variables('nsgId')]"
                }
            }
        },
        {
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2020-05-01",
            "name": "szkolenie-nsg",
            "location": "polandcentral",
            "properties": {
                "securityRules": [
                    {
                        "name": "SSH",
                        "properties": {
                            "priority": 100,
                            "protocol": "TCP",
                            "access": "Allow",
                            "direction": "Inbound",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*",
                            "destinationPortRange": "22"
                        }
                    },
                    {
                        "name": "PostgreSQL",
                        "properties": {
                            "priority": 110,
                            "protocol": "TCP",
                            "access": "Allow",
                            "direction": "Inbound",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*",
                            "destinationPortRange": "5432"
                        }
                    },
                    {
                        "name": "ICMP",
                        "properties": {
                            "priority": 130,
                            "protocol": "ICMP",
                            "access": "Allow",
                            "direction": "Inbound",
                            "sourceAddressPrefix": "*",
                            "sourcePortRange": "*",
                            "destinationAddressPrefix": "*",
                            "destinationPortRange": "*"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2023-05-01",
            "name": "[variables('vnetName')]",
            "location": "polandcentral",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "10.0.0.0/24"
                    ]
                },
                "subnets": [
                    {
                        "name": "subnet1",
                        "properties": {
                            "addressPrefix": "10.0.0.0/24"
                        }
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Network/publicIpAddresses",
            "apiVersion": "2020-08-01",
            "name": "pg1-ip",
            "location": "polandcentral",
            "sku": {
                "name": "Standard"
            },
            "zones": [
                "1"
            ],
            "properties": {
                "publicIpAllocationMethod": "Static"
            }
        },
        {
            "type": "Microsoft.Network/publicIpAddresses",
            "apiVersion": "2020-08-01",
            "name": "pg2-ip",
            "location": "polandcentral",
            "sku": {
                "name": "Standard"
            },
            "zones": [
                "1"
            ],
            "properties": {
                "publicIpAllocationMethod": "Static"
            }
        },
        {
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2024-03-01",
            "name": "pg1",
            "location": "polandcentral",
            "dependsOn": [
                "[concat('Microsoft.Network/networkInterfaces/', 'pg1-nic')]"
            ],
            "properties": {
                "hardwareProfile": {
                    "vmSize": "Standard_B1ms"
                },
                "storageProfile": {
                    "osDisk": {
                        "createOption": "fromImage",
                        "managedDisk": {
                            "storageAccountType": "StandardSSD_LRS"
                        },
                        "diskSizeGB": 32,
                        "deleteOption": "Delete"
                    },
                    "imageReference": {
                        "publisher": "canonical",
                        "offer": "0001-com-ubuntu-server-jammy",
                        "sku": "22_04-lts-gen2",
                        "version": "latest"
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', 'pg1-nic')]",
                            "properties": {
                                "deleteOption": "Delete"
                            }
                        }
                    ]
                },
                "additionalCapabilities": {
                    "hibernationEnabled": false
                },
                "osProfile": {
                    "computerName": "pg1",
                    "adminUsername": "jsystems",
                    "adminPassword": "[parameters('adminPassword')]",
                    "linuxConfiguration": {
                        "patchSettings": {
                            "patchMode": "AutomaticByPlatform",
                            "automaticByPlatformSettings": {
                                "rebootSetting": "IfRequired"
                            }
                        }
                    }
                },
                "securityProfile": {
                    "securityType": "TrustedLaunch",
                    "uefiSettings": {
                        "secureBootEnabled": true,
                        "vTpmEnabled": true
                    }
                }
            }
        },
        {
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2024-03-01",
            "name": "pg2",
            "location": "polandcentral",
            "dependsOn": [
                "[concat('Microsoft.Network/networkInterfaces/', 'pg2-nic')]"
            ],
            "properties": {
                "hardwareProfile": {
                    "vmSize": "Standard_B1ms"
                },
                "storageProfile": {
                    "osDisk": {
                        "createOption": "fromImage",
                        "managedDisk": {
                            "storageAccountType": "StandardSSD_LRS"
                        },
                        "diskSizeGB": 32,
                        "deleteOption": "Delete"
                    },
                    "imageReference": {
                        "publisher": "canonical",
                        "offer": "0001-com-ubuntu-server-jammy",
                        "sku": "22_04-lts-gen2",
                        "version": "latest"
                    }
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', 'pg2-nic')]",
                            "properties": {
                                "deleteOption": "Delete"
                            }
                        }
                    ]
                },
                "additionalCapabilities": {
                    "hibernationEnabled": false
                },
                "osProfile": {
                    "computerName": "pg2",
                    "adminUsername": "jsystems",
                    "adminPassword": "[parameters('adminPassword')]",
                    "linuxConfiguration": {
                        "patchSettings": {
                            "patchMode": "AutomaticByPlatform",
                            "automaticByPlatformSettings": {
                                "rebootSetting": "IfRequired"
                            }
                        }
                    }
                },
                "securityProfile": {
                    "securityType": "TrustedLaunch",
                    "uefiSettings": {
                        "secureBootEnabled": true,
                        "vTpmEnabled": true
                    }
                }
            }
        }
    ]
}