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

alicloud.resourcemanager.ControlPolicyAttachment

Explore with Pulumi AI

Provides a Resource Manager Control Policy Attachment resource.

For information about Resource Manager Control Policy Attachment and how to use it, see What is Control Policy Attachment.

NOTE: Available since v1.120.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 defaultControlPolicy = new alicloud.resourcemanager.ControlPolicy("default", {
    controlPolicyName: name,
    description: name,
    effectScope: "RAM",
    policyDocument: `  {
    "Version": "1",
    "Statement": [
      {
        "Effect": "Deny",
        "Action": [
          "ram:UpdateRole",
          "ram:DeleteRole",
          "ram:AttachPolicyToRole",
          "ram:DetachPolicyFromRole"
        ],
        "Resource": "acs:ram:*:*:role/ResourceDirectoryAccountAccessRole"
      }
    ]
  }
`,
});
const defaultFolder = new alicloud.resourcemanager.Folder("default", {folderName: `${name}-${_default.result}`});
const defaultControlPolicyAttachment = new alicloud.resourcemanager.ControlPolicyAttachment("default", {
    policyId: defaultControlPolicy.id,
    targetId: defaultFolder.id,
});
Copy
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_control_policy = alicloud.resourcemanager.ControlPolicy("default",
    control_policy_name=name,
    description=name,
    effect_scope="RAM",
    policy_document="""  {
    "Version": "1",
    "Statement": [
      {
        "Effect": "Deny",
        "Action": [
          "ram:UpdateRole",
          "ram:DeleteRole",
          "ram:AttachPolicyToRole",
          "ram:DetachPolicyFromRole"
        ],
        "Resource": "acs:ram:*:*:role/ResourceDirectoryAccountAccessRole"
      }
    ]
  }
""")
default_folder = alicloud.resourcemanager.Folder("default", folder_name=f"{name}-{default['result']}")
default_control_policy_attachment = alicloud.resourcemanager.ControlPolicyAttachment("default",
    policy_id=default_control_policy.id,
    target_id=default_folder.id)
Copy
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/resourcemanager"
	"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
		}
		defaultControlPolicy, err := resourcemanager.NewControlPolicy(ctx, "default", &resourcemanager.ControlPolicyArgs{
			ControlPolicyName: pulumi.String(name),
			Description:       pulumi.String(name),
			EffectScope:       pulumi.String("RAM"),
			PolicyDocument: pulumi.String(`  {
    "Version": "1",
    "Statement": [
      {
        "Effect": "Deny",
        "Action": [
          "ram:UpdateRole",
          "ram:DeleteRole",
          "ram:AttachPolicyToRole",
          "ram:DetachPolicyFromRole"
        ],
        "Resource": "acs:ram:*:*:role/ResourceDirectoryAccountAccessRole"
      }
    ]
  }
`),
		})
		if err != nil {
			return err
		}
		defaultFolder, err := resourcemanager.NewFolder(ctx, "default", &resourcemanager.FolderArgs{
			FolderName: pulumi.Sprintf("%v-%v", name, _default.Result),
		})
		if err != nil {
			return err
		}
		_, err = resourcemanager.NewControlPolicyAttachment(ctx, "default", &resourcemanager.ControlPolicyAttachmentArgs{
			PolicyId: defaultControlPolicy.ID(),
			TargetId: defaultFolder.ID(),
		})
		if err != nil {
			return err
		}
		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 config = new Config();
    var name = config.Get("name") ?? "terraform-example";
    var @default = new Random.Index.Integer("default", new()
    {
        Min = 10000,
        Max = 99999,
    });

    var defaultControlPolicy = new AliCloud.ResourceManager.ControlPolicy("default", new()
    {
        ControlPolicyName = name,
        Description = name,
        EffectScope = "RAM",
        PolicyDocument = @"  {
    ""Version"": ""1"",
    ""Statement"": [
      {
        ""Effect"": ""Deny"",
        ""Action"": [
          ""ram:UpdateRole"",
          ""ram:DeleteRole"",
          ""ram:AttachPolicyToRole"",
          ""ram:DetachPolicyFromRole""
        ],
        ""Resource"": ""acs:ram:*:*:role/ResourceDirectoryAccountAccessRole""
      }
    ]
  }
",
    });

    var defaultFolder = new AliCloud.ResourceManager.Folder("default", new()
    {
        FolderName = $"{name}-{@default.Result}",
    });

    var defaultControlPolicyAttachment = new AliCloud.ResourceManager.ControlPolicyAttachment("default", new()
    {
        PolicyId = defaultControlPolicy.Id,
        TargetId = defaultFolder.Id,
    });

});
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.resourcemanager.ControlPolicy;
import com.pulumi.alicloud.resourcemanager.ControlPolicyArgs;
import com.pulumi.alicloud.resourcemanager.Folder;
import com.pulumi.alicloud.resourcemanager.FolderArgs;
import com.pulumi.alicloud.resourcemanager.ControlPolicyAttachment;
import com.pulumi.alicloud.resourcemanager.ControlPolicyAttachmentArgs;
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 defaultControlPolicy = new ControlPolicy("defaultControlPolicy", ControlPolicyArgs.builder()
            .controlPolicyName(name)
            .description(name)
            .effectScope("RAM")
            .policyDocument("""
  {
    "Version": "1",
    "Statement": [
      {
        "Effect": "Deny",
        "Action": [
          "ram:UpdateRole",
          "ram:DeleteRole",
          "ram:AttachPolicyToRole",
          "ram:DetachPolicyFromRole"
        ],
        "Resource": "acs:ram:*:*:role/ResourceDirectoryAccountAccessRole"
      }
    ]
  }
            """)
            .build());

        var defaultFolder = new Folder("defaultFolder", FolderArgs.builder()
            .folderName(String.format("%s-%s", name,default_.result()))
            .build());

        var defaultControlPolicyAttachment = new ControlPolicyAttachment("defaultControlPolicyAttachment", ControlPolicyAttachmentArgs.builder()
            .policyId(defaultControlPolicy.id())
            .targetId(defaultFolder.id())
            .build());

    }
}
Copy
configuration:
  name:
    type: string
    default: terraform-example
resources:
  default:
    type: random:integer
    properties:
      min: 10000
      max: 99999
  defaultControlPolicy:
    type: alicloud:resourcemanager:ControlPolicy
    name: default
    properties:
      controlPolicyName: ${name}
      description: ${name}
      effectScope: RAM
      policyDocument: |2
          {
            "Version": "1",
            "Statement": [
              {
                "Effect": "Deny",
                "Action": [
                  "ram:UpdateRole",
                  "ram:DeleteRole",
                  "ram:AttachPolicyToRole",
                  "ram:DetachPolicyFromRole"
                ],
                "Resource": "acs:ram:*:*:role/ResourceDirectoryAccountAccessRole"
              }
            ]
          }
  defaultFolder:
    type: alicloud:resourcemanager:Folder
    name: default
    properties:
      folderName: ${name}-${default.result}
  defaultControlPolicyAttachment:
    type: alicloud:resourcemanager:ControlPolicyAttachment
    name: default
    properties:
      policyId: ${defaultControlPolicy.id}
      targetId: ${defaultFolder.id}
Copy

Create ControlPolicyAttachment Resource

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

Constructor syntax

new ControlPolicyAttachment(name: string, args: ControlPolicyAttachmentArgs, opts?: CustomResourceOptions);
@overload
def ControlPolicyAttachment(resource_name: str,
                            args: ControlPolicyAttachmentArgs,
                            opts: Optional[ResourceOptions] = None)

@overload
def ControlPolicyAttachment(resource_name: str,
                            opts: Optional[ResourceOptions] = None,
                            policy_id: Optional[str] = None,
                            target_id: Optional[str] = None)
func NewControlPolicyAttachment(ctx *Context, name string, args ControlPolicyAttachmentArgs, opts ...ResourceOption) (*ControlPolicyAttachment, error)
public ControlPolicyAttachment(string name, ControlPolicyAttachmentArgs args, CustomResourceOptions? opts = null)
public ControlPolicyAttachment(String name, ControlPolicyAttachmentArgs args)
public ControlPolicyAttachment(String name, ControlPolicyAttachmentArgs args, CustomResourceOptions options)
type: alicloud:resourcemanager:ControlPolicyAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. ControlPolicyAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. ControlPolicyAttachmentArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. ControlPolicyAttachmentArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. ControlPolicyAttachmentArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. ControlPolicyAttachmentArgs
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 controlPolicyAttachmentResource = new AliCloud.ResourceManager.ControlPolicyAttachment("controlPolicyAttachmentResource", new()
{
    PolicyId = "string",
    TargetId = "string",
});
Copy
example, err := resourcemanager.NewControlPolicyAttachment(ctx, "controlPolicyAttachmentResource", &resourcemanager.ControlPolicyAttachmentArgs{
	PolicyId: pulumi.String("string"),
	TargetId: pulumi.String("string"),
})
Copy
var controlPolicyAttachmentResource = new ControlPolicyAttachment("controlPolicyAttachmentResource", ControlPolicyAttachmentArgs.builder()
    .policyId("string")
    .targetId("string")
    .build());
Copy
control_policy_attachment_resource = alicloud.resourcemanager.ControlPolicyAttachment("controlPolicyAttachmentResource",
    policy_id="string",
    target_id="string")
Copy
const controlPolicyAttachmentResource = new alicloud.resourcemanager.ControlPolicyAttachment("controlPolicyAttachmentResource", {
    policyId: "string",
    targetId: "string",
});
Copy
type: alicloud:resourcemanager:ControlPolicyAttachment
properties:
    policyId: string
    targetId: string
Copy

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

PolicyId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the access control policy.
TargetId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the object to which you want to attach the access control policy.
PolicyId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the access control policy.
TargetId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the object to which you want to attach the access control policy.
policyId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the access control policy.
targetId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the object to which you want to attach the access control policy.
policyId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the access control policy.
targetId
This property is required.
Changes to this property will trigger replacement.
string
The ID of the object to which you want to attach the access control policy.
policy_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of the access control policy.
target_id
This property is required.
Changes to this property will trigger replacement.
str
The ID of the object to which you want to attach the access control policy.
policyId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the access control policy.
targetId
This property is required.
Changes to this property will trigger replacement.
String
The ID of the object to which you want to attach the access control policy.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing ControlPolicyAttachment Resource

Get an existing ControlPolicyAttachment 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?: ControlPolicyAttachmentState, opts?: CustomResourceOptions): ControlPolicyAttachment
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        policy_id: Optional[str] = None,
        target_id: Optional[str] = None) -> ControlPolicyAttachment
func GetControlPolicyAttachment(ctx *Context, name string, id IDInput, state *ControlPolicyAttachmentState, opts ...ResourceOption) (*ControlPolicyAttachment, error)
public static ControlPolicyAttachment Get(string name, Input<string> id, ControlPolicyAttachmentState? state, CustomResourceOptions? opts = null)
public static ControlPolicyAttachment get(String name, Output<String> id, ControlPolicyAttachmentState state, CustomResourceOptions options)
resources:  _:    type: alicloud:resourcemanager:ControlPolicyAttachment    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
PolicyId Changes to this property will trigger replacement. string
The ID of the access control policy.
TargetId Changes to this property will trigger replacement. string
The ID of the object to which you want to attach the access control policy.
PolicyId Changes to this property will trigger replacement. string
The ID of the access control policy.
TargetId Changes to this property will trigger replacement. string
The ID of the object to which you want to attach the access control policy.
policyId Changes to this property will trigger replacement. String
The ID of the access control policy.
targetId Changes to this property will trigger replacement. String
The ID of the object to which you want to attach the access control policy.
policyId Changes to this property will trigger replacement. string
The ID of the access control policy.
targetId Changes to this property will trigger replacement. string
The ID of the object to which you want to attach the access control policy.
policy_id Changes to this property will trigger replacement. str
The ID of the access control policy.
target_id Changes to this property will trigger replacement. str
The ID of the object to which you want to attach the access control policy.
policyId Changes to this property will trigger replacement. String
The ID of the access control policy.
targetId Changes to this property will trigger replacement. String
The ID of the object to which you want to attach the access control policy.

Import

Resource Manager Control Policy Attachment can be imported using the id, e.g.

$ pulumi import alicloud:resourcemanager/controlPolicyAttachment:ControlPolicyAttachment example <policy_id>:<target_id>
Copy

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

Package Details

Repository
Alibaba Cloud pulumi/pulumi-alicloud
License
Apache-2.0
Notes
This Pulumi package is based on the alicloud Terraform Provider.