apiVersion: compute.azure.com/v1api20220301
kind: VirtualMachine
metadata:
  name: vm-windows
  namespace: winfv
spec:
  location: {{.Env.AZURE_LOCATION}}
  owner:
    name: {{.Env.AZURE_RESOURCE_GROUP}}
  hardwareProfile:
    vmSize: Standard_D4s_v3
  networkProfile:
    networkInterfaces:
      - reference:
          group: network.azure.com
          kind: NetworkInterface
          name: nic-windows
  osProfile:
    computerName: winfv-windows
    adminUsername: winfv
    adminPassword:
      key: password
      name: winfv-secret-windows
  storageProfile:
    imageReference:
      publisher: MicrosoftWindowsServer
      offer: WindowsServer
      sku: {{.Env.AZURE_WINDOWS_IMAGE_SKU}}
      version: {{.Env.AZURE_WINDOWS_IMAGE_VERSION}}
    osDisk:
      createOption: FromImage
      managedDisk:
        storageAccountType: Premium_LRS
---
apiVersion: network.azure.com/v1api20240301
kind: NetworkInterface
metadata:
  name: nic-windows
  namespace: winfv
spec:
  location: {{.Env.AZURE_LOCATION}}
  owner:
    name: {{.Env.AZURE_RESOURCE_GROUP}}
  networkSecurityGroup:
    reference:
      group: network.azure.com
      kind: NetworkSecurityGroup
      name: winfv-sg
  ipConfigurations:
    - name: ipconfig-windows
      subnet:
        reference:
          group: network.azure.com
          kind: VirtualNetworksSubnet
          name: subnet-winfv
      publicIPAddress:
        reference:
          group: network.azure.com
          kind: PublicIPAddress
          name: pip-windows
---
apiVersion: network.azure.com/v1api20240301
kind: PublicIPAddress
metadata:
  name: pip-windows
  namespace: winfv
spec:
  location: {{.Env.AZURE_LOCATION}}
  owner:
    name: {{.Env.AZURE_RESOURCE_GROUP}}
  publicIPAllocationMethod: Static
  sku:
    name: Standard
---
apiVersion: compute.azure.com/v1api20220301
kind: VirtualMachinesExtension
metadata:
  name: vm-windows-openssh
  namespace: winfv
spec:
  location: {{.Env.AZURE_LOCATION}}
  owner:
    name: vm-windows
  publisher: Microsoft.Azure.OpenSSH
  type: WindowsOpenSSH
  typeHandlerVersion: "3.0"
---
apiVersion: compute.azure.com/v1api20220301
kind: VirtualMachinesExtension
metadata:
  name: vm-windows-customextension
  namespace: winfv
spec:
  location: {{.Env.AZURE_LOCATION}}
  owner:
    name: vm-windows
  publisher: Microsoft.Compute
  type: CustomScriptExtension
  typeHandlerVersion: "1.9"
  settings:
    commandToExecute: powershell -command "echo \"{{.Env.PUBLIC_KEY}}\" | Add-Content 'C:\ProgramData\ssh\administrators_authorized_keys' -Encoding UTF8;icacls.exe 'C:\ProgramData\ssh\administrators_authorized_keys' /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F'"
