1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. ram
  5. getPolicies
Alibaba Cloud v3.88.1 published on Saturday, Nov 8, 2025 by Pulumi
alicloud logo
Alibaba Cloud v3.88.1 published on Saturday, Nov 8, 2025 by Pulumi

    This data source provides the RAM Policies of the current Alibaba Cloud user.

    NOTE: Available since v1.0.0.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    import * as random from "@pulumi/random";
    
    const config = new pulumi.Config();
    const name = config.get("name") || "terraform-example";
    const _default = new random.index.Integer("default", {
        min: 10000,
        max: 99999,
    });
    const defaultPolicy = new alicloud.ram.Policy("default", {
        policyName: `${name}-${_default.result}`,
        description: `${name}-${_default.result}`,
        force: true,
        policyDocument: `  {
        \\"Statement\\": [
          {
            \\"Effect\\": \\"Allow\\",
            \\"Action\\": \\"*\\",
            \\"Resource\\": \\"*\\"
          }
        ],
        \\"Version\\": \\"1\\"
      }
    `,
        tags: {
            Created: "TF",
            For: "Policy",
        },
    });
    const ids = alicloud.ram.getPoliciesOutput({
        ids: [defaultPolicy.id],
    });
    export const ramPoliciesId0 = ids.apply(ids => ids.policies?.[0]?.id);
    
    import pulumi
    import pulumi_alicloud as alicloud
    import pulumi_random as random
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "terraform-example"
    default = random.index.Integer("default",
        min=10000,
        max=99999)
    default_policy = alicloud.ram.Policy("default",
        policy_name=f"{name}-{default['result']}",
        description=f"{name}-{default['result']}",
        force=True,
        policy_document="""  {
        \"Statement\": [
          {
            \"Effect\": \"Allow\",
            \"Action\": \"*\",
            \"Resource\": \"*\"
          }
        ],
        \"Version\": \"1\"
      }
    """,
        tags={
            "Created": "TF",
            "For": "Policy",
        })
    ids = alicloud.ram.get_policies_output(ids=[default_policy.id])
    pulumi.export("ramPoliciesId0", ids.policies[0].id)
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ram"
    	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
    	"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
    		}
    		_default, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
    			Min: 10000,
    			Max: 99999,
    		})
    		if err != nil {
    			return err
    		}
    		defaultPolicy, err := ram.NewPolicy(ctx, "default", &ram.PolicyArgs{
    			PolicyName:  pulumi.Sprintf("%v-%v", name, _default.Result),
    			Description: pulumi.Sprintf("%v-%v", name, _default.Result),
    			Force:       pulumi.Bool(true),
    			PolicyDocument: pulumi.String(`  {
        \"Statement\": [
          {
            \"Effect\": \"Allow\",
            \"Action\": \"*\",
            \"Resource\": \"*\"
          }
        ],
        \"Version\": \"1\"
      }
    `),
    			Tags: pulumi.StringMap{
    				"Created": pulumi.String("TF"),
    				"For":     pulumi.String("Policy"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		ids := ram.GetPoliciesOutput(ctx, ram.GetPoliciesOutputArgs{
    			Ids: pulumi.StringArray{
    				defaultPolicy.ID(),
    			},
    		}, nil)
    		ctx.Export("ramPoliciesId0", ids.ApplyT(func(ids ram.GetPoliciesResult) (*string, error) {
    			return &ids.Policies[0].Id, nil
    		}).(pulumi.StringPtrOutput))
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    using Random = Pulumi.Random;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var name = config.Get("name") ?? "terraform-example";
        var @default = new Random.Index.Integer("default", new()
        {
            Min = 10000,
            Max = 99999,
        });
    
        var defaultPolicy = new AliCloud.Ram.Policy("default", new()
        {
            PolicyName = $"{name}-{@default.Result}",
            Description = $"{name}-{@default.Result}",
            Force = true,
            PolicyDocument = @"  {
        \""Statement\"": [
          {
            \""Effect\"": \""Allow\"",
            \""Action\"": \""*\"",
            \""Resource\"": \""*\""
          }
        ],
        \""Version\"": \""1\""
      }
    ",
            Tags = 
            {
                { "Created", "TF" },
                { "For", "Policy" },
            },
        });
    
        var ids = AliCloud.Ram.GetPolicies.Invoke(new()
        {
            Ids = new[]
            {
                defaultPolicy.Id,
            },
        });
    
        return new Dictionary<string, object?>
        {
            ["ramPoliciesId0"] = ids.Apply(getPoliciesResult => getPoliciesResult.Policies[0]?.Id),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.Integer;
    import com.pulumi.random.IntegerArgs;
    import com.pulumi.alicloud.ram.Policy;
    import com.pulumi.alicloud.ram.PolicyArgs;
    import com.pulumi.alicloud.ram.RamFunctions;
    import com.pulumi.alicloud.ram.inputs.GetPoliciesArgs;
    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 default_ = new Integer("default", IntegerArgs.builder()
                .min(10000)
                .max(99999)
                .build());
    
            var defaultPolicy = new Policy("defaultPolicy", PolicyArgs.builder()
                .policyName(String.format("%s-%s", name,default_.result()))
                .description(String.format("%s-%s", name,default_.result()))
                .force(true)
                .policyDocument("""
      {
        \"Statement\": [
          {
            \"Effect\": \"Allow\",
            \"Action\": \"*\",
            \"Resource\": \"*\"
          }
        ],
        \"Version\": \"1\"
      }
                """)
                .tags(Map.ofEntries(
                    Map.entry("Created", "TF"),
                    Map.entry("For", "Policy")
                ))
                .build());
    
            final var ids = RamFunctions.getPolicies(GetPoliciesArgs.builder()
                .ids(defaultPolicy.id())
                .build());
    
            ctx.export("ramPoliciesId0", ids.applyValue(_ids -> _ids.policies()[0].id()));
        }
    }
    
    configuration:
      name:
        type: string
        default: terraform-example
    resources:
      default:
        type: random:Integer
        properties:
          min: 10000
          max: 99999
      defaultPolicy:
        type: alicloud:ram:Policy
        name: default
        properties:
          policyName: ${name}-${default.result}
          description: ${name}-${default.result}
          force: true
          policyDocument: |2
              {
                \"Statement\": [
                  {
                    \"Effect\": \"Allow\",
                    \"Action\": \"*\",
                    \"Resource\": \"*\"
                  }
                ],
                \"Version\": \"1\"
              }
          tags:
            Created: TF
            For: Policy
    variables:
      ids:
        fn::invoke:
          function: alicloud:ram:getPolicies
          arguments:
            ids:
              - ${defaultPolicy.id}
    outputs:
      ramPoliciesId0: ${ids.policies[0].id}
    

    Using getPolicies

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getPolicies(args: GetPoliciesArgs, opts?: InvokeOptions): Promise<GetPoliciesResult>
    function getPoliciesOutput(args: GetPoliciesOutputArgs, opts?: InvokeOptions): Output<GetPoliciesResult>
    def get_policies(enable_details: Optional[bool] = None,
                     group_name: Optional[str] = None,
                     ids: Optional[Sequence[str]] = None,
                     name_regex: Optional[str] = None,
                     output_file: Optional[str] = None,
                     role_name: Optional[str] = None,
                     tags: Optional[Mapping[str, str]] = None,
                     type: Optional[str] = None,
                     user_name: Optional[str] = None,
                     opts: Optional[InvokeOptions] = None) -> GetPoliciesResult
    def get_policies_output(enable_details: Optional[pulumi.Input[bool]] = None,
                     group_name: Optional[pulumi.Input[str]] = None,
                     ids: Optional[pulumi.Input[Sequence[pulumi.Input[str]]]] = None,
                     name_regex: Optional[pulumi.Input[str]] = None,
                     output_file: Optional[pulumi.Input[str]] = None,
                     role_name: Optional[pulumi.Input[str]] = None,
                     tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                     type: Optional[pulumi.Input[str]] = None,
                     user_name: Optional[pulumi.Input[str]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetPoliciesResult]
    func GetPolicies(ctx *Context, args *GetPoliciesArgs, opts ...InvokeOption) (*GetPoliciesResult, error)
    func GetPoliciesOutput(ctx *Context, args *GetPoliciesOutputArgs, opts ...InvokeOption) GetPoliciesResultOutput

    > Note: This function is named GetPolicies in the Go SDK.

    public static class GetPolicies 
    {
        public static Task<GetPoliciesResult> InvokeAsync(GetPoliciesArgs args, InvokeOptions? opts = null)
        public static Output<GetPoliciesResult> Invoke(GetPoliciesInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetPoliciesResult> getPolicies(GetPoliciesArgs args, InvokeOptions options)
    public static Output<GetPoliciesResult> getPolicies(GetPoliciesArgs args, InvokeOptions options)
    
    fn::invoke:
      function: alicloud:ram/getPolicies:getPolicies
      arguments:
        # arguments dictionary

    The following arguments are supported:

    EnableDetails bool
    Whether to query the detailed list of resource attributes. Default value: true.
    GroupName string
    The name of the user group.
    Ids List<string>
    A list of Policy IDs.
    NameRegex string
    A regex string to filter results by Policy name.
    OutputFile string
    File name where to save data source results (after running pulumi preview).
    RoleName string
    The name of the RAM role.
    Tags Dictionary<string, string>
    A mapping of tags to assign to the resource.
    Type string
    The type of the policy. Valid values: System and Custom.
    UserName string
    The name of the RAM user.
    EnableDetails bool
    Whether to query the detailed list of resource attributes. Default value: true.
    GroupName string
    The name of the user group.
    Ids []string
    A list of Policy IDs.
    NameRegex string
    A regex string to filter results by Policy name.
    OutputFile string
    File name where to save data source results (after running pulumi preview).
    RoleName string
    The name of the RAM role.
    Tags map[string]string
    A mapping of tags to assign to the resource.
    Type string
    The type of the policy. Valid values: System and Custom.
    UserName string
    The name of the RAM user.
    enableDetails Boolean
    Whether to query the detailed list of resource attributes. Default value: true.
    groupName String
    The name of the user group.
    ids List<String>
    A list of Policy IDs.
    nameRegex String
    A regex string to filter results by Policy name.
    outputFile String
    File name where to save data source results (after running pulumi preview).
    roleName String
    The name of the RAM role.
    tags Map<String,String>
    A mapping of tags to assign to the resource.
    type String
    The type of the policy. Valid values: System and Custom.
    userName String
    The name of the RAM user.
    enableDetails boolean
    Whether to query the detailed list of resource attributes. Default value: true.
    groupName string
    The name of the user group.
    ids string[]
    A list of Policy IDs.
    nameRegex string
    A regex string to filter results by Policy name.
    outputFile string
    File name where to save data source results (after running pulumi preview).
    roleName string
    The name of the RAM role.
    tags {[key: string]: string}
    A mapping of tags to assign to the resource.
    type string
    The type of the policy. Valid values: System and Custom.
    userName string
    The name of the RAM user.
    enable_details bool
    Whether to query the detailed list of resource attributes. Default value: true.
    group_name str
    The name of the user group.
    ids Sequence[str]
    A list of Policy IDs.
    name_regex str
    A regex string to filter results by Policy name.
    output_file str
    File name where to save data source results (after running pulumi preview).
    role_name str
    The name of the RAM role.
    tags Mapping[str, str]
    A mapping of tags to assign to the resource.
    type str
    The type of the policy. Valid values: System and Custom.
    user_name str
    The name of the RAM user.
    enableDetails Boolean
    Whether to query the detailed list of resource attributes. Default value: true.
    groupName String
    The name of the user group.
    ids List<String>
    A list of Policy IDs.
    nameRegex String
    A regex string to filter results by Policy name.
    outputFile String
    File name where to save data source results (after running pulumi preview).
    roleName String
    The name of the RAM role.
    tags Map<String>
    A mapping of tags to assign to the resource.
    type String
    The type of the policy. Valid values: System and Custom.
    userName String
    The name of the RAM user.

    getPolicies Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Ids List<string>
    Names List<string>
    (Available since v1.42.0) A list of Policy names.
    Policies List<Pulumi.AliCloud.Ram.Outputs.GetPoliciesPolicy>
    A list of Policy. Each element contains the following attributes:
    EnableDetails bool
    GroupName string
    NameRegex string
    OutputFile string
    RoleName string
    Tags Dictionary<string, string>
    (Available since v1.262.1) The tags of the Policy.
    Type string
    The type of the policy.
    UserName string
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids []string
    Names []string
    (Available since v1.42.0) A list of Policy names.
    Policies []GetPoliciesPolicy
    A list of Policy. Each element contains the following attributes:
    EnableDetails bool
    GroupName string
    NameRegex string
    OutputFile string
    RoleName string
    Tags map[string]string
    (Available since v1.262.1) The tags of the Policy.
    Type string
    The type of the policy.
    UserName string
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    names List<String>
    (Available since v1.42.0) A list of Policy names.
    policies List<GetPoliciesPolicy>
    A list of Policy. Each element contains the following attributes:
    enableDetails Boolean
    groupName String
    nameRegex String
    outputFile String
    roleName String
    tags Map<String,String>
    (Available since v1.262.1) The tags of the Policy.
    type String
    The type of the policy.
    userName String
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    names string[]
    (Available since v1.42.0) A list of Policy names.
    policies GetPoliciesPolicy[]
    A list of Policy. Each element contains the following attributes:
    enableDetails boolean
    groupName string
    nameRegex string
    outputFile string
    roleName string
    tags {[key: string]: string}
    (Available since v1.262.1) The tags of the Policy.
    type string
    The type of the policy.
    userName string
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.
    id str
    The provider-assigned unique ID for this managed resource.
    ids Sequence[str]
    names Sequence[str]
    (Available since v1.42.0) A list of Policy names.
    policies Sequence[GetPoliciesPolicy]
    A list of Policy. Each element contains the following attributes:
    enable_details bool
    group_name str
    name_regex str
    output_file str
    role_name str
    tags Mapping[str, str]
    (Available since v1.262.1) The tags of the Policy.
    type str
    The type of the policy.
    user_name str
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    names List<String>
    (Available since v1.42.0) A list of Policy names.
    policies List<Property Map>
    A list of Policy. Each element contains the following attributes:
    enableDetails Boolean
    groupName String
    nameRegex String
    outputFile String
    roleName String
    tags Map<String>
    (Available since v1.262.1) The tags of the Policy.
    type String
    The type of the policy.
    userName String
    (Removed since v1.262.1) Field user_name has been removed from provider version 1.262.1.

    Supporting Types

    GetPoliciesPolicy

    AttachmentCount int
    The number of references to the policy.
    CreateDate string
    The time when the policy was created.
    DefaultVersion string
    The default version of the policy.
    Description string
    The description of the policy.
    Document string
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    Id string
    (Available since v1.114.0) The ID of the Policy.
    Name string
    The name of the policy.
    PolicyDocument string
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    PolicyName string
    (Available since v1.114.0) The name of the policy.
    Tags Dictionary<string, string>
    A mapping of tags to assign to the resource.
    Type string
    The type of the policy. Valid values: System and Custom.
    UpdateDate string
    The time when the policy was modified.
    UserName string
    The name of the RAM user.
    VersionId string
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.
    AttachmentCount int
    The number of references to the policy.
    CreateDate string
    The time when the policy was created.
    DefaultVersion string
    The default version of the policy.
    Description string
    The description of the policy.
    Document string
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    Id string
    (Available since v1.114.0) The ID of the Policy.
    Name string
    The name of the policy.
    PolicyDocument string
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    PolicyName string
    (Available since v1.114.0) The name of the policy.
    Tags map[string]string
    A mapping of tags to assign to the resource.
    Type string
    The type of the policy. Valid values: System and Custom.
    UpdateDate string
    The time when the policy was modified.
    UserName string
    The name of the RAM user.
    VersionId string
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.
    attachmentCount Integer
    The number of references to the policy.
    createDate String
    The time when the policy was created.
    defaultVersion String
    The default version of the policy.
    description String
    The description of the policy.
    document String
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    id String
    (Available since v1.114.0) The ID of the Policy.
    name String
    The name of the policy.
    policyDocument String
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    policyName String
    (Available since v1.114.0) The name of the policy.
    tags Map<String,String>
    A mapping of tags to assign to the resource.
    type String
    The type of the policy. Valid values: System and Custom.
    updateDate String
    The time when the policy was modified.
    userName String
    The name of the RAM user.
    versionId String
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.
    attachmentCount number
    The number of references to the policy.
    createDate string
    The time when the policy was created.
    defaultVersion string
    The default version of the policy.
    description string
    The description of the policy.
    document string
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    id string
    (Available since v1.114.0) The ID of the Policy.
    name string
    The name of the policy.
    policyDocument string
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    policyName string
    (Available since v1.114.0) The name of the policy.
    tags {[key: string]: string}
    A mapping of tags to assign to the resource.
    type string
    The type of the policy. Valid values: System and Custom.
    updateDate string
    The time when the policy was modified.
    userName string
    The name of the RAM user.
    versionId string
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.
    attachment_count int
    The number of references to the policy.
    create_date str
    The time when the policy was created.
    default_version str
    The default version of the policy.
    description str
    The description of the policy.
    document str
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    id str
    (Available since v1.114.0) The ID of the Policy.
    name str
    The name of the policy.
    policy_document str
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    policy_name str
    (Available since v1.114.0) The name of the policy.
    tags Mapping[str, str]
    A mapping of tags to assign to the resource.
    type str
    The type of the policy. Valid values: System and Custom.
    update_date str
    The time when the policy was modified.
    user_name str
    The name of the RAM user.
    version_id str
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.
    attachmentCount Number
    The number of references to the policy.
    createDate String
    The time when the policy was created.
    defaultVersion String
    The default version of the policy.
    description String
    The description of the policy.
    document String
    The document of the policy. Note: document takes effect only if enable_details is set to true.
    id String
    (Available since v1.114.0) The ID of the Policy.
    name String
    The name of the policy.
    policyDocument String
    (Available since v1.114.0) The document of the policy. Note: policy_document takes effect only if enable_details is set to true.
    policyName String
    (Available since v1.114.0) The name of the policy.
    tags Map<String>
    A mapping of tags to assign to the resource.
    type String
    The type of the policy. Valid values: System and Custom.
    updateDate String
    The time when the policy was modified.
    userName String
    The name of the RAM user.
    versionId String
    (Available since v1.114.0) The ID of the default policy version. Note: version_id takes effect only if enable_details is set to true.

    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.88.1 published on Saturday, Nov 8, 2025 by Pulumi
      Meet Neo: Your AI Platform Teammate