1. Packages
  2. Tencentcloud Provider
  3. API Docs
  4. CamUserPolicyAttachment
tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack

tencentcloud.CamUserPolicyAttachment

Explore with Pulumi AI

tencentcloud logo
tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack

    Provides a resource to create a CAM user policy attachment.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as tencentcloud from "@pulumi/tencentcloud";
    
    const config = new pulumi.Config();
    const camUserBasic = config.get("camUserBasic") || "keep-cam-user";
    const policyBasic = new tencentcloud.CamPolicy("policyBasic", {
        document: JSON.stringify({
            version: "2.0",
            statement: [
                {
                    action: ["cos:*"],
                    resource: ["*"],
                    effect: "allow",
                },
                {
                    effect: "allow",
                    action: [
                        "monitor:*",
                        "cam:ListUsersForGroup",
                        "cam:ListGroups",
                        "cam:GetGroup",
                    ],
                    resource: ["*"],
                },
            ],
        }),
        description: "tf_test",
    });
    const users = tencentcloud.getCamUsers({
        name: camUserBasic,
    });
    const userPolicyAttachmentBasic = new tencentcloud.CamUserPolicyAttachment("userPolicyAttachmentBasic", {
        userName: users.then(users => users.userLists?.[0]?.userId),
        policyId: policyBasic.camPolicyId,
    });
    
    import pulumi
    import json
    import pulumi_tencentcloud as tencentcloud
    
    config = pulumi.Config()
    cam_user_basic = config.get("camUserBasic")
    if cam_user_basic is None:
        cam_user_basic = "keep-cam-user"
    policy_basic = tencentcloud.CamPolicy("policyBasic",
        document=json.dumps({
            "version": "2.0",
            "statement": [
                {
                    "action": ["cos:*"],
                    "resource": ["*"],
                    "effect": "allow",
                },
                {
                    "effect": "allow",
                    "action": [
                        "monitor:*",
                        "cam:ListUsersForGroup",
                        "cam:ListGroups",
                        "cam:GetGroup",
                    ],
                    "resource": ["*"],
                },
            ],
        }),
        description="tf_test")
    users = tencentcloud.get_cam_users(name=cam_user_basic)
    user_policy_attachment_basic = tencentcloud.CamUserPolicyAttachment("userPolicyAttachmentBasic",
        user_name=users.user_lists[0].user_id,
        policy_id=policy_basic.cam_policy_id)
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/tencentcloud/tencentcloud"
    	"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, "")
    		camUserBasic := "keep-cam-user"
    		if param := cfg.Get("camUserBasic"); param != "" {
    			camUserBasic = param
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"version": "2.0",
    			"statement": []map[string]interface{}{
    				map[string]interface{}{
    					"action": []string{
    						"cos:*",
    					},
    					"resource": []string{
    						"*",
    					},
    					"effect": "allow",
    				},
    				map[string]interface{}{
    					"effect": "allow",
    					"action": []string{
    						"monitor:*",
    						"cam:ListUsersForGroup",
    						"cam:ListGroups",
    						"cam:GetGroup",
    					},
    					"resource": []string{
    						"*",
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		policyBasic, err := tencentcloud.NewCamPolicy(ctx, "policyBasic", &tencentcloud.CamPolicyArgs{
    			Document:    pulumi.String(json0),
    			Description: pulumi.String("tf_test"),
    		})
    		if err != nil {
    			return err
    		}
    		users, err := tencentcloud.GetCamUsers(ctx, &tencentcloud.GetCamUsersArgs{
    			Name: pulumi.StringRef(camUserBasic),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = tencentcloud.NewCamUserPolicyAttachment(ctx, "userPolicyAttachmentBasic", &tencentcloud.CamUserPolicyAttachmentArgs{
    			UserName: pulumi.String(users.UserLists[0].UserId),
    			PolicyId: policyBasic.CamPolicyId,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Tencentcloud = Pulumi.Tencentcloud;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var camUserBasic = config.Get("camUserBasic") ?? "keep-cam-user";
        var policyBasic = new Tencentcloud.CamPolicy("policyBasic", new()
        {
            Document = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["version"] = "2.0",
                ["statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["action"] = new[]
                        {
                            "cos:*",
                        },
                        ["resource"] = new[]
                        {
                            "*",
                        },
                        ["effect"] = "allow",
                    },
                    new Dictionary<string, object?>
                    {
                        ["effect"] = "allow",
                        ["action"] = new[]
                        {
                            "monitor:*",
                            "cam:ListUsersForGroup",
                            "cam:ListGroups",
                            "cam:GetGroup",
                        },
                        ["resource"] = new[]
                        {
                            "*",
                        },
                    },
                },
            }),
            Description = "tf_test",
        });
    
        var users = Tencentcloud.GetCamUsers.Invoke(new()
        {
            Name = camUserBasic,
        });
    
        var userPolicyAttachmentBasic = new Tencentcloud.CamUserPolicyAttachment("userPolicyAttachmentBasic", new()
        {
            UserName = users.Apply(getCamUsersResult => getCamUsersResult.UserLists[0]?.UserId),
            PolicyId = policyBasic.CamPolicyId,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.tencentcloud.CamPolicy;
    import com.pulumi.tencentcloud.CamPolicyArgs;
    import com.pulumi.tencentcloud.TencentcloudFunctions;
    import com.pulumi.tencentcloud.inputs.GetCamUsersArgs;
    import com.pulumi.tencentcloud.CamUserPolicyAttachment;
    import com.pulumi.tencentcloud.CamUserPolicyAttachmentArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    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 camUserBasic = config.get("camUserBasic").orElse("keep-cam-user");
            var policyBasic = new CamPolicy("policyBasic", CamPolicyArgs.builder()
                .document(serializeJson(
                    jsonObject(
                        jsonProperty("version", "2.0"),
                        jsonProperty("statement", jsonArray(
                            jsonObject(
                                jsonProperty("action", jsonArray("cos:*")),
                                jsonProperty("resource", jsonArray("*")),
                                jsonProperty("effect", "allow")
                            ), 
                            jsonObject(
                                jsonProperty("effect", "allow"),
                                jsonProperty("action", jsonArray(
                                    "monitor:*", 
                                    "cam:ListUsersForGroup", 
                                    "cam:ListGroups", 
                                    "cam:GetGroup"
                                )),
                                jsonProperty("resource", jsonArray("*"))
                            )
                        ))
                    )))
                .description("tf_test")
                .build());
    
            final var users = TencentcloudFunctions.getCamUsers(GetCamUsersArgs.builder()
                .name(camUserBasic)
                .build());
    
            var userPolicyAttachmentBasic = new CamUserPolicyAttachment("userPolicyAttachmentBasic", CamUserPolicyAttachmentArgs.builder()
                .userName(users.applyValue(getCamUsersResult -> getCamUsersResult.userLists()[0].userId()))
                .policyId(policyBasic.camPolicyId())
                .build());
    
        }
    }
    
    configuration:
      camUserBasic:
        type: string
        default: keep-cam-user
    resources:
      policyBasic:
        type: tencentcloud:CamPolicy
        properties:
          document:
            fn::toJSON:
              version: '2.0'
              statement:
                - action:
                    - cos:*
                  resource:
                    - '*'
                  effect: allow
                - effect: allow
                  action:
                    - monitor:*
                    - cam:ListUsersForGroup
                    - cam:ListGroups
                    - cam:GetGroup
                  resource:
                    - '*'
          description: tf_test
      userPolicyAttachmentBasic:
        type: tencentcloud:CamUserPolicyAttachment
        properties:
          userName: ${users.userLists[0].userId}
          policyId: ${policyBasic.camPolicyId}
    variables:
      users:
        fn::invoke:
          function: tencentcloud:getCamUsers
          arguments:
            name: ${camUserBasic}
    

    Create CamUserPolicyAttachment Resource

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

    Constructor syntax

    new CamUserPolicyAttachment(name: string, args: CamUserPolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def CamUserPolicyAttachment(resource_name: str,
                                args: CamUserPolicyAttachmentArgs,
                                opts: Optional[ResourceOptions] = None)
    
    @overload
    def CamUserPolicyAttachment(resource_name: str,
                                opts: Optional[ResourceOptions] = None,
                                policy_id: Optional[str] = None,
                                cam_user_policy_attachment_id: Optional[str] = None,
                                user_id: Optional[str] = None,
                                user_name: Optional[str] = None)
    func NewCamUserPolicyAttachment(ctx *Context, name string, args CamUserPolicyAttachmentArgs, opts ...ResourceOption) (*CamUserPolicyAttachment, error)
    public CamUserPolicyAttachment(string name, CamUserPolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public CamUserPolicyAttachment(String name, CamUserPolicyAttachmentArgs args)
    public CamUserPolicyAttachment(String name, CamUserPolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: tencentcloud:CamUserPolicyAttachment
    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 CamUserPolicyAttachmentArgs
    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 CamUserPolicyAttachmentArgs
    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 CamUserPolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args CamUserPolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args CamUserPolicyAttachmentArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

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

    PolicyId string
    ID of the policy.
    CamUserPolicyAttachmentId string
    ID of the resource.
    UserId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    UserName string
    Name of the attached CAM user as uniq key.
    PolicyId string
    ID of the policy.
    CamUserPolicyAttachmentId string
    ID of the resource.
    UserId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    UserName string
    Name of the attached CAM user as uniq key.
    policyId String
    ID of the policy.
    camUserPolicyAttachmentId String
    ID of the resource.
    userId String
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName String
    Name of the attached CAM user as uniq key.
    policyId string
    ID of the policy.
    camUserPolicyAttachmentId string
    ID of the resource.
    userId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName string
    Name of the attached CAM user as uniq key.
    policy_id str
    ID of the policy.
    cam_user_policy_attachment_id str
    ID of the resource.
    user_id str
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    user_name str
    Name of the attached CAM user as uniq key.
    policyId String
    ID of the policy.
    camUserPolicyAttachmentId String
    ID of the resource.
    userId String
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName String
    Name of the attached CAM user as uniq key.

    Outputs

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

    CreateMode double
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    CreateTime string
    Create time of the CAM user policy attachment.
    Id string
    The provider-assigned unique ID for this managed resource.
    PolicyName string
    Name of the policy.
    PolicyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    CreateMode float64
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    CreateTime string
    Create time of the CAM user policy attachment.
    Id string
    The provider-assigned unique ID for this managed resource.
    PolicyName string
    Name of the policy.
    PolicyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    createMode Double
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime String
    Create time of the CAM user policy attachment.
    id String
    The provider-assigned unique ID for this managed resource.
    policyName String
    Name of the policy.
    policyType String
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    createMode number
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime string
    Create time of the CAM user policy attachment.
    id string
    The provider-assigned unique ID for this managed resource.
    policyName string
    Name of the policy.
    policyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    create_mode float
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    create_time str
    Create time of the CAM user policy attachment.
    id str
    The provider-assigned unique ID for this managed resource.
    policy_name str
    Name of the policy.
    policy_type str
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    createMode Number
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime String
    Create time of the CAM user policy attachment.
    id String
    The provider-assigned unique ID for this managed resource.
    policyName String
    Name of the policy.
    policyType String
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.

    Look up Existing CamUserPolicyAttachment Resource

    Get an existing CamUserPolicyAttachment 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?: CamUserPolicyAttachmentState, opts?: CustomResourceOptions): CamUserPolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            cam_user_policy_attachment_id: Optional[str] = None,
            create_mode: Optional[float] = None,
            create_time: Optional[str] = None,
            policy_id: Optional[str] = None,
            policy_name: Optional[str] = None,
            policy_type: Optional[str] = None,
            user_id: Optional[str] = None,
            user_name: Optional[str] = None) -> CamUserPolicyAttachment
    func GetCamUserPolicyAttachment(ctx *Context, name string, id IDInput, state *CamUserPolicyAttachmentState, opts ...ResourceOption) (*CamUserPolicyAttachment, error)
    public static CamUserPolicyAttachment Get(string name, Input<string> id, CamUserPolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static CamUserPolicyAttachment get(String name, Output<String> id, CamUserPolicyAttachmentState state, CustomResourceOptions options)
    resources:  _:    type: tencentcloud:CamUserPolicyAttachment    get:      id: ${id}
    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:
    CamUserPolicyAttachmentId string
    ID of the resource.
    CreateMode double
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    CreateTime string
    Create time of the CAM user policy attachment.
    PolicyId string
    ID of the policy.
    PolicyName string
    Name of the policy.
    PolicyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    UserId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    UserName string
    Name of the attached CAM user as uniq key.
    CamUserPolicyAttachmentId string
    ID of the resource.
    CreateMode float64
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    CreateTime string
    Create time of the CAM user policy attachment.
    PolicyId string
    ID of the policy.
    PolicyName string
    Name of the policy.
    PolicyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    UserId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    UserName string
    Name of the attached CAM user as uniq key.
    camUserPolicyAttachmentId String
    ID of the resource.
    createMode Double
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime String
    Create time of the CAM user policy attachment.
    policyId String
    ID of the policy.
    policyName String
    Name of the policy.
    policyType String
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    userId String
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName String
    Name of the attached CAM user as uniq key.
    camUserPolicyAttachmentId string
    ID of the resource.
    createMode number
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime string
    Create time of the CAM user policy attachment.
    policyId string
    ID of the policy.
    policyName string
    Name of the policy.
    policyType string
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    userId string
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName string
    Name of the attached CAM user as uniq key.
    cam_user_policy_attachment_id str
    ID of the resource.
    create_mode float
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    create_time str
    Create time of the CAM user policy attachment.
    policy_id str
    ID of the policy.
    policy_name str
    Name of the policy.
    policy_type str
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    user_id str
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    user_name str
    Name of the attached CAM user as uniq key.
    camUserPolicyAttachmentId String
    ID of the resource.
    createMode Number
    Mode of Creation of the CAM user policy attachment. 1 means the CAM policy attachment is created by production, and the others indicate syntax strategy ways.
    createTime String
    Create time of the CAM user policy attachment.
    policyId String
    ID of the policy.
    policyName String
    Name of the policy.
    policyType String
    Type of the policy strategy. User means customer strategy and QCS means preset strategy.
    userId String
    It has been deprecated from version 1.59.5. Use user_name instead. ID of the attached CAM user.

    Deprecated: Deprecated

    userName String
    Name of the attached CAM user as uniq key.

    Import

    CAM user policy attachment can be imported using the id, e.g.

    $ pulumi import tencentcloud:index/camUserPolicyAttachment:CamUserPolicyAttachment foo cam-test#26800353
    

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

    Package Details

    Repository
    tencentcloud tencentcloudstack/terraform-provider-tencentcloud
    License
    Notes
    This Pulumi package is based on the tencentcloud Terraform Provider.
    tencentcloud logo
    tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack