以下の内容はhttps://htn20190109.hatenablog.com/entry/2024/12/14/171100より取得しました。


{Azure Virtual Machines}仮想マシンのサイズの変更

 

https://learn.microsoft.com/ja-jp/azure/virtual-machines/sizes/resize-vm


-- 1. Azureログイン

az login --use-device-code
az account show

az version

az configure --list-defaults
az configure --defaults location=japaneast
az configure --list-defaults

 

az group list
az upgrade

 

-- 2. VPC、サブネット作成

 

cat <<-'EOF' > main.tf


terraform{
    required_providers{
        azurerm={
            source  = "hashicorp/azurerm"
            version = "=3.6.0"
        }
    }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}


resource "azurerm_resource_group" "rg9999999" {
  name = "rg9999999"
  location = "Japan East"

}


resource "azurerm_virtual_network" "vnet01" {
  name                = "vnet01"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.rg9999999.location
  resource_group_name = azurerm_resource_group.rg9999999.name
}

resource "azurerm_subnet" "subnet01" {
  name                 = "subnet01"
  resource_group_name  = azurerm_resource_group.rg9999999.name
  virtual_network_name = azurerm_virtual_network.vnet01.name
  address_prefixes     = ["10.0.0.0/24"]
}

 

resource "azurerm_public_ip" "pip01" {
  name                = "pip01"
  location            = azurerm_resource_group.rg9999999.location
  resource_group_name = azurerm_resource_group.rg9999999.name
  allocation_method   = "Dynamic"
}

resource "azurerm_network_security_group" "nsg01" {
  name                = "nsg01"
  location            = azurerm_resource_group.rg9999999.location
  resource_group_name = azurerm_resource_group.rg9999999.name

  security_rule {
    name                       = "SSH"
    priority                   = 100
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = "22"
    source_address_prefix      = "*"
    destination_address_prefix = "*"
  }
  security_rule {
    name                       = "OCI"
    priority                   = 110
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "*"
    source_port_range          = "*"
    destination_port_range     = "*"
    source_address_prefix      = "10.1.0.0/24"
    destination_address_prefix = "*"
  }
}


resource "azurerm_network_interface" "nic01" {
  name                = "nic01"
  location            = azurerm_resource_group.rg9999999.location
  resource_group_name = azurerm_resource_group.rg9999999.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.subnet01.id
    private_ip_address_allocation = "Dynamic"
    public_ip_address_id          = azurerm_public_ip.pip01.id
  }
}

resource "azurerm_network_interface_security_group_association" "nsg01_nic01" {
  network_interface_id      = azurerm_network_interface.nic01.id
  network_security_group_id = azurerm_network_security_group.nsg01.id
}

 

 


EOF

terraform init
terraform fmt
terraform -version

terraform plan

terraform apply -auto-approve


# terraform destroy -auto-approve

 

-- 3. VMインスタンス作成

az vm create \
--resource-group rg9999999 \
--name vm01 \
--image Ubuntu2404 \
--size Standard_B1s \
--admin-username azureuser \
--generate-ssh-keys \
--storage-sku Standard_LRS \
--nics nic01 \
--os-disk-delete-option delete 

 

az vm list \
--resource-group rg9999999 

 

VMインスタンス削除
az vm delete \
--resource-group rg9999999 \
--name vm01 \
--yes

 

-- 4. VM のサイズの変更

Standard B1ls (1 vcpu、0.5 GiB メモリ)
Standard B1s (1 vcpu、1 GiB メモリ)


az vm list-vm-resize-options \
--resource-group rg9999999 \
--name vm01 \
--query "[].name" 


# Deallocate the VM
az vm deallocate \
--resource-group rg9999999 \
--name vm01

# Resize the VM
az vm resize \
--resource-group rg9999999 \
--name vm01 \
--size Standard_B1ls

 


# Start the VM
az vm start \
--resource-group rg9999999 \
--name vm01

 

 


-- 5. クリーンアップ

az group list

 

az group delete \
--name NetworkWatcherRG \
--yes

 




以上の内容はhttps://htn20190109.hatenablog.com/entry/2024/12/14/171100より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14