1. Packages
  2. Alibaba Cloud
  3. API Docs
  4. tag
  5. PolicyAttachment
Alibaba Cloud v3.57.1 published on Wednesday, Jun 26, 2024 by Pulumi

alicloud.tag.PolicyAttachment

Explore with Pulumi AI

alicloud logo
Alibaba Cloud v3.57.1 published on Wednesday, Jun 26, 2024 by Pulumi

    Provides a Tag Policy Attachment resource to attaches a policy to an object. After you attach a tag policy to an object. For information about Tag Policy Attachment and how to use it, see What is Policy Attachment.

    NOTE: Available since v1.204.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") || "tf-example";
    const default = alicloud.getAccount({});
    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",
    });
    const examplePolicyAttachment = new alicloud.tag.PolicyAttachment("example", {
        policyId: example.id,
        targetId: _default.then(_default => _default.id),
        targetType: "USER",
    });
    
    import pulumi
    import pulumi_alicloud as alicloud
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "tf-example"
    default = alicloud.get_account()
    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")
    example_policy_attachment = alicloud.tag.PolicyAttachment("example",
        policy_id=example.id,
        target_id=default.id,
        target_type="USER")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
    	"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 := "tf-example"
    		if param := cfg.Get("name"); param != "" {
    			name = param
    		}
    		_default, err := alicloud.GetAccount(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		example, 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
    		}
    		_, err = tag.NewPolicyAttachment(ctx, "example", &tag.PolicyAttachmentArgs{
    			PolicyId:   example.ID(),
    			TargetId:   pulumi.String(_default.Id),
    			TargetType: pulumi.String("USER"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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") ?? "tf-example";
        var @default = AliCloud.GetAccount.Invoke();
    
        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""}}}}
    ",
        });
    
        var examplePolicyAttachment = new AliCloud.Tag.PolicyAttachment("example", new()
        {
            PolicyId = example.Id,
            TargetId = @default.Apply(@default => @default.Apply(getAccountResult => getAccountResult.Id)),
            TargetType = "USER",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.alicloud.AlicloudFunctions;
    import com.pulumi.alicloud.tag.Policy;
    import com.pulumi.alicloud.tag.PolicyArgs;
    import com.pulumi.alicloud.tag.PolicyAttachment;
    import com.pulumi.alicloud.tag.PolicyAttachmentArgs;
    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("tf-example");
            final var default = AlicloudFunctions.getAccount();
    
            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());
    
            var examplePolicyAttachment = new PolicyAttachment("examplePolicyAttachment", PolicyAttachmentArgs.builder()
                .policyId(example.id())
                .targetId(default_.id())
                .targetType("USER")
                .build());
    
        }
    }
    
    configuration:
      name:
        type: string
        default: tf-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"}}}}        
      examplePolicyAttachment:
        type: alicloud:tag:PolicyAttachment
        name: example
        properties:
          policyId: ${example.id}
          targetId: ${default.id}
          targetType: USER
    variables:
      default:
        fn::invoke:
          Function: alicloud:getAccount
          Arguments: {}
    

    Create PolicyAttachment Resource

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

    Constructor syntax

    new PolicyAttachment(name: string, args: PolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def PolicyAttachment(resource_name: str,
                         args: PolicyAttachmentArgs,
                         opts: Optional[ResourceOptions] = None)
    
    @overload
    def PolicyAttachment(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         policy_id: Optional[str] = None,
                         target_id: Optional[str] = None,
                         target_type: Optional[str] = None)
    func NewPolicyAttachment(ctx *Context, name string, args PolicyAttachmentArgs, opts ...ResourceOption) (*PolicyAttachment, error)
    public PolicyAttachment(string name, PolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public PolicyAttachment(String name, PolicyAttachmentArgs args)
    public PolicyAttachment(String name, PolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: alicloud:tag:PolicyAttachment
    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 PolicyAttachmentArgs
    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 PolicyAttachmentArgs
    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 PolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args PolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args PolicyAttachmentArgs
    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 alicloudPolicyAttachmentResource = new AliCloud.Tag.PolicyAttachment("alicloudPolicyAttachmentResource", new()
    {
        PolicyId = "string",
        TargetId = "string",
        TargetType = "string",
    });
    
    example, err := tag.NewPolicyAttachment(ctx, "alicloudPolicyAttachmentResource", &tag.PolicyAttachmentArgs{
    	PolicyId:   pulumi.String("string"),
    	TargetId:   pulumi.String("string"),
    	TargetType: pulumi.String("string"),
    })
    
    var alicloudPolicyAttachmentResource = new PolicyAttachment("alicloudPolicyAttachmentResource", PolicyAttachmentArgs.builder()
        .policyId("string")
        .targetId("string")
        .targetType("string")
        .build());
    
    alicloud_policy_attachment_resource = alicloud.tag.PolicyAttachment("alicloudPolicyAttachmentResource",
        policy_id="string",
        target_id="string",
        target_type="string")
    
    const alicloudPolicyAttachmentResource = new alicloud.tag.PolicyAttachment("alicloudPolicyAttachmentResource", {
        policyId: "string",
        targetId: "string",
        targetType: "string",
    });
    
    type: alicloud:tag:PolicyAttachment
    properties:
        policyId: string
        targetId: string
        targetType: string
    

    PolicyAttachment 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 PolicyAttachment resource accepts the following input properties:

    PolicyId string
    The ID of the tag policy.
    TargetId string
    The ID of the object.
    TargetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    PolicyId string
    The ID of the tag policy.
    TargetId string
    The ID of the object.
    TargetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId String
    The ID of the tag policy.
    targetId String
    The ID of the object.
    targetType String
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId string
    The ID of the tag policy.
    targetId string
    The ID of the object.
    targetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policy_id str
    The ID of the tag policy.
    target_id str
    The ID of the object.
    target_type str
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId String
    The ID of the tag policy.
    targetId String
    The ID of the object.
    targetType String
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the PolicyAttachment 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 PolicyAttachment Resource

    Get an existing PolicyAttachment 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?: PolicyAttachmentState, opts?: CustomResourceOptions): PolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy_id: Optional[str] = None,
            target_id: Optional[str] = None,
            target_type: Optional[str] = None) -> PolicyAttachment
    func GetPolicyAttachment(ctx *Context, name string, id IDInput, state *PolicyAttachmentState, opts ...ResourceOption) (*PolicyAttachment, error)
    public static PolicyAttachment Get(string name, Input<string> id, PolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static PolicyAttachment get(String name, Output<String> id, PolicyAttachmentState 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.
    The following state arguments are supported:
    PolicyId string
    The ID of the tag policy.
    TargetId string
    The ID of the object.
    TargetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    PolicyId string
    The ID of the tag policy.
    TargetId string
    The ID of the object.
    TargetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId String
    The ID of the tag policy.
    targetId String
    The ID of the object.
    targetType String
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId string
    The ID of the tag policy.
    targetId string
    The ID of the object.
    targetType string
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policy_id str
    The ID of the tag policy.
    target_id str
    The ID of the object.
    target_type str
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.
    policyId String
    The ID of the tag policy.
    targetId String
    The ID of the object.
    targetType String
    The type of the object. Valid values: USER, ROOT, FOLDER, ACCOUNT.

    Import

    Tag Policy Attachment can be imported using the id, e.g.

    $ pulumi import alicloud:tag/policyAttachment:PolicyAttachment example <policy_id>:<target_id>:<target_type>
    

    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.
    alicloud logo
    Alibaba Cloud v3.57.1 published on Wednesday, Jun 26, 2024 by Pulumi