Configuring parameters of the VM metadata service
You can configure parameters of the VM metadata service when creating or updating the VM.
To configure metadata service parameters for a VM:
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
View the 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
ID
orNAME
of the VM you need. -
Define the metadata service settings:
yc compute instance update <VM_ID> \ --metadata-options gce-http-endpoint=enabled
Where
--metadata-options
is the parameter defining the settings of the VM metadata service. The possible values are:gce-http-endpoint
: Allows you to access metadata using the Google Compute Engine format. It can be eitherenabled
ordisabled
.gce-http-token
: Allows you to get the service account IAM token for the VM using Google Compute Engine metadata. It can be eitherenabled
ordisabled
.
For more information, see VM instance metadata service parameters.
To configure parameters of the VM metadata service when creating the VM, use the --metadata-options
parameter in the yc compute instance create
command in the same way.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
-
Open the Terraform configuration file and specify the
metadata_options
parameter in the VM description:... resource "yandex_compute_instance" "test-vm" { ... metadata_options { gce_http_endpoint = 0 gce_http_token = 0 } ... } ...
Where:
-
yandex_compute_instance
: VM description:metadata_options
: Metadata parameters:gce_http_endpoint
: Allows you to access metadata using the Google Compute Engine format. Possible values:0
,1
forenabled
and2
fordisabled
.gce_http_token
: Allows you to get the service account IAM token for the VM using Google Compute Engine metadata. Possible values:0
,1
forenabled
and2
fordisabled
.
For more information, see VM instance metadata service parameters.
For more information about the
yandex_compute_instance
resource parameters in Terraform, see this TF provider article . -
-
Create the resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
All the resources you need will then be created in the specified folder with the settings you defined. You can check the new resources and their settings using the management console
or this CLI command:yc compute instance get <VM_name>
-
When creating a VM, use the create REST API method for the Instance resource or the InstanceService/Create gRPC API call.
When updating a VM, use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.