Function: name_from_id

Returns the short-form name within a provided resource's id, resource URI, self link, or full resource name.

For more information about using provider-defined functions with Terraform see the official documentation.

Example Usage

Use with the google provider

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
    }
  }
}

resource "google_pubsub_topic" "default" {
  name = "my-topic"
}

# Value is "my-topic"
output "function_output" {
  value = provider::google::name_from_id(google_pubsub_topic.default.id)
}

Use with the google-beta provider

terraform {
  required_providers {
    google-beta = {
      source = "hashicorp/google-beta"
    }
  }
}

resource "google_pubsub_topic" "default" {
  # provider argument omitted - provisioning by google or google-beta doesn't impact this example
  name = "my-topic"
}

# Value is "my-topic"
output "function_output" {
  value = provider::google-beta::name_from_id(google_pubsub_topic.default.id)
}

Signature

name_from_id(id string) string

Arguments

  1. id (String) A string of a resource's id, resource URI, self link, or full resource name. For example, these are all valid values: