Migrating from v0.1 to v1 metadata server endpoint

If you use the 0.1 metadata server endpoint, read this guide to understand how to migrate to the v1 metadata server endpoint. If you are migrating from v1beta1 metadata server endpoint to v1, see Transitioning from v1beta1 metadata server endpoint.

To migrate from v0.1 to v1.0, you need to complete the following steps:

  1. Review the differences between v0.1 and v1.0 metadata server endpoints.
  2. Review the mapping tables to identify the new metadata server values.
  3. Update queries to reflect these changes.
  4. (Optional) Disable the v0.1 and v1beta1 endpoints.

Differences between the v0.1 and v1.0 metadata server endpoints

In general, the v0.1 metadata server endpoints differ from v1 in the following ways:

  • The root used for querying metadata server endpoint has changed from http://metadata.google.internal/0.1/meta-data/ to http://metadata.google.internal/computeMetadata/v1/.
  • v1 metadata server requests must include the Metadata-Flavor: Google header. For example, a request to the disks/ attribute now looks like the following:

    curl "http://metadata.google.internal/computeMetadata/v1/instance/disks/" -H "Metadata-Flavor: Google"
    
  • Custom metadata can be queried at both the project and instance level.

    In the v0.1 metadata server, for the attributes/ property, both instance and project metadata values are in the same directory. If an attribute has both instance and project metadata values, the instance metadata value for a given key is returned.

    For v1 queries, the URL must specify whether instance or project metadata is requested. For example to query the sshKeys attribute, run one or both of the following:

    For sshKeys set on the project, run the following command:

    curl "http://metadata.google.internal/computeMetadata/v1/project/attributes/sshKeys" -H "Metadata-Flavor: Google"
    

    For sshKeys set on this instance, run the following command:

    curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/sshKeys" -H "Metadata-Flavor: Google"
    
  • Some metadata entries in v0.1 return JSON objects. In the v1 metadata server, these metadata entries are organized by directories. This organization of entries lets you query specific index entries and values for these previously nested fields. For more information about querying a directory listing or accessing JSON objects in v1, see Attributes as directory listings.

Mapping 0.1 metadata server values to v1 values

Instance attributes

The following metadata entries are moved into the instance/ directory:

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to the root) Example output
Description v0.1 description My instance description
v1 instance/description
Hostname v0.1 hostname my-instance.c.my-project.internal
v1 instance/hostname
Image v0.1 image projects/eip-images/global/images/debian-9-drawfork-v20180109
v1 instance/image
Machine type v0.1 machine-type projects/12345/machineTypes/n1-standard-1
v1 instance/machine-type
Instance tags v0.1 tags ["cheese", "lettuce"]
v1 instance/tags
Zone v0.1 zone projects/12345/zones/us-central1-c
v1 instance/zone

Project attributes

The following metadata entries are moved into the project/ directory:

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to root) Example output
Project ID v0.1 project-id my-project
v1 project/project-id
Numeric Project ID v0.1 numeric-project-id 12345
v1 project/numeric-project-id

Attributes that are moved

The following metadata entries are moved to a new endpoint:

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to root) Example output
Domain v0.1 domain c.my-project.internal
v1 instance/hostname my-instance.c.my-project.internal

Attributes that are renamed

The following metadata entries are renamed:

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to root) Example output
Instance ID v0.1 instance-id 123456789
v1 instance/id 123456789

Attributes as directory listings

The following metadata entries returned JSON objects in v0.1 and are organized into directories in v1.

For these metadata entries, you can use either of the following methods to access the endpoints:

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to root) Example output
Disks v0.1 disks
{"disks":[{
"deviceName":"persistent-disk-0",
"index":0,
"mode":"READ_WRITE",
"type":"PERSISTENT"}]}
v1 instance/attached-disks/?recursive=true
[{"deviceName": "persistent-disk-0",
"index":0,
"mode":"READ_WRITE",
"type":"PERSISTENT"}]
Network interfaces v0.1 network
{"networkInterface":
[{"accessConfiguration":
[{"externalIp":"35.194.6.47",
"type":"ONE_TO_ONE_NAT"}],
"ip":"10.128.0.4",
"mac":"42:01:0a:80:00:04","mtu":1460,
"network":"projects/12345/networks/default"}]}
v1 instance/network-interfaces/?recursive=true
[{"accessConfigs":
[{"externalIp":"35.194.6.47",
"type":"ONE_TO_ONE_NAT"}],
"dnsServers":["169.254.169.254"],
"forwardedIps":[],
"gateway":"10.128.0.1",
"ip":"10.128.0.4",
"ipAliases [],
"mac":"42:01:0a:80:00:04","mtu":1460,
"network":"projects/12345/networks/default",
"subnetmask":"255.255.240.0","targetInstanceIps":[]}]
Service account information (all service accounts) v0.1 service-accounts
{"serviceAccounts":
[{"scopes":["https://www.googleapis.com/auth/devstorage.read_only"],
"serviceAccount":"12345-compute@developer.gserviceaccount.com"}]}
v1 instance/service-accounts/?recursive=true
{"123451-compute@developer.gserviceaccount.com":
{"aliases":["default"],
"email":"123451-compute@developer.gserviceaccount.com",
"scopes":["https://www.googleapis.com/auth/devstorage.read_only"]},
"default":{"aliases":["default"],
"email":"123451-compute@developer.gserviceaccount.com",
"scopes":["https://www.googleapis.com/auth/devstorage.read_only"]}}
Service account information (single service account) v0.1 service-accounts/<email|default>
{"scopes":["https://www.googleapis.com/auth/devstorage.read_only"],
"serviceAccount":"123451-compute@developer.gserviceaccount.com"}
v1 instance/service-accounts/<email|default>/?recursive=true
{"aliases":["default"],
"email":"123451-compute@developer.gserviceaccount.com",
"scopes":["https://www.googleapis.com/auth/devstorage.read_only"]}

Querying OAuth2 access tokens

The following metadata entries return OAuth2 access tokens.

v0.1 root - http://metadata.google.internal/0.1/meta-data/
v1 root - http://metadata.google.internal/computeMetadata/v1
Metadata entry Version URI (relative to root) Example output
OAuth2 Token v0.1 (Method 1)

auth-token?service_account=<email|default>&scope=scopeA,scopeB

or

auth_token?service_account=<email|default>&scope=scopeA,scopeB

{"expires":1568854217,
"oauth2_access_token":"ya29.c.KmyIB0i4tH1xLzKGrqeeK6TGWEW3b18Lcq...."}
v0.1 (Method 2) service-accounts/<email|default>/acquire
{"accessToken":"ya29.c.KmyIB0i4tH1xLNzKGrqeeK6TGWEW3b18Lcq.....",
"expiresAt":1568854217,"expiresIn":2022}
v1 instance/service-accounts/<email|default>/token
{"access_token":"ya29.c.KmyIB0i4tH1xLNzKGrqeeK6TGWEW3b18Lcq....",
"expires_in":2022,"token_type":"Bearer"}
Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation