published on Monday, Aug 24, 2026 by Pulumi
published on Monday, Aug 24, 2026 by Pulumi
Provides a RAM Access Key Policy resource.
Sets the network access restriction policy for the AccessKey of an Alibaba Cloud account (primary account) or a RAM user.
For information about RAM Access Key Policy and how to use it, see What is Access Key Policy.
NOTE: Available since v1.286.0.
NOTE: There is no dedicated delete API for the network access restriction policy. Destroying this resource clears all whitelist rules by setting a disabled policy with no statements (
{"Version":1,"Status":"Inactive","Statements":[]}) via theSetAccessKeyPolicyAPI. A disabled policy that carries no statements is treated as “no policy” (equivalent to never having configured one), so a policy document of this form is not considered a managed resource.
Example Usage
Basic Usage
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
const _default = alicloud.getAccount({});
const defaultUser = new alicloud.ram.User("default", {name: name});
const defaultAccessKey = new alicloud.ram.AccessKey("default", {userName: defaultUser.name});
const defaultAccessKeyPolicy = new alicloud.ram.AccessKeyPolicy("default", {
userAccessKeyId: defaultAccessKey.id,
userPrincipalName: pulumi.all([defaultUser.name, _default]).apply(([name, _default]) => `${name}@${_default.id}.onaliyun.com`),
accessKeyPolicy: JSON.stringify({
Status: "Active",
Statements: [{
Type: "ClassicWhiteList",
IPList: ["10.0.0.1/32"],
}],
}),
});
import pulumi
import json
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "terraform-example"
default = alicloud.get_account()
default_user = alicloud.ram.User("default", name=name)
default_access_key = alicloud.ram.AccessKey("default", user_name=default_user.name)
default_access_key_policy = alicloud.ram.AccessKeyPolicy("default",
user_access_key_id=default_access_key.id,
user_principal_name=default_user.name.apply(lambda name: f"{name}@{default.id}.onaliyun.com"),
access_key_policy=json.dumps({
"Status": "Active",
"Statements": [{
"Type": "ClassicWhiteList",
"IPList": ["10.0.0.1/32"],
}],
}))
package main
import (
"encoding/json"
"fmt"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/ram"
"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 := alicloud.GetAccount(ctx, map[string]interface{}{}, nil)
if err != nil {
return err
}
defaultUser, err := ram.NewUser(ctx, "default", &ram.UserArgs{
Name: pulumi.String(name),
})
if err != nil {
return err
}
defaultAccessKey, err := ram.NewAccessKey(ctx, "default", &ram.AccessKeyArgs{
UserName: defaultUser.Name,
})
if err != nil {
return err
}
tmpJSON0, err := json.Marshal(map[string]interface{}{
"Status": "Active",
"Statements": []map[string]interface{}{
map[string]interface{}{
"Type": "ClassicWhiteList",
"IPList": []string{
"10.0.0.1/32",
},
},
},
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
_, err = ram.NewAccessKeyPolicy(ctx, "default", &ram.AccessKeyPolicyArgs{
UserAccessKeyId: defaultAccessKey.ID().ToIDOutput().ToStringOutput(),
UserPrincipalName: defaultUser.Name.ApplyT(func(name string) (string, error) {
return fmt.Sprintf("%v@%v.onaliyun.com", name, _default.Id), nil
}).(pulumi.StringOutput),
AccessKeyPolicy: pulumi.String(json0),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var name = config.Get("name") ?? "terraform-example";
var @default = AliCloud.GetAccount.Invoke();
var defaultUser = new AliCloud.Ram.User("default", new()
{
Name = name,
});
var defaultAccessKey = new AliCloud.Ram.AccessKey("default", new()
{
UserName = defaultUser.Name,
});
var defaultAccessKeyPolicy = new AliCloud.Ram.AccessKeyPolicy("default", new()
{
UserAccessKeyId = defaultAccessKey.Id,
UserPrincipalName = Output.Tuple(defaultUser.Name, @default).Apply(values =>
{
var name = values.Item1;
var @default = values.Item2;
return $"{name}@{@default.Apply(getAccountResult => getAccountResult.Id)}.onaliyun.com";
}),
Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["Status"] = "Active",
["Statements"] = new[]
{
new Dictionary<string, object?>
{
["Type"] = "ClassicWhiteList",
["IPList"] = new[]
{
"10.0.0.1/32",
},
},
},
}),
});
});
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.ram.User;
import com.pulumi.alicloud.ram.UserArgs;
import com.pulumi.alicloud.ram.AccessKey;
import com.pulumi.alicloud.ram.AccessKeyArgs;
import com.pulumi.alicloud.ram.AccessKeyPolicy;
import com.pulumi.alicloud.ram.AccessKeyPolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.ArrayList;
import java.util.Arrays;
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");
final var default = AlicloudFunctions.getAccount(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference);
var defaultUser = new User("defaultUser", UserArgs.builder()
.name(name)
.build());
var defaultAccessKey = new AccessKey("defaultAccessKey", AccessKeyArgs.builder()
.userName(defaultUser.name())
.build());
var defaultAccessKeyPolicy = new AccessKeyPolicy("defaultAccessKeyPolicy", AccessKeyPolicyArgs.builder()
.userAccessKeyId(defaultAccessKey.id())
.userPrincipalName(defaultUser.name().applyValue(_name -> String.format("%s@%s.onaliyun.com", _name,default_.id())))
.accessKeyPolicy(serializeJson(
jsonObject(
jsonProperty("Status", "Active"),
jsonProperty("Statements", jsonArray(jsonObject(
jsonProperty("Type", "ClassicWhiteList"),
jsonProperty("IPList", jsonArray("10.0.0.1/32"))
)))
)))
.build());
}
}
configuration:
name:
type: string
default: terraform-example
resources:
defaultUser:
type: alicloud:ram:User
name: default
properties:
name: ${name}
defaultAccessKey:
type: alicloud:ram:AccessKey
name: default
properties:
userName: ${defaultUser.name}
defaultAccessKeyPolicy:
type: alicloud:ram:AccessKeyPolicy
name: default
properties:
userAccessKeyId: ${defaultAccessKey.id}
userPrincipalName: ${defaultUser.name}@${default.id}.onaliyun.com
accessKeyPolicy:
fn::toJSON:
Status: Active
Statements:
- Type: ClassicWhiteList
IPList:
- 10.0.0.1/32
variables:
default:
fn::invoke:
function: alicloud:getAccount
arguments: {}
pulumi {
required_providers {
alicloud = {
source = "pulumi/alicloud"
}
}
}
data "alicloud_getaccount" "default" {
}
resource "alicloud_ram_user" "default" {
name = var.name
}
resource "alicloud_ram_accesskey" "default" {
user_name = alicloud_ram_user.default.name
}
resource "alicloud_ram_accesskeypolicy" "default" {
user_access_key_id = alicloud_ram_accesskey.default.id
user_principal_name ="${alicloud_ram_user.default.name}@${data.alicloud_getaccount.default.id}.onaliyun.com"
access_key_policy = jsonencode({
"Status" = "Active"
"Statements" = [{
"Type" = "ClassicWhiteList"
"IPList" = ["10.0.0.1/32"]
}]
})
}
variable "name" {
type = string
default = "terraform-example"
}
📚 Need more examples? VIEW MORE EXAMPLES
Create AccessKeyPolicy Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new AccessKeyPolicy(name: string, args: AccessKeyPolicyArgs, opts?: CustomResourceOptions);@overload
def AccessKeyPolicy(resource_name: str,
args: AccessKeyPolicyArgs,
opts: Optional[ResourceOptions] = None)
@overload
def AccessKeyPolicy(resource_name: str,
opts: Optional[ResourceOptions] = None,
access_key_policy: Optional[str] = None,
user_access_key_id: Optional[str] = None,
user_principal_name: Optional[str] = None)func NewAccessKeyPolicy(ctx *Context, name string, args AccessKeyPolicyArgs, opts ...ResourceOption) (*AccessKeyPolicy, error)public AccessKeyPolicy(string name, AccessKeyPolicyArgs args, CustomResourceOptions? opts = null)
public AccessKeyPolicy(String name, AccessKeyPolicyArgs args)
public AccessKeyPolicy(String name, AccessKeyPolicyArgs args, CustomResourceOptions options)
type: alicloud:ram:AccessKeyPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
resource "alicloud_ram_access_key_policy" "name" {
# resource properties
}Parameters
- name string
- The unique name of the resource.
- args AccessKeyPolicyArgs
- 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 AccessKeyPolicyArgs
- 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 AccessKeyPolicyArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args AccessKeyPolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args AccessKeyPolicyArgs
- 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 accessKeyPolicyResource = new AliCloud.Ram.AccessKeyPolicy("accessKeyPolicyResource", new()
{
Policy = "string",
UserAccessKeyId = "string",
UserPrincipalName = "string",
});
example, err := ram.NewAccessKeyPolicy(ctx, "accessKeyPolicyResource", &ram.AccessKeyPolicyArgs{
AccessKeyPolicy: pulumi.String("string"),
UserAccessKeyId: pulumi.String("string"),
UserPrincipalName: pulumi.String("string"),
})
resource "alicloud_ram_access_key_policy" "accessKeyPolicyResource" {
lifecycle {
create_before_destroy = true
}
access_key_policy = "string"
user_access_key_id = "string"
user_principal_name = "string"
}
var accessKeyPolicyResource = new AccessKeyPolicy("accessKeyPolicyResource", AccessKeyPolicyArgs.builder()
.accessKeyPolicy("string")
.userAccessKeyId("string")
.userPrincipalName("string")
.build());
access_key_policy_resource = alicloud.ram.AccessKeyPolicy("accessKeyPolicyResource",
access_key_policy="string",
user_access_key_id="string",
user_principal_name="string")
const accessKeyPolicyResource = new alicloud.ram.AccessKeyPolicy("accessKeyPolicyResource", {
accessKeyPolicy: "string",
userAccessKeyId: "string",
userPrincipalName: "string",
});
type: alicloud:ram:AccessKeyPolicy
properties:
accessKeyPolicy: string
userAccessKeyId: string
userPrincipalName: string
AccessKeyPolicy 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 AccessKeyPolicy resource accepts the following input properties:
- Policy string
- The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- User
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- User
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- Access
Key stringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- User
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- User
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access_
key_ stringpolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user_
access_ stringkey_ id - The ID of the access key that the network access restriction policy applies to.
- user_
principal_ stringname - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key StringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access StringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal StringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key stringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access_
key_ strpolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user_
access_ strkey_ id - The ID of the access key that the network access restriction policy applies to.
- user_
principal_ strname - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key StringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access StringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal StringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
Outputs
All input properties are implicitly available as output properties. Additionally, the AccessKeyPolicy 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 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 AccessKeyPolicy Resource
Get an existing AccessKeyPolicy 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?: AccessKeyPolicyState, opts?: CustomResourceOptions): AccessKeyPolicy@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
access_key_policy: Optional[str] = None,
user_access_key_id: Optional[str] = None,
user_principal_name: Optional[str] = None) -> AccessKeyPolicyfunc GetAccessKeyPolicy(ctx *Context, name string, id IDInput, state *AccessKeyPolicyState, opts ...ResourceOption) (*AccessKeyPolicy, error)public static AccessKeyPolicy Get(string name, Input<string> id, AccessKeyPolicyState? state, CustomResourceOptions? opts = null)public static AccessKeyPolicy get(String name, Output<String> id, AccessKeyPolicyState state, CustomResourceOptions options)resources: _: type: alicloud:ram:AccessKeyPolicy get: id: ${id}import {
to = alicloud_ram_access_key_policy.example
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.
- Policy string
- The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- User
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- User
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- Access
Key stringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- User
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- User
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access_
key_ stringpolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user_
access_ stringkey_ id - The ID of the access key that the network access restriction policy applies to.
- user_
principal_ stringname - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key StringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access StringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal StringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key stringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access stringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal stringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access_
key_ strpolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user_
access_ strkey_ id - The ID of the access key that the network access restriction policy applies to.
- user_
principal_ strname - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
- access
Key StringPolicy - The network access restriction policy, in JSON format. For the structure of the policy document, see SetAccessKeyPolicy.
- user
Access StringKey Id - The ID of the access key that the network access restriction policy applies to.
- user
Principal StringName - The logon name of the RAM user. Specify this parameter when managing the access key policy of another RAM user. If it is left empty, the policy is applied to the specified access key of the current user.
Import
RAM Access Key Policy can be imported using the id, e.g.
$ pulumi import alicloud:ram/accessKeyPolicy:AccessKeyPolicy example <user_access_key_id>
If the policy is set for another RAM user, use the composite id:
$ pulumi import alicloud:ram/accessKeyPolicy:AccessKeyPolicy example <user_principal_name>:<user_access_key_id>
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
alicloudTerraform Provider.
published on Monday, Aug 24, 2026 by Pulumi