| Crates.io | cloud-metadata |
| lib.rs | cloud-metadata |
| version | 0.2.0 |
| created_at | 2026-01-22 12:36:42.393729+00 |
| updated_at | 2026-01-22 14:47:32.083037+00 |
| description | Minimal Rust crate for fetching custom instance metadata from AWS, GCP, and Azure VMs |
| homepage | |
| repository | https://github.com/haraldh/cloud-metadata |
| max_upload_size | |
| id | 2061462 |
| size | 117,226 |
Minimal Rust crate for fetching custom instance metadata from AWS, GCP, and Azure VMs.
Add to your Cargo.toml:
[dependencies]
cloud-metadata = "0.1"
Or install the CLI:
cargo install cloud-metadata
use cloud_metadata::{CloudMetadata, MetadataError};
use serde::Deserialize;
#[derive(Deserialize)]
struct MyConfig {
db_host: String,
feature_flags: Vec<String>,
}
#[tokio::main]
async fn main() -> Result<(), MetadataError> {
// Auto-detect cloud provider
let metadata = CloudMetadata::detect().await?;
// Fetch and deserialize JSON config
let config: MyConfig = metadata.custom_json("user-data-json").await?;
// Or fetch as raw bytes
let raw: Vec<u8> = metadata.custom_data("user-data-json").await?;
// Or fetch as string
let text: String = metadata.custom_text("user-data-json").await?;
Ok(())
}
// Skip auto-detection if you know the provider
let metadata = CloudMetadata::aws();
let metadata = CloudMetadata::gcp();
let metadata = CloudMetadata::azure();
let metadata = CloudMetadata::gcp();
let value = metadata.project_attribute("my-project-key").await?;
# Auto-detect provider and fetch metadata
cloud-metadata fetch
# Fetch with explicit provider
cloud-metadata fetch --provider gcp
# Fetch specific key (for GCP)
cloud-metadata fetch my-custom-key
# Output as JSON
cloud-metadata fetch --format json
# Detect provider only
cloud-metadata detect
| Provider | Metadata Source | Key Parameter | Encoding |
|---|---|---|---|
| AWS | user-data | Ignored | Raw |
| GCP | instance/attributes/{key} | Required | Raw |
| Azure | customData | Ignored | Base64 (auto-decoded) |
resource "aws_instance" "example" {
user_data = jsonencode({
db_host = "postgres.internal"
feature_flags = ["new_ui"]
})
}
resource "google_compute_instance" "example" {
metadata = {
user-data-json = jsonencode({
db_host = "postgres.internal"
feature_flags = ["new_ui"]
})
}
}
resource "azurerm_linux_virtual_machine" "example" {
custom_data = base64encode(jsonencode({
db_host = "postgres.internal"
feature_flags = ["new_ui"]
}))
}
Licensed under either of Apache License, Version 2.0 or MIT license at your option.