1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. tag
  5. Policy
Alibaba Cloud v3.76.0 published on Tuesday, Apr 8, 2025 by Pulumi

alicloud.tag.Policy

Explore with Pulumi AI

Provides a TAG Policy resource.

For information about TAG Policy and how to use it, see What is Policy.

NOTE: Available since v1.203.0.

Example Usage

Basic Usage

import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
const example = new alicloud.tag.Policy("example", {
    policyName: name,
    policyDesc: name,
    userType: "USER",
    policyContent: "\x09\x09{\"tags\":{\"CostCenter\":{\"tag_value\":{\"@@assign\":[\"Beijing\",\"Shanghai\"]},\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}\n",
});
Copy
import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
name = config.get("name")
if name is None:
    name = "terraform-example"
example = alicloud.tag.Policy("example",
    policy_name=name,
    policy_desc=name,
    user_type="USER",
    policy_content="\x09\x09{\"tags\":{\"CostCenter\":{\"tag_value\":{\"@@assign\":[\"Beijing\",\"Shanghai\"]},\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}\n")
Copy
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/tag"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		name := "terraform-example"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		_, err := tag.NewPolicy(ctx, "example", &tag.PolicyArgs{
			PolicyName:    pulumi.String(name),
			PolicyDesc:    pulumi.String(name),
			UserType:      pulumi.String("USER"),
			PolicyContent: pulumi.String("		{\"tags\":{\"CostCenter\":{\"tag_value\":{\"@@assign\":[\"Beijing\",\"Shanghai\"]},\"tag_key\":{\"@@assign\":\"CostCenter\"}}}}\n"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

return await Deployment.RunAsync(() => 
{
    var config = new Config();
    var name = config.Get("name") ?? "terraform-example";
    var example = new AliCloud.Tag.Policy("example", new()
    {
        PolicyName = name,
        PolicyDesc = name,
        UserType = "USER",
        PolicyContent = @"		{""tags"":{""CostCenter"":{""tag_value"":{""@@assign"":[""Beijing"",""Shanghai""]},""tag_key"":{""@@assign"":""CostCenter""}}}}
",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.tag.Policy;
import com.pulumi.alicloud.tag.PolicyArgs;
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) {
        final var config = ctx.config();
        final var name = config.get("name").orElse("terraform-example");
        var example = new Policy("example", PolicyArgs.builder()
            .policyName(name)
            .policyDesc(name)
            .userType("USER")
            .policyContent("""
		{"tags":{"CostCenter":{"tag_value":{"@@assign":["Beijing","Shanghai"]},"tag_key":{"@@assign":"CostCenter"}}}}
            """)
            .build());

    }
}
Copy
configuration:
  name:
    type: string
    default: terraform-example
resources:
  example:
    type: alicloud:tag:Policy
    properties:
      policyName: ${name}
      policyDesc: ${name}
      userType: USER
      policyContent: |
        		{"tags":{"CostCenter":{"tag_value":{"@@assign":["Beijing","Shanghai"]},"tag_key":{"@@assign":"CostCenter"}}}}        
Copy

Create Policy Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new Policy(name: string, args: PolicyArgs, opts?: CustomResourceOptions);
@overload
def Policy(resource_name: str,
           args: PolicyArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def Policy(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           policy_content: Optional[str] = None,
           policy_name: Optional[str] = None,
           policy_desc: Optional[str] = None,
           user_type: Optional[str] = None)
func NewPolicy(ctx *Context, name string, args PolicyArgs, opts ...ResourceOption) (*Policy, error)
public Policy(string name, PolicyArgs args, CustomResourceOptions? opts = null)
public Policy(String name, PolicyArgs args)
public Policy(String name, PolicyArgs args, CustomResourceOptions options)
type: alicloud:tag:Policy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. PolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. PolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. PolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. PolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. PolicyArgs
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 examplepolicyResourceResourceFromTagpolicy = new AliCloud.Tag.Policy("examplepolicyResourceResourceFromTagpolicy", new()
{
    PolicyContent = "string",
    PolicyName = "string",
    PolicyDesc = "string",
    UserType = "string",
});
Copy
example, err := tag.NewPolicy(ctx, "examplepolicyResourceResourceFromTagpolicy", &tag.PolicyArgs{
	PolicyContent: pulumi.String("string"),
	PolicyName:    pulumi.String("string"),
	PolicyDesc:    pulumi.String("string"),
	UserType:      pulumi.String("string"),
})
Copy
var examplepolicyResourceResourceFromTagpolicy = new Policy("examplepolicyResourceResourceFromTagpolicy", PolicyArgs.builder()
    .policyContent("string")
    .policyName("string")
    .policyDesc("string")
    .userType("string")
    .build());
Copy
examplepolicy_resource_resource_from_tagpolicy = alicloud.tag.Policy("examplepolicyResourceResourceFromTagpolicy",
    policy_content="string",
    policy_name="string",
    policy_desc="string",
    user_type="string")
Copy
const examplepolicyResourceResourceFromTagpolicy = new alicloud.tag.Policy("examplepolicyResourceResourceFromTagpolicy", {
    policyContent: "string",
    policyName: "string",
    policyDesc: "string",
    userType: "string",
});
Copy
type: alicloud:tag:Policy
properties:
    policyContent: string
    policyDesc: string
    policyName: string
    userType: string
Copy

Policy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The Policy resource accepts the following input properties:

PolicyContent This property is required. string
The document of the tag policy.
PolicyName This property is required. string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
PolicyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
UserType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
PolicyContent This property is required. string
The document of the tag policy.
PolicyName This property is required. string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
PolicyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
UserType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent This property is required. String
The document of the tag policy.
policyName This property is required. String
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
policyDesc String
The description of the policy. The description must be 1 to 512 characters in length.
userType Changes to this property will trigger replacement. String
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent This property is required. string
The document of the tag policy.
policyName This property is required. string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
policyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
userType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
policy_content This property is required. str
The document of the tag policy.
policy_name This property is required. str
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
policy_desc str
The description of the policy. The description must be 1 to 512 characters in length.
user_type Changes to this property will trigger replacement. str
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent This property is required. String
The document of the tag policy.
policyName This property is required. String
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
policyDesc String
The description of the policy. The description must be 1 to 512 characters in length.
userType Changes to this property will trigger replacement. String
The mode of the Tag Policy feature. Valid values: USER, RD.

Outputs

All input properties are implicitly available as output properties. Additionally, the Policy resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing Policy Resource

Get an existing Policy 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?: PolicyState, opts?: CustomResourceOptions): Policy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy_content: Optional[str] = None,
        policy_desc: Optional[str] = None,
        policy_name: Optional[str] = None,
        user_type: Optional[str] = None) -> Policy
func GetPolicy(ctx *Context, name string, id IDInput, state *PolicyState, opts ...ResourceOption) (*Policy, error)
public static Policy Get(string name, Input<string> id, PolicyState? state, CustomResourceOptions? opts = null)
public static Policy get(String name, Output<String> id, PolicyState state, CustomResourceOptions options)
resources:  _:    type: alicloud:tag:Policy    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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.
The following state arguments are supported:
PolicyContent string
The document of the tag policy.
PolicyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
PolicyName string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
UserType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
PolicyContent string
The document of the tag policy.
PolicyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
PolicyName string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
UserType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent String
The document of the tag policy.
policyDesc String
The description of the policy. The description must be 1 to 512 characters in length.
policyName String
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
userType Changes to this property will trigger replacement. String
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent string
The document of the tag policy.
policyDesc string
The description of the policy. The description must be 1 to 512 characters in length.
policyName string
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
userType Changes to this property will trigger replacement. string
The mode of the Tag Policy feature. Valid values: USER, RD.
policy_content str
The document of the tag policy.
policy_desc str
The description of the policy. The description must be 1 to 512 characters in length.
policy_name str
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
user_type Changes to this property will trigger replacement. str
The mode of the Tag Policy feature. Valid values: USER, RD.
policyContent String
The document of the tag policy.
policyDesc String
The description of the policy. The description must be 1 to 512 characters in length.
policyName String
The name of the tag policy. The name must be 1 to 128 characters in length and can contain letters, digits, and underscores (_).
userType Changes to this property will trigger replacement. String
The mode of the Tag Policy feature. Valid values: USER, RD.

Import

TAG Policy can be imported using the id, e.g.

$ pulumi import alicloud:tag/policy:Policy example <id>
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.