gcp.tags.LocationTagBinding
Explore with Pulumi AI
A LocationTagBinding represents a connection between a TagValue and a non-global target such as a Cloud Run Service or Compute Instance. Once a LocationTagBinding is created, the TagValue is applied to all the descendants of the cloud resource.
To get more information about LocationTagBinding, see:
- API documentation
- How-to Guides
Example Usage
Cloud Run Service
To bind a tag to a Cloud Run service:
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const project = new gcp.organizations.Project("project", {
projectId: "project_id",
name: "project_id",
orgId: "123456789",
});
const key = new gcp.tags.TagKey("key", {
parent: "organizations/123456789",
shortName: "keyname",
description: "For keyname resources.",
});
const value = new gcp.tags.TagValue("value", {
parent: pulumi.interpolate`tagKeys/${key.name}`,
shortName: "valuename",
description: "For valuename resources.",
});
const binding = new gcp.tags.LocationTagBinding("binding", {
parent: `//run.googleapis.com/projects/${projectGoogleProject.number}/locations/${_default.location}/services/${_default.name}`,
tagValue: pulumi.interpolate`tagValues/${value.name}`,
location: "us-central1",
});
import pulumi
import pulumi_gcp as gcp
project = gcp.organizations.Project("project",
project_id="project_id",
name="project_id",
org_id="123456789")
key = gcp.tags.TagKey("key",
parent="organizations/123456789",
short_name="keyname",
description="For keyname resources.")
value = gcp.tags.TagValue("value",
parent=key.name.apply(lambda name: f"tagKeys/{name}"),
short_name="valuename",
description="For valuename resources.")
binding = gcp.tags.LocationTagBinding("binding",
parent=f"//run.googleapis.com/projects/{project_google_project['number']}/locations/{default['location']}/services/{default['name']}",
tag_value=value.name.apply(lambda name: f"tagValues/{name}"),
location="us-central1")
package main
import (
"fmt"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/organizations"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/tags"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := organizations.NewProject(ctx, "project", &organizations.ProjectArgs{
ProjectId: pulumi.String("project_id"),
Name: pulumi.String("project_id"),
OrgId: pulumi.String("123456789"),
})
if err != nil {
return err
}
key, err := tags.NewTagKey(ctx, "key", &tags.TagKeyArgs{
Parent: pulumi.String("organizations/123456789"),
ShortName: pulumi.String("keyname"),
Description: pulumi.String("For keyname resources."),
})
if err != nil {
return err
}
value, err := tags.NewTagValue(ctx, "value", &tags.TagValueArgs{
Parent: key.Name.ApplyT(func(name string) (string, error) {
return fmt.Sprintf("tagKeys/%v", name), nil
}).(pulumi.StringOutput),
ShortName: pulumi.String("valuename"),
Description: pulumi.String("For valuename resources."),
})
if err != nil {
return err
}
_, err = tags.NewLocationTagBinding(ctx, "binding", &tags.LocationTagBindingArgs{
Parent: pulumi.Sprintf("//run.googleapis.com/projects/%v/locations/%v/services/%v", projectGoogleProject.Number, _default.Location, _default.Name),
TagValue: value.Name.ApplyT(func(name string) (string, error) {
return fmt.Sprintf("tagValues/%v", name), nil
}).(pulumi.StringOutput),
Location: pulumi.String("us-central1"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var project = new Gcp.Organizations.Project("project", new()
{
ProjectId = "project_id",
Name = "project_id",
OrgId = "123456789",
});
var key = new Gcp.Tags.TagKey("key", new()
{
Parent = "organizations/123456789",
ShortName = "keyname",
Description = "For keyname resources.",
});
var @value = new Gcp.Tags.TagValue("value", new()
{
Parent = key.Name.Apply(name => $"tagKeys/{name}"),
ShortName = "valuename",
Description = "For valuename resources.",
});
var binding = new Gcp.Tags.LocationTagBinding("binding", new()
{
Parent = $"//run.googleapis.com/projects/{projectGoogleProject.Number}/locations/{@default.Location}/services/{@default.Name}",
TagValue = @value.Name.Apply(name => $"tagValues/{name}"),
Location = "us-central1",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.Project;
import com.pulumi.gcp.organizations.ProjectArgs;
import com.pulumi.gcp.tags.TagKey;
import com.pulumi.gcp.tags.TagKeyArgs;
import com.pulumi.gcp.tags.TagValue;
import com.pulumi.gcp.tags.TagValueArgs;
import com.pulumi.gcp.tags.LocationTagBinding;
import com.pulumi.gcp.tags.LocationTagBindingArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var project = new Project("project", ProjectArgs.builder()
.projectId("project_id")
.name("project_id")
.orgId("123456789")
.build());
var key = new TagKey("key", TagKeyArgs.builder()
.parent("organizations/123456789")
.shortName("keyname")
.description("For keyname resources.")
.build());
var value = new TagValue("value", TagValueArgs.builder()
.parent(key.name().applyValue(name -> String.format("tagKeys/%s", name)))
.shortName("valuename")
.description("For valuename resources.")
.build());
var binding = new LocationTagBinding("binding", LocationTagBindingArgs.builder()
.parent(String.format("//run.googleapis.com/projects/%s/locations/%s/services/%s", projectGoogleProject.number(),default_.location(),default_.name()))
.tagValue(value.name().applyValue(name -> String.format("tagValues/%s", name)))
.location("us-central1")
.build());
}
}
resources:
project:
type: gcp:organizations:Project
properties:
projectId: project_id
name: project_id
orgId: '123456789'
key:
type: gcp:tags:TagKey
properties:
parent: organizations/123456789
shortName: keyname
description: For keyname resources.
value:
type: gcp:tags:TagValue
properties:
parent: tagKeys/${key.name}
shortName: valuename
description: For valuename resources.
binding:
type: gcp:tags:LocationTagBinding
properties:
parent: //run.googleapis.com/projects/${projectGoogleProject.number}/locations/${default.location}/services/${default.name}
tagValue: tagValues/${value.name}
location: us-central1
Compute Instance
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const project = new gcp.organizations.Project("project", {
projectId: "project_id",
name: "project_id",
orgId: "123456789",
});
const key = new gcp.tags.TagKey("key", {
parent: "organizations/123456789",
shortName: "keyname",
description: "For keyname resources.",
});
const value = new gcp.tags.TagValue("value", {
parent: pulumi.interpolate`tagKeys/${key.name}`,
shortName: "valuename",
description: "For valuename resources.",
});
const binding = new gcp.tags.LocationTagBinding("binding", {
parent: pulumi.interpolate`//compute.googleapis.com/projects/${project.number}/zones/us-central1-a/instances/${instance.instanceId}`,
tagValue: pulumi.interpolate`tagValues/${value.name}`,
location: "us-central1-a",
});
import pulumi
import pulumi_gcp as gcp
project = gcp.organizations.Project("project",
project_id="project_id",
name="project_id",
org_id="123456789")
key = gcp.tags.TagKey("key",
parent="organizations/123456789",
short_name="keyname",
description="For keyname resources.")
value = gcp.tags.TagValue("value",
parent=key.name.apply(lambda name: f"tagKeys/{name}"),
short_name="valuename",
description="For valuename resources.")
binding = gcp.tags.LocationTagBinding("binding",
parent=project.number.apply(lambda number: f"//compute.googleapis.com/projects/{number}/zones/us-central1-a/instances/{instance['instanceId']}"),
tag_value=value.name.apply(lambda name: f"tagValues/{name}"),
location="us-central1-a")
package main
import (
"fmt"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/organizations"
"github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/tags"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
project, err := organizations.NewProject(ctx, "project", &organizations.ProjectArgs{
ProjectId: pulumi.String("project_id"),
Name: pulumi.String("project_id"),
OrgId: pulumi.String("123456789"),
})
if err != nil {
return err
}
key, err := tags.NewTagKey(ctx, "key", &tags.TagKeyArgs{
Parent: pulumi.String("organizations/123456789"),
ShortName: pulumi.String("keyname"),
Description: pulumi.String("For keyname resources."),
})
if err != nil {
return err
}
value, err := tags.NewTagValue(ctx, "value", &tags.TagValueArgs{
Parent: key.Name.ApplyT(func(name string) (string, error) {
return fmt.Sprintf("tagKeys/%v", name), nil
}).(pulumi.StringOutput),
ShortName: pulumi.String("valuename"),
Description: pulumi.String("For valuename resources."),
})
if err != nil {
return err
}
_, err = tags.NewLocationTagBinding(ctx, "binding", &tags.LocationTagBindingArgs{
Parent: project.Number.ApplyT(func(number string) (string, error) {
return fmt.Sprintf("//compute.googleapis.com/projects/%v/zones/us-central1-a/instances/%v", number, instance.InstanceId), nil
}).(pulumi.StringOutput),
TagValue: value.Name.ApplyT(func(name string) (string, error) {
return fmt.Sprintf("tagValues/%v", name), nil
}).(pulumi.StringOutput),
Location: pulumi.String("us-central1-a"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var project = new Gcp.Organizations.Project("project", new()
{
ProjectId = "project_id",
Name = "project_id",
OrgId = "123456789",
});
var key = new Gcp.Tags.TagKey("key", new()
{
Parent = "organizations/123456789",
ShortName = "keyname",
Description = "For keyname resources.",
});
var @value = new Gcp.Tags.TagValue("value", new()
{
Parent = key.Name.Apply(name => $"tagKeys/{name}"),
ShortName = "valuename",
Description = "For valuename resources.",
});
var binding = new Gcp.Tags.LocationTagBinding("binding", new()
{
Parent = project.Number.Apply(number => $"//compute.googleapis.com/projects/{number}/zones/us-central1-a/instances/{instance.InstanceId}"),
TagValue = @value.Name.Apply(name => $"tagValues/{name}"),
Location = "us-central1-a",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.Project;
import com.pulumi.gcp.organizations.ProjectArgs;
import com.pulumi.gcp.tags.TagKey;
import com.pulumi.gcp.tags.TagKeyArgs;
import com.pulumi.gcp.tags.TagValue;
import com.pulumi.gcp.tags.TagValueArgs;
import com.pulumi.gcp.tags.LocationTagBinding;
import com.pulumi.gcp.tags.LocationTagBindingArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var project = new Project("project", ProjectArgs.builder()
.projectId("project_id")
.name("project_id")
.orgId("123456789")
.build());
var key = new TagKey("key", TagKeyArgs.builder()
.parent("organizations/123456789")
.shortName("keyname")
.description("For keyname resources.")
.build());
var value = new TagValue("value", TagValueArgs.builder()
.parent(key.name().applyValue(name -> String.format("tagKeys/%s", name)))
.shortName("valuename")
.description("For valuename resources.")
.build());
var binding = new LocationTagBinding("binding", LocationTagBindingArgs.builder()
.parent(project.number().applyValue(number -> String.format("//compute.googleapis.com/projects/%s/zones/us-central1-a/instances/%s", number,instance.instanceId())))
.tagValue(value.name().applyValue(name -> String.format("tagValues/%s", name)))
.location("us-central1-a")
.build());
}
}
resources:
project:
type: gcp:organizations:Project
properties:
projectId: project_id
name: project_id
orgId: '123456789'
key:
type: gcp:tags:TagKey
properties:
parent: organizations/123456789
shortName: keyname
description: For keyname resources.
value:
type: gcp:tags:TagValue
properties:
parent: tagKeys/${key.name}
shortName: valuename
description: For valuename resources.
binding:
type: gcp:tags:LocationTagBinding
properties:
parent: //compute.googleapis.com/projects/${project.number}/zones/us-central1-a/instances/${instance.instanceId}
tagValue: tagValues/${value.name}
location: us-central1-a
Create LocationTagBinding Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new LocationTagBinding(name: string, args: LocationTagBindingArgs, opts?: CustomResourceOptions);
@overload
def LocationTagBinding(resource_name: str,
args: LocationTagBindingArgs,
opts: Optional[ResourceOptions] = None)
@overload
def LocationTagBinding(resource_name: str,
opts: Optional[ResourceOptions] = None,
parent: Optional[str] = None,
tag_value: Optional[str] = None,
location: Optional[str] = None)
func NewLocationTagBinding(ctx *Context, name string, args LocationTagBindingArgs, opts ...ResourceOption) (*LocationTagBinding, error)
public LocationTagBinding(string name, LocationTagBindingArgs args, CustomResourceOptions? opts = null)
public LocationTagBinding(String name, LocationTagBindingArgs args)
public LocationTagBinding(String name, LocationTagBindingArgs args, CustomResourceOptions options)
type: gcp:tags:LocationTagBinding
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args LocationTagBindingArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args LocationTagBindingArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args LocationTagBindingArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args LocationTagBindingArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args LocationTagBindingArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var locationTagBindingResource = new Gcp.Tags.LocationTagBinding("locationTagBindingResource", new()
{
Parent = "string",
TagValue = "string",
Location = "string",
});
example, err := tags.NewLocationTagBinding(ctx, "locationTagBindingResource", &tags.LocationTagBindingArgs{
Parent: pulumi.String("string"),
TagValue: pulumi.String("string"),
Location: pulumi.String("string"),
})
var locationTagBindingResource = new LocationTagBinding("locationTagBindingResource", LocationTagBindingArgs.builder()
.parent("string")
.tagValue("string")
.location("string")
.build());
location_tag_binding_resource = gcp.tags.LocationTagBinding("locationTagBindingResource",
parent="string",
tag_value="string",
location="string")
const locationTagBindingResource = new gcp.tags.LocationTagBinding("locationTagBindingResource", {
parent: "string",
tagValue: "string",
location: "string",
});
type: gcp:tags:LocationTagBinding
properties:
location: string
parent: string
tagValue: string
LocationTagBinding Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The LocationTagBinding resource accepts the following input properties:
Outputs
All input properties are implicitly available as output properties. Additionally, the LocationTagBinding resource produces the following output properties:
Look up Existing LocationTagBinding Resource
Get an existing LocationTagBinding resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: LocationTagBindingState, opts?: CustomResourceOptions): LocationTagBinding
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
location: Optional[str] = None,
name: Optional[str] = None,
parent: Optional[str] = None,
tag_value: Optional[str] = None) -> LocationTagBinding
func GetLocationTagBinding(ctx *Context, name string, id IDInput, state *LocationTagBindingState, opts ...ResourceOption) (*LocationTagBinding, error)
public static LocationTagBinding Get(string name, Input<string> id, LocationTagBindingState? state, CustomResourceOptions? opts = null)
public static LocationTagBinding get(String name, Output<String> id, LocationTagBindingState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Location string
- Location of the target resource.
- Name string
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- Parent string
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- Tag
Value string - The TagValue of the TagBinding. Must be of the form tagValues/456.
- Location string
- Location of the target resource.
- Name string
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- Parent string
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- Tag
Value string - The TagValue of the TagBinding. Must be of the form tagValues/456.
- location String
- Location of the target resource.
- name String
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- parent String
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- tag
Value String - The TagValue of the TagBinding. Must be of the form tagValues/456.
- location string
- Location of the target resource.
- name string
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- parent string
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- tag
Value string - The TagValue of the TagBinding. Must be of the form tagValues/456.
- location str
- Location of the target resource.
- name str
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- parent str
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- tag_
value str - The TagValue of the TagBinding. Must be of the form tagValues/456.
- location String
- Location of the target resource.
- name String
- The generated id for the TagBinding. This is a string of the form:
tagBindings/{parent}/{tag-value-name}
- parent String
- The full resource name of the resource the TagValue is bound to. E.g. //cloudresourcemanager.googleapis.com/projects/123
- tag
Value String - The TagValue of the TagBinding. Must be of the form tagValues/456.
Import
LocationTagBinding can be imported using any of these accepted formats:
{{location}}/{{name}}
When using the pulumi import
command, TagBinding can be imported using one of the formats above. For example:
$ pulumi import gcp:tags/locationTagBinding:LocationTagBinding default {{location}}/{{name}}
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- Google Cloud (GCP) Classic pulumi/pulumi-gcp
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
google-beta
Terraform Provider.