Returns the project 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.
google
providerterraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
}
resource "google_pubsub_topic" "default" {
project = "my-project"
name = "my-topic"
}
# Value is "my-project"
output "project_from_id" {
value = provider::google::project_from_id(google_pubsub_topic.default.id)
}
google-beta
providerterraform {
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
project = "my-project"
name = "my-topic"
}
# Value is "my-project"
output "project_from_id" {
value = provider::google-beta::project_from_id(google_pubsub_topic.default.id)
}
project_from_id(id string) string
id
(String) A string of a resource's id, resource URI, self link, or full resource name. For example, these are all valid values:"projects/my-project/zones/us-central1-c/instances/my-instance"
"https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/instances/my-instance"
"//gkehub.googleapis.com/projects/my-project/locations/us-central1/memberships/my-membership"