Getting information about a VM
To get basic information about each VM you created, go to the management console and open the VM page. To get detailed information with user-defined metadata, use the CLI or API.
You can also get basic information and metadata from inside a VM.
Getting information from outside a VM
On the Virtual machines page in the Compute Cloud section, you can find a list of VMs in the folder and brief information for each of them.
For more information about a certain VM, click the line with its name.
Tabs:
-
Overview shows general information about the VM, including the IP addresses assigned to it.
-
Disks provides information about the disks attached to the VM.
-
File storage provides information about the file storage attached.
-
Operations lists operations on the VM and resources attached to it, such as disks.
-
Monitoring shows information about resource consumption on the VM. You can only get this information from the management console or from inside the VM.
-
Serial console provides access to the serial console if enabled when creating the VM.
-
Serial port provides information that the VM outputs to the serial port. To get this information via the API or CLI, follow the Getting serial port's output guide.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a description of the command to get serial port output:
yc compute instance get --help
-
Select a VM, such as
first-instance
:yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4tkoa3jl6 | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7gcoji2f8s | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
-
Get basic information about the VM:
yc compute instance get first-instance
To get VM information with metadata, use the
--full
flag:yc compute instance get --full first-instance
To get basic information about a VM, use the get REST API method for the Instance resource or the InstanceService/Get gRPC API call.
The basic information does not include the user-defined metadata provided when creating or updating the VM. To get the information along with the metadata, specify view=FULL
in the parameters.
Getting information from inside a VM
From inside the VM, the metadata service is accessible at the IP address 169.254.169.254
.
Currently, the Yandex Cloud metadata service returns metadata in Google Compute Engine and Amazon EC2 formats.
Google Compute Engine
The Yandex Cloud metadata service lets you return metadata in Google Compute Engine format.
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 (by default,text
).recursive
: Iftrue
, it returns all values in the tree recursively. By default,false
.wait_for_change
: Iftrue
, this response is only returned when one of the metadata parameters is modified. By default,false
.last_etag
: The ETag value from the previous response to a similar request. Use it whenwait_for_change="true"
.timeout_sec
: Maximum request timeout. Use it whenwait_for_change="true"
.
Request examples
Find out the ID of a VM from inside it:
curl -H Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/id
Get metadata in JSON format:
curl -H Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/?recursive=true
Get metadata in an easy-to-read format. Use the jq utility:
curl -H Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/?recursive=true | jq -r '.'
List of returned elements
List of elements available for this request:
attributes/
: User-defined metadata provided in themetadata
field when creating or updating the VM.attributes/ssh-keys
: List of public SSH keys provided in themetadata
field through thessh-keys
value when creating the VM.description
: Text description provided when creating or updating the VM.disks/
: Disks attached to the VM.hostname
: FQDN assigned to the VM.id
: VM ID. The ID is generated automatically when the VM is being created and is unique within Yandex Cloud.name
: Name that was provided when creating or updating the VM.networkInterfaces/
: Network interfaces connected to the VM.service-accounts
: Service accounts linked to the VM.service-accounts/default/token
: Yandex Identity and Access Management token of the linked service account.
Other elements, such as project
, which are used for backward compatibility and remain empty.
Amazon EC2
The Yandex Cloud metadata service lets you return metadata in Amazon EC2 format.
This format has no support for user-defined metadata fields.
HTTP request
GET http://169.254.169.254/latest/meta-data/<element>
Where <element>
stands for the path to the element you want to get. If the element is omitted, the response returns a list of available elements.
List of returned elements
List of elements that are available for this request.
Note
The angle brackets contain parameters that need to be replaced with values. For example, instead of <mac>
, you should insert the MAC address of the network interface.
hostname
: VM's hostname.instance-id
: VM ID.local-ipv4
: Internal IPv4 address.local-hostname
: VM's hostname.mac
: MAC address of the VM's network interface.network/interfaces/macs/<mac>/ipv6s
: Internal IPv6 addresses associated with the network interface.network/interfaces/macs/<mac>/local-hostname
: Hostname associated with the network interface.network/interfaces/macs/<mac>/local-ipv4s
: Internal IPv4 addresses associated with the network interface.network/interfaces/macs/<mac>/mac
: MAC address of the VM's network interface.public-ipv4
: External IPv4 address.
Request examples
Getting an internal IP address from inside a VM:
curl http://169.254.169.254/latest/meta-data/local-ipv4
Setting up metadata service parameters for a VM instance
You can set up metadata service parameters when creating or updating VMs.
You can use the following settings:
-
aws-v1-http-endpoint
provides access to metadata using AWS format (IMDSv1). Acceptable values:enabled
,disabled
. -
aws-v1-http-endpoint
provides access to Identity and Access Management credentials using AWS format (IMDSv1). Acceptable values:enabled
,disabled
.Note
The IMDSv1 format has certain drawbacks in terms of security, which is why the
aws-v1-http-token
parameter isdisabled
by default. The most severe drawback of IMDSv1 is its high risk of certain attacks, e.g., SSRF. You can read more about it in the AWS official blog. To change the default behavior of this parameter, contact support.The safest method to obtain the token in Yandex Cloud is to use Google Compute Engine format, which uses an extra header for protection against SSRF.
-
gce-http-endpoint
provides access to metadata using Google Compute Engine format. Acceptable values:enabled
,disabled
. -
gce-http-token
provides access to Identity and Access Management credentials using Google Compute Engine format. Acceptable values:enabled
,disabled
.
To set up metadata service parameters for a VM instance:
If you don't have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a description of the CLI command for updating VM parameters:
yc compute instance update --help
-
Get a list of VMs in the default folder:
yc compute instance list
-
Select the
ID
orNAME
of the relevant VM instance. -
Set the metadata service settings using the
--metadata-options
parameter:yc compute instance update <VM instance ID> \ --metadata-options gce-http-endpoint=enabled
Use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.
For more information about Terraform, see our documentation.
With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.
For more information about the provider resources, see the documentation on the Terraform site or mirror site.
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
-
Open the Terraform configuration file and change the
metadata_options
parameter in the VM description:... resource "yandex_compute_instance" "test-vm" { metadata_options { gce-http-endpoint = "enabled" } } ...
For more information about the
yandex_compute_instance
resource parameters in Terraform, see the provider documentation. -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.