How metadata keys work? Do they look for exact word in the startup script and replace? Are there any restrictions on metadata names allowed?
Metadata in a GCE instance is stored as
key:value pairs, same for startup script. Think of it like a huge sidecar JSON file with many entries, and startup script is one of them. When an instance boots up, this specific key for startup script will be inspected and sent to the guest OS for execution. You have a limit of 256 KB in terms of text content for the startup script if it is defined directly on a GCE instance’s metadata (to go over this limit, use a script stored in a GCS bucket).
General limits of metadata in GCE can be found in this article: About VM metadata – Limits