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

alicloud.ram.getPolicies

Explore with Pulumi AI

Alibaba Cloud v3.76.0 published on Tuesday, Apr 8, 2025 by Pulumi

This data source provides a list of RAM policies in an Alibaba Cloud account according to the specified filters.

NOTE: Available since v1.0.0+.

Example Usage

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

const _default = new random.index.Integer("default", {
    min: 10000,
    max: 99999,
});
const group = new alicloud.ram.Group("group", {
    name: `groupName-${_default.result}`,
    comments: "this is a group comments.",
});
const policy = new alicloud.ram.Policy("policy", {
    policyName: `tf-example-${_default.result}`,
    policyDocument: `    {
      "Statement": [
        {
          "Action": [
            "oss:ListObjects",
            "oss:GetObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "acs:oss:*:*:mybucket",
            "acs:oss:*:*:mybucket/*"
          ]
        }
      ],
        "Version": "1"
    }
`,
    description: "this is a policy test",
});
const attach = new alicloud.ram.GroupPolicyAttachment("attach", {
    policyName: policy.policyName,
    policyType: policy.type,
    groupName: group.name,
});
const policiesDs = alicloud.ram.getPoliciesOutput({
    groupName: attach.groupName,
    type: "Custom",
});
export const firstPolicyName = policiesDs.apply(policiesDs => policiesDs.policies?.[0]?.name);
Copy
import pulumi
import pulumi_alicloud as alicloud
import pulumi_random as random

default = random.index.Integer("default",
    min=10000,
    max=99999)
group = alicloud.ram.Group("group",
    name=f"groupName-{default['result']}",
    comments="this is a group comments.")
policy = alicloud.ram.Policy("policy",
    policy_name=f"tf-example-{default['result']}",
    policy_document="""    {
      "Statement": [
        {
          "Action": [
            "oss:ListObjects",
            "oss:GetObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "acs:oss:*:*:mybucket",
            "acs:oss:*:*:mybucket/*"
          ]
        }
      ],
        "Version": "1"
    }
""",
    description="this is a policy test")
attach = alicloud.ram.GroupPolicyAttachment("attach",
    policy_name=policy.policy_name,
    policy_type=policy.type,
    group_name=group.name)
policies_ds = alicloud.ram.get_policies_output(group_name=attach.group_name,
    type="Custom")
pulumi.export("firstPolicyName", policies_ds.policies[0].name)
Copy
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"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_default, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
			Min: 10000,
			Max: 99999,
		})
		if err != nil {
			return err
		}
		group, err := ram.NewGroup(ctx, "group", &ram.GroupArgs{
			Name:     pulumi.Sprintf("groupName-%v", _default.Result),
			Comments: pulumi.String("this is a group comments."),
		})
		if err != nil {
			return err
		}
		policy, err := ram.NewPolicy(ctx, "policy", &ram.PolicyArgs{
			PolicyName: pulumi.Sprintf("tf-example-%v", _default.Result),
			PolicyDocument: pulumi.String(`    {
      "Statement": [
        {
          "Action": [
            "oss:ListObjects",
            "oss:GetObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "acs:oss:*:*:mybucket",
            "acs:oss:*:*:mybucket/*"
          ]
        }
      ],
        "Version": "1"
    }
`),
			Description: pulumi.String("this is a policy test"),
		})
		if err != nil {
			return err
		}
		attach, err := ram.NewGroupPolicyAttachment(ctx, "attach", &ram.GroupPolicyAttachmentArgs{
			PolicyName: policy.PolicyName,
			PolicyType: policy.Type,
			GroupName:  group.Name,
		})
		if err != nil {
			return err
		}
		policiesDs := ram.GetPoliciesOutput(ctx, ram.GetPoliciesOutputArgs{
			GroupName: attach.GroupName,
			Type:      pulumi.String("Custom"),
		}, nil)
		ctx.Export("firstPolicyName", policiesDs.ApplyT(func(policiesDs ram.GetPoliciesResult) (*string, error) {
			return &policiesDs.Policies[0].Name, nil
		}).(pulumi.StringPtrOutput))
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
using Random = Pulumi.Random;

return await Deployment.RunAsync(() => 
{
    var @default = new Random.Index.Integer("default", new()
    {
        Min = 10000,
        Max = 99999,
    });

    var @group = new AliCloud.Ram.Group("group", new()
    {
        Name = $"groupName-{@default.Result}",
        Comments = "this is a group comments.",
    });

    var policy = new AliCloud.Ram.Policy("policy", new()
    {
        PolicyName = $"tf-example-{@default.Result}",
        PolicyDocument = @"    {
      ""Statement"": [
        {
          ""Action"": [
            ""oss:ListObjects"",
            ""oss:GetObject""
          ],
          ""Effect"": ""Allow"",
          ""Resource"": [
            ""acs:oss:*:*:mybucket"",
            ""acs:oss:*:*:mybucket/*""
          ]
        }
      ],
        ""Version"": ""1""
    }
",
        Description = "this is a policy test",
    });

    var attach = new AliCloud.Ram.GroupPolicyAttachment("attach", new()
    {
        PolicyName = policy.PolicyName,
        PolicyType = policy.Type,
        GroupName = @group.Name,
    });

    var policiesDs = AliCloud.Ram.GetPolicies.Invoke(new()
    {
        GroupName = attach.GroupName,
        Type = "Custom",
    });

    return new Dictionary<string, object?>
    {
        ["firstPolicyName"] = policiesDs.Apply(getPoliciesResult => getPoliciesResult.Policies[0]?.Name),
    };
});
Copy
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.Group;
import com.pulumi.alicloud.ram.GroupArgs;
import com.pulumi.alicloud.ram.Policy;
import com.pulumi.alicloud.ram.PolicyArgs;
import com.pulumi.alicloud.ram.GroupPolicyAttachment;
import com.pulumi.alicloud.ram.GroupPolicyAttachmentArgs;
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) {
        var default_ = new Integer("default", IntegerArgs.builder()
            .min(10000)
            .max(99999)
            .build());

        var group = new Group("group", GroupArgs.builder()
            .name(String.format("groupName-%s", default_.result()))
            .comments("this is a group comments.")
            .build());

        var policy = new Policy("policy", PolicyArgs.builder()
            .policyName(String.format("tf-example-%s", default_.result()))
            .policyDocument("""
    {
      "Statement": [
        {
          "Action": [
            "oss:ListObjects",
            "oss:GetObject"
          ],
          "Effect": "Allow",
          "Resource": [
            "acs:oss:*:*:mybucket",
            "acs:oss:*:*:mybucket/*"
          ]
        }
      ],
        "Version": "1"
    }
            """)
            .description("this is a policy test")
            .build());

        var attach = new GroupPolicyAttachment("attach", GroupPolicyAttachmentArgs.builder()
            .policyName(policy.policyName())
            .policyType(policy.type())
            .groupName(group.name())
            .build());

        final var policiesDs = RamFunctions.getPolicies(GetPoliciesArgs.builder()
            .groupName(attach.groupName())
            .type("Custom")
            .build());

        ctx.export("firstPolicyName", policiesDs.applyValue(getPoliciesResult -> getPoliciesResult).applyValue(policiesDs -> policiesDs.applyValue(getPoliciesResult -> getPoliciesResult.policies()[0].name())));
    }
}
Copy
resources:
  group:
    type: alicloud:ram:Group
    properties:
      name: groupName-${default.result}
      comments: this is a group comments.
  default:
    type: random:integer
    properties:
      min: 10000
      max: 99999
  policy:
    type: alicloud:ram:Policy
    properties:
      policyName: tf-example-${default.result}
      policyDocument: |2
            {
              "Statement": [
                {
                  "Action": [
                    "oss:ListObjects",
                    "oss:GetObject"
                  ],
                  "Effect": "Allow",
                  "Resource": [
                    "acs:oss:*:*:mybucket",
                    "acs:oss:*:*:mybucket/*"
                  ]
                }
              ],
                "Version": "1"
            }
      description: this is a policy test
  attach:
    type: alicloud:ram:GroupPolicyAttachment
    properties:
      policyName: ${policy.policyName}
      policyType: ${policy.type}
      groupName: ${group.name}
variables:
  policiesDs:
    fn::invoke:
      function: alicloud:ram:getPolicies
      arguments:
        groupName: ${attach.groupName}
        type: Custom
outputs:
  firstPolicyName: ${policiesDs.policies[0].name}
Copy

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>
Copy
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,
                 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,
                 type: Optional[pulumi.Input[str]] = None,
                 user_name: Optional[pulumi.Input[str]] = None,
                 opts: Optional[InvokeOptions] = None) -> Output[GetPoliciesResult]
Copy
func GetPolicies(ctx *Context, args *GetPoliciesArgs, opts ...InvokeOption) (*GetPoliciesResult, error)
func GetPoliciesOutput(ctx *Context, args *GetPoliciesOutputArgs, opts ...InvokeOption) GetPoliciesResultOutput
Copy

> 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)
}
Copy
public static CompletableFuture<GetPoliciesResult> getPolicies(GetPoliciesArgs args, InvokeOptions options)
public static Output<GetPoliciesResult> getPolicies(GetPoliciesArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: alicloud:ram/getPolicies:getPolicies
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

EnableDetails bool
Default to true. Set it to true can output more details.
GroupName Changes to this property will trigger replacement. string
Filter results by a specific group name. Returned policies are attached to the specified group.
Ids Changes to this property will trigger replacement. List<string>
A list of ram group IDs.
NameRegex Changes to this property will trigger replacement. string
A regex string to filter resulting policies by name.
OutputFile string
File name where to save data source results (after running pulumi preview).
RoleName Changes to this property will trigger replacement. string
Filter results by a specific role name. Returned policies are attached to the specified role.
Type Changes to this property will trigger replacement. string
Filter results by a specific policy type. Valid values are Custom and System.
UserName Changes to this property will trigger replacement. string
Filter results by a specific user name. Returned policies are attached to the specified user.
EnableDetails bool
Default to true. Set it to true can output more details.
GroupName Changes to this property will trigger replacement. string
Filter results by a specific group name. Returned policies are attached to the specified group.
Ids Changes to this property will trigger replacement. []string
A list of ram group IDs.
NameRegex Changes to this property will trigger replacement. string
A regex string to filter resulting policies by name.
OutputFile string
File name where to save data source results (after running pulumi preview).
RoleName Changes to this property will trigger replacement. string
Filter results by a specific role name. Returned policies are attached to the specified role.
Type Changes to this property will trigger replacement. string
Filter results by a specific policy type. Valid values are Custom and System.
UserName Changes to this property will trigger replacement. string
Filter results by a specific user name. Returned policies are attached to the specified user.
enableDetails Boolean
Default to true. Set it to true can output more details.
groupName Changes to this property will trigger replacement. String
Filter results by a specific group name. Returned policies are attached to the specified group.
ids Changes to this property will trigger replacement. List<String>
A list of ram group IDs.
nameRegex Changes to this property will trigger replacement. String
A regex string to filter resulting policies by name.
outputFile String
File name where to save data source results (after running pulumi preview).
roleName Changes to this property will trigger replacement. String
Filter results by a specific role name. Returned policies are attached to the specified role.
type Changes to this property will trigger replacement. String
Filter results by a specific policy type. Valid values are Custom and System.
userName Changes to this property will trigger replacement. String
Filter results by a specific user name. Returned policies are attached to the specified user.
enableDetails boolean
Default to true. Set it to true can output more details.
groupName Changes to this property will trigger replacement. string
Filter results by a specific group name. Returned policies are attached to the specified group.
ids Changes to this property will trigger replacement. string[]
A list of ram group IDs.
nameRegex Changes to this property will trigger replacement. string
A regex string to filter resulting policies by name.
outputFile string
File name where to save data source results (after running pulumi preview).
roleName Changes to this property will trigger replacement. string
Filter results by a specific role name. Returned policies are attached to the specified role.
type Changes to this property will trigger replacement. string
Filter results by a specific policy type. Valid values are Custom and System.
userName Changes to this property will trigger replacement. string
Filter results by a specific user name. Returned policies are attached to the specified user.
enable_details bool
Default to true. Set it to true can output more details.
group_name Changes to this property will trigger replacement. str
Filter results by a specific group name. Returned policies are attached to the specified group.
ids Changes to this property will trigger replacement. Sequence[str]
A list of ram group IDs.
name_regex Changes to this property will trigger replacement. str
A regex string to filter resulting policies by name.
output_file str
File name where to save data source results (after running pulumi preview).
role_name Changes to this property will trigger replacement. str
Filter results by a specific role name. Returned policies are attached to the specified role.
type Changes to this property will trigger replacement. str
Filter results by a specific policy type. Valid values are Custom and System.
user_name Changes to this property will trigger replacement. str
Filter results by a specific user name. Returned policies are attached to the specified user.
enableDetails Boolean
Default to true. Set it to true can output more details.
groupName Changes to this property will trigger replacement. String
Filter results by a specific group name. Returned policies are attached to the specified group.
ids Changes to this property will trigger replacement. List<String>
A list of ram group IDs.
nameRegex Changes to this property will trigger replacement. String
A regex string to filter resulting policies by name.
outputFile String
File name where to save data source results (after running pulumi preview).
roleName Changes to this property will trigger replacement. String
Filter results by a specific role name. Returned policies are attached to the specified role.
type Changes to this property will trigger replacement. String
Filter results by a specific policy type. Valid values are Custom and System.
userName Changes to this property will trigger replacement. String
Filter results by a specific user name. Returned policies are attached to the specified 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>
A list of ram group names.
Policies List<Pulumi.AliCloud.Ram.Outputs.GetPoliciesPolicy>
A list of policies. Each element contains the following attributes:
EnableDetails bool
GroupName string
NameRegex string
OutputFile string
RoleName string
Type string
Type of the policy.
UserName string
The user name of policy.
Id string
The provider-assigned unique ID for this managed resource.
Ids []string
Names []string
A list of ram group names.
Policies []GetPoliciesPolicy
A list of policies. Each element contains the following attributes:
EnableDetails bool
GroupName string
NameRegex string
OutputFile string
RoleName string
Type string
Type of the policy.
UserName string
The user name of policy.
id String
The provider-assigned unique ID for this managed resource.
ids List<String>
names List<String>
A list of ram group names.
policies List<GetPoliciesPolicy>
A list of policies. Each element contains the following attributes:
enableDetails Boolean
groupName String
nameRegex String
outputFile String
roleName String
type String
Type of the policy.
userName String
The user name of policy.
id string
The provider-assigned unique ID for this managed resource.
ids string[]
names string[]
A list of ram group names.
policies GetPoliciesPolicy[]
A list of policies. Each element contains the following attributes:
enableDetails boolean
groupName string
nameRegex string
outputFile string
roleName string
type string
Type of the policy.
userName string
The user name of policy.
id str
The provider-assigned unique ID for this managed resource.
ids Sequence[str]
names Sequence[str]
A list of ram group names.
policies Sequence[GetPoliciesPolicy]
A list of policies. Each element contains the following attributes:
enable_details bool
group_name str
name_regex str
output_file str
role_name str
type str
Type of the policy.
user_name str
The user name of policy.
id String
The provider-assigned unique ID for this managed resource.
ids List<String>
names List<String>
A list of ram group names.
policies List<Property Map>
A list of policies. Each element contains the following attributes:
enableDetails Boolean
groupName String
nameRegex String
outputFile String
roleName String
type String
Type of the policy.
userName String
The user name of policy.

Supporting Types

GetPoliciesPolicy

AttachmentCount This property is required. int
Attachment count of the policy.
CreateDate This property is required. string
Creation date of the policy.
DefaultVersion This property is required. string
Default version of the policy.
Description This property is required. string
Description of the policy.
Document This property is required. string
Policy document of the policy.
Id This property is required. string
ID of the policy.
Name This property is required. string
Name of the policy.
PolicyDocument This property is required. string
Policy document of the policy.
PolicyName This property is required. string
Name of the policy.
Type This property is required. string
Filter results by a specific policy type. Valid values are Custom and System.
UpdateDate This property is required. string
Update date of the policy.
UserName This property is required. string
Filter results by a specific user name. Returned policies are attached to the specified user.
VersionId This property is required. string
The ID of default policy.
AttachmentCount This property is required. int
Attachment count of the policy.
CreateDate This property is required. string
Creation date of the policy.
DefaultVersion This property is required. string
Default version of the policy.
Description This property is required. string
Description of the policy.
Document This property is required. string
Policy document of the policy.
Id This property is required. string
ID of the policy.
Name This property is required. string
Name of the policy.
PolicyDocument This property is required. string
Policy document of the policy.
PolicyName This property is required. string
Name of the policy.
Type This property is required. string
Filter results by a specific policy type. Valid values are Custom and System.
UpdateDate This property is required. string
Update date of the policy.
UserName This property is required. string
Filter results by a specific user name. Returned policies are attached to the specified user.
VersionId This property is required. string
The ID of default policy.
attachmentCount This property is required. Integer
Attachment count of the policy.
createDate This property is required. String
Creation date of the policy.
defaultVersion This property is required. String
Default version of the policy.
description This property is required. String
Description of the policy.
document This property is required. String
Policy document of the policy.
id This property is required. String
ID of the policy.
name This property is required. String
Name of the policy.
policyDocument This property is required. String
Policy document of the policy.
policyName This property is required. String
Name of the policy.
type This property is required. String
Filter results by a specific policy type. Valid values are Custom and System.
updateDate This property is required. String
Update date of the policy.
userName This property is required. String
Filter results by a specific user name. Returned policies are attached to the specified user.
versionId This property is required. String
The ID of default policy.
attachmentCount This property is required. number
Attachment count of the policy.
createDate This property is required. string
Creation date of the policy.
defaultVersion This property is required. string
Default version of the policy.
description This property is required. string
Description of the policy.
document This property is required. string
Policy document of the policy.
id This property is required. string
ID of the policy.
name This property is required. string
Name of the policy.
policyDocument This property is required. string
Policy document of the policy.
policyName This property is required. string
Name of the policy.
type This property is required. string
Filter results by a specific policy type. Valid values are Custom and System.
updateDate This property is required. string
Update date of the policy.
userName This property is required. string
Filter results by a specific user name. Returned policies are attached to the specified user.
versionId This property is required. string
The ID of default policy.
attachment_count This property is required. int
Attachment count of the policy.
create_date This property is required. str
Creation date of the policy.
default_version This property is required. str
Default version of the policy.
description This property is required. str
Description of the policy.
document This property is required. str
Policy document of the policy.
id This property is required. str
ID of the policy.
name This property is required. str
Name of the policy.
policy_document This property is required. str
Policy document of the policy.
policy_name This property is required. str
Name of the policy.
type This property is required. str
Filter results by a specific policy type. Valid values are Custom and System.
update_date This property is required. str
Update date of the policy.
user_name This property is required. str
Filter results by a specific user name. Returned policies are attached to the specified user.
version_id This property is required. str
The ID of default policy.
attachmentCount This property is required. Number
Attachment count of the policy.
createDate This property is required. String
Creation date of the policy.
defaultVersion This property is required. String
Default version of the policy.
description This property is required. String
Description of the policy.
document This property is required. String
Policy document of the policy.
id This property is required. String
ID of the policy.
name This property is required. String
Name of the policy.
policyDocument This property is required. String
Policy document of the policy.
policyName This property is required. String
Name of the policy.
type This property is required. String
Filter results by a specific policy type. Valid values are Custom and System.
updateDate This property is required. String
Update date of the policy.
userName This property is required. String
Filter results by a specific user name. Returned policies are attached to the specified user.
versionId This property is required. String
The ID of default policy.

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.
Alibaba Cloud v3.76.0 published on Tuesday, Apr 8, 2025 by Pulumi