https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/public_ip
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface
- resource_group.tf
1 2 3 4 5 |
resource "azurerm_resource_group" "hoge" { name = "hoge" location = "japaneast" tags = local.tags } |
- virtual_network.tf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
resource "azurerm_virtual_network" "hoge" { name = "hoge" address_space = ["10.0.0.0/16"] location = azurerm_resource_group.hoge.location resource_group_name = azurerm_resource_group.hoge.name tags = local.tags } resource "azurerm_subnet" "hoge" { resource_group_name = azurerm_resource_group.hoge.name virtual_network_name = azurerm_virtual_network.hoge.name address_prefixes = ["10.0.1.0/24"] name = "hoge" service_endpoints = [ "Microsoft.Storage" ] } resource "azurerm_network_interface" "hoge" { name = "hoge" location = azurerm_resource_group.hoge.location resource_group_name = azurerm_resource_group.hoge.name ip_configuration { name = "hoge" subnet_id = azurerm_subnet.hoge.id private_ip_address_allocation = "Dynamic" public_ip_address_id = azurerm_public_ip.hoge.id } } |
- network_security_group.tf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
resource "azurerm_network_security_group" "hoge" { name = "japaneast-vm-nsg" location = azurerm_resource_group.hoge.location resource_group_name = azurerm_resource_group.hoge.name } resource "azurerm_network_security_rule" "hoge" { name = "Port_3389" priority = 310 direction = "Inbound" access = "Allow" protocol = "Tcp" source_port_range = "*" destination_port_range = "3389" source_address_prefix = "xx.xx.xx.xx/32" destination_address_prefix = "*" resource_group_name = azurerm_resource_group.hoge.name network_security_group_name = azurerm_network_security_group.hoge.name } |
- public_ip.tf
1 2 3 4 5 6 7 |
resource "azurerm_public_ip" "hoge" { name = "hoge" location = azurerm_resource_group.hoge.location resource_group_name = azurerm_resource_group.hoge.name allocation_method = "Static" tags = local.tags } |
- vm.tf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
resource "azurerm_windows_virtual_machine" "hoge" { name = "hoge" location = azurerm_resource_group.hoge.location resource_group_name = azurerm_resource_group.hoge.name size = "Standard_D2s_v3" computer_name = "hoge" admin_username = "hoge-admin" admin_password = "xxxxxxxxxxxx" #仮パスワード lifecycle { ignore_changes = [ admin_password ] } network_interface_ids = [ azurerm_network_interface.hoge.id, ] source_image_reference { publisher = "MicrosoftWindowsDesktop" offer = "Windows-11" sku = "win11-23h2-pro" version = "latest" } os_disk { caching = "ReadWrite" storage_account_type = "Standard_LRS" } tags = local.tags } resource "azurerm_network_interface_security_group_association" "hoge" { network_interface_id = azurerm_network_interface.hoge.id network_security_group_id = azurerm_network_security_group.hoge.id } resource "azurerm_dev_test_global_vm_shutdown_schedule" "hoge" { virtual_machine_id = azurerm_windows_virtual_machine.hoge.id location = azurerm_resource_group.hoge.location enabled = true daily_recurrence_time = "1900" timezone = "Tokyo Standard Time" notification_settings { enabled = false } } |
- image一覧の確認方法
1 |
$ az vm image list --location japaneast --offer Windows-11 --all --output table |
Microsoft Remote Desktopをインストールしておいて、Connect > Download RDP fileをダウンロードして接続できればOK.
自動起動方法は以下。
Was this helpful?
0 / 0
1989年生まれのFindy/SRE。ホスティングから大規模なアドテクなどのインフラエンジニアとして携わる。現在はサービスの信頼性向上、DevOps、可用性、レイテンシ、パフォーマンス、モニタリング、オブザーバビリティ、緊急対応、AWSでのインフラ構築、Docker開発環境の提供、IaC、新技術の検証、リファクタリング、セキュリティ強化、分析基盤の運用などを担当している。個人事業主では数社サーバー保守とベンチャー企業のSREインフラコンサルティングやMENTA/TechBullで未経験者にインフラのコーチング/コミュニティマネージャーとして立ち上げと運営をしている。また、過去「脆弱性スキャナVuls」のOSS活動もしており、自称エバンジェリスト/技術広報/テクニカルサポート/コントリビュータでもある。