[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Getting VM info > Getting VM info

# Getting information about a VM


To get basic information about each [VM](../../concepts/vm.md) you created, go to the VM page in the [management console](https://console.yandex.cloud). To get detailed information with custom [metadata](../../concepts/vm-metadata.md), use the [CLI](../../../cli/cli-ref/compute/cli-ref/instance/get.md) or [API](../../api-ref/Instance/get.md).

You can also get basic information and metadata [from within a VM](#inside-instance).

## Getting information from outside a VM {#outside-instance}

This method provides access to all metadata [folders](../../concepts/metadata/directories.md) as well as some keys in them: 

* In the [computeMetadata folder](../../concepts/metadata/directories.md#dir-compute), only the keys in `/instance/attributes/*` are readable.
* The [user-data folder](../../concepts/metadata/directories.md#dir-user) is fully readable.

{% list tabs group=instructions %}

- Management console {#console}

  In **Compute Cloud**, the **Virtual machines** page gives a list of VMs in the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) and brief information on each of them.

  For more information about a VM, click the row with its name.

  Here is a description of the available tabs:
  * **Overview** shows general information about the VM, including the [IP addresses](../../../vpc/concepts/address.md) assigned to it.
  * **Disks and storages** gives information about the [disks](../../concepts/disk.md) and [file storages](../../concepts/filesystem.md) attached to the VM.
  * **Backups** gives information about the VM [backups](../../../backup/concepts/index.md).
  * **Access bindings** gives information on the VM [access permissions](../../../iam/concepts/access-control/index.md).
  * **Operations** lists operations on the VM and its resources, such as disks.
  * **Monitoring** shows information about VM resource consumption. You can only get this info from the management console or from within the VM.
  * **Serial console** provides access to the [serial console](../../concepts/serial-console.md) if enabled when [creating](../index.md#vm-create) the VM.
  * **Serial port** provides information that the VM outputs to the serial port. To get this information via the API or CLI, follow [Getting the serial port output](get-serial-port-output.md).

- CLI {#cli}

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the command for getting information about a VM:

     ```bash
     yc compute instance get --help
     ```

  1. Select a VM, e.g., `first-instance`:

     ```bash
     yc compute instance list
     ```
     
     Result:
     ```text
     +----------------------+-----------------+---------------+---------+----------------------+
     |          ID          |       NAME      |    ZONE ID    | STATUS  |     DESCRIPTION      |
     +----------------------+-----------------+---------------+---------+----------------------+
     | fhm0b28lgfp4******** | first-instance  | ru-central1-a | RUNNING | my first vm via CLI  |
     | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI |
     +----------------------+-----------------+---------------+---------+----------------------+
     ```

  1. Get basic information about the VM:

     ```bash
     yc compute instance get first-instance
     ```

     To get VM information with metadata, use the `--full` flag:

     ```bash
     yc compute instance get --full first-instance
     ```

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  1. In the Terraform configuration file, describe the resources you want to create:

     ```hcl
     data "yandex_compute_instance" "my_instance" {
       instance_id = "<VM_ID>"
     }

     output "instance_external_ip" {
       value = "${data.yandex_compute_instance.my_instance.network_interface.0.nat_ip_address}"
     }
     ```

     Where:
     * `data "yandex_compute_instance"`: Description of the data source to get VM information from:
       * `instance_id`: VM ID.
     * `output "instance_external_ip"`: [Public IP address](../../../vpc/concepts/address.md#public-addresses) of the VM to return in the output:
       * `value`: Return value.

     For more information about the `yandex_compute_instance` data source properties, see [this provider guide](../../../terraform/data-sources/compute_instance.md).
  1. Create the resources:

     1. In the terminal, navigate to the configuration file directory.
     1. Make sure the configuration is correct using this command:
     
        ```bash
        terraform validate
        ```
     
        If the configuration is valid, you will get this message:
     
        ```bash
        Success! The configuration is valid.
        ```
     
     1. Run this command:
     
        ```bash
        terraform plan
        ```
     
        You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
     1. Apply the configuration changes:
     
        ```bash
        terraform apply
        ```
     
     1. Type `yes` and press **Enter** to confirm the changes.

     Terraform will create all required resources and display their output variables. To check the results, run this command:

     ```bash
     terraform output instance_external_ip
     ```

     Result:

     ```text
     instance_external_ip = "158.160.50.228"
     ```

- API {#api}

  To get basic information about a VM, use the [get](../../api-ref/Instance/get.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Get](../../api-ref/grpc/Instance/get.md) gRPC API call.

  The basic information does not include any custom metadata provided when creating or [updating](../vm-control/vm-update.md) the VM. To get the information along with the metadata, specify `view=FULL` in the parameters.

{% endlist %}

## Getting information from within a VM {#inside-instance}

You can directly access the VM metadata from within the VM. This method provides access to [all the metadata folders](../../concepts/metadata/directories.md) as well as all the keys inside them.

You can get direct access (without authentication) to metadata from inside the VM through a special metadata service. The metadata service inside the VM instance is available at `http://169.254.169.254`.

All authenticated VM users can access the metadata service without any restrictions. You cannot restrict an individual VM user's access to metadata.

You can test the metadata service using [cURL](https://curl.haxx.se) by first [connecting](../vm-connect/ssh.md) to the VM via the ssh protocol:

```bash
curl \
  --header Metadata-Flavor:Google \
  169.254.169.254
```

The metadata service will respond with a list of available metadata versions, for example:

```bash
1.0
2007-01-19
2007-03-01
...
2023-02-15
2023-05-10
latest
```

We recommend always using the `latest` metadata version.

### HTTP request {#gce-http}

```http request
GET http://169.254.169.254/computeMetadata/v1/instance/
  ? alt=<json|text>
  & recursive=<true|false>
  & wait_for_change=<true|false>
  & last_etag=<string>
  & timeout_sec=<int>
Metadata-Flavor: Google
```

Where:
* `alt`: Response format. The default value is `text`.
* `recursive`: If `true`, it returns all values in the tree recursively. The default value is `false`.
* `wait_for_change`: If `true`, this response will be returned only when one of the metadata parameters is modified. The default value is `false`.
* `last_etag`: ETag from the previous response to a similar request. Use if `wait_for_change="true"`.
* `timeout_sec`: Maximum request timeout. Use if `wait_for_change="true"`.

In response, the service will return the current values ​​of the `computeMetadata` folder metadata [keys](../../concepts/metadata/directories.md#dir-compute).

### Request examples {#request-examples}

#### Getting an FQDN {#example1}

To get the full name of the VM ([FQDN](../../concepts/network.md#hostname)) from the [computeMetadata](../../concepts/metadata/directories.md#dir-compute) folder, [connect](../vm-connect/ssh.md) to the VM and send the following request:

```bash
curl \
  --header Metadata-Flavor:Google \
  169.254.169.254/computeMetadata/v1/instance/hostname
```

#### Getting VM metadata in an easy-to-read format {#example2}

To get metadata in an easy-to-read format, [connect](../vm-connect/ssh.md) to the VM and send the following request using the [jq](https://stedolan.github.io/jq/) utility:

```bash
  curl \
    --header Metadata-Flavor:Google \
    169.254.169.254/computeMetadata/v1/instance/?recursive=true | \
    jq -r '.'
```

#### Getting an identity document {#example3}

To get an [identity document](../../concepts/metadata/identity-document.md) from the [computeMetadata](../../concepts/metadata/directories.md#dir-compute) folder, [connect](../vm-connect/ssh.md) to the VM and send the following request:

```bash
curl \
  --header Metadata-Flavor:Google \
  169.254.169.254/computeMetadata/v1/instance/vendor/identity/document
```

#### Getting data from the user-data folder {#example4}

To get the metadata from the [user-data](../../concepts/metadata/directories.md#dir-user) folder, [connect](../vm-connect/ssh.md) to the VM and send the following request:

```bash
curl \
  --header Metadata-Flavor:Google \
  169.254.169.254/latest/user-data
```

The metadata service will return the response in YAML format:

```yaml
#cloud-config
datasource:
 Ec2:
  strict_id: false
ssh_pwauth: no
users:
- name: admin
  sudo: ALL=(ALL) NOPASSWD:ALL
  shell: /bin/bash
  ssh_authorized_keys:
  - ssh-ed25519 AAAAC3Nza******l0pTWGO
```

If you want to get only a particular key (e.g., user name) in the output, use the [yq](https://github.com/mikefarah/yq) tool.

```bash
curl \
  --silent \
  --fail \
  --header Metadata-Flavor:Google \
  169.254.169.254/latest/user-data | \
  yq .users[].name
```

#### Getting an IAM token for a service account {#example5}

When sending [Yandex Cloud API](../../../api-design-guide/index.md) requests, you need an [IAM token](../../../iam/concepts/authorization/iam-token.md) issued for the [service account](../../../iam/concepts/users/service-accounts.md). You can obtain such an IAM token using the metadata service from within your VM. To do this, a service account must be [linked](../vm-connect/auth-inside-vm.md#link-sa-with-instance) to the VM.

To get the IAM token from the [computeMetadata](../../concepts/metadata/directories.md#dir-compute) folder, [connect](../vm-connect/ssh.md) to the VM and send the following request:

```bash
curl \
  --silent \
  --fail \
  --header Metadata-Flavor:Google \
  169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token | \
  jq -r .access_token
```

#### Getting data from the user-data folder from outside the VM {#example6}

To get metadata from outside a VM, use the [Yandex Cloud CLI](../../../cli/cli-ref/compute/cli-ref/instance/get.md) tool:

```bash
yc compute instance get my-vm --full --jq .metadata
```

The metadata service will return the response in JSON format:

```json
{
  "install-unified-agent": "0",
  "serial-port-enable": "0",
  "ssh-keys": "admin:ssh-ed25519 AAAAC3N******l0pTWGO admin@my.domain\n",
  "user-data": "#cloud-config\ndatasource:\n Ec2:\n  strict_id: false\nssh_pwauth: no\nusers:\n- name: admin\n  sudo: ALL=(ALL) NOPASSWD:ALL\n  shell: /bin/bash\n  ssh_authorized_keys:\n  - ssh-ed25519 AAAAC3N******l0pTWGO"
}
```

For more information on how to get the values of variables and [Yandex Lockbox secrets](../../../lockbox/concepts/secret.md) provided through metadata, see [Creating a VM with metadata from environment variables](../vm-create/create-with-env-variables.md) and [Creating a VM with access to a Yandex Lockbox secret](../vm-create/create-with-lockbox-secret.md).