# Configuring parameters of the VM metadata service

You can configure parameters of the VM [metadata service](../../concepts/vm-metadata.md#metadata-formats) when [creating](../index.md#vm-create) or [updating](../vm-control/vm-update.md) the VM.

To configure metadata service parameters for a VM:

{% list tabs group=instructions %}

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  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 CLI command for updating VM parameters:

     ```bash
     yc compute instance update --help
     ```

  1. Get a list of VMs in the default folder:

     ```bash
     yc compute instance list
     ```

  1. Select `ID` or `NAME` of the VM you need.
  1. Define the metadata service settings:

     ```bash
     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 either `enabled` or `disabled`.
     * `gce-http-token`: Allows you to get the service account [IAM token](../../../iam/concepts/authorization/iam-token.md) for the VM using Google Compute Engine metadata. It can be either `enabled` or `disabled`.

     For more information, see [VM instance metadata service parameters](../../concepts/vm-metadata.md#metadata-formats).

  To configure parameters of the VM metadata service when creating the VM, use the `--metadata-options` parameter in the `yc compute instance create` [command](../../../cli/cli-ref/compute/cli-ref/instance/create.md) in the same way.

- Terraform {#tf}

  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.

  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 relevant documentation on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

  1. Open the Terraform configuration file and specify the `metadata_options` parameter in the VM description:

     ```hcl
     ...
     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` for `enabled` and `2` for `disabled`.
         * `gce_http_token`: Allows you to get the service account [IAM token](../../../iam/concepts/authorization/iam-token.md) for the VM using Google Compute Engine metadata. Possible values: `0`, `1` for `enabled` and `2` for `disabled`.

       For more information, see [VM instance metadata service parameters](../../concepts/vm-metadata.md#metadata-formats).

     For more information about `yandex_compute_instance` properties in Terraform, see [this provider guide](../../../terraform/resources/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.

     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](https://console.yandex.cloud) or this CLI command:

     ```bash
     yc compute instance get <VM_name>
     ```

- API {#api}

  When creating a VM, use the [create](../../api-ref/Instance/create.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Create](../../api-ref/grpc/Instance/create.md) gRPC API call.

  When updating a VM, use the [update](../../api-ref/Instance/update.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Update](../../api-ref/grpc/Instance/update.md) gRPC API call.

{% endlist %}