1. Packages
  2. Alicloud Provider
  3. API Docs
  4. ram
  5. RolePolicyAttachment
Alibaba Cloud v3.63.0 published on Monday, Sep 30, 2024 by Pulumi

alicloud.ram.RolePolicyAttachment

Explore with Pulumi AI

alicloud logo
Alibaba Cloud v3.63.0 published on Monday, Sep 30, 2024 by Pulumi

    Provides a RAM Role attachment resource.

    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";
    
    // Create a RAM Role Policy attachment.
    const role = new alicloud.ram.Role("role", {
        name: "roleName",
        document: `    {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "apigateway.aliyuncs.com", 
                  "ecs.aliyuncs.com"
                ]
              }
            }
          ],
          "Version": "1"
        }
    `,
        description: "this is a role test.",
    });
    const _default = new random.index.Integer("default", {
        min: 10000,
        max: 99999,
    });
    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.RolePolicyAttachment("attach", {
        policyName: policy.policyName,
        policyType: policy.type,
        roleName: role.name,
    });
    
    import pulumi
    import pulumi_alicloud as alicloud
    import pulumi_random as random
    
    # Create a RAM Role Policy attachment.
    role = alicloud.ram.Role("role",
        name="roleName",
        document="""    {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "apigateway.aliyuncs.com", 
                  "ecs.aliyuncs.com"
                ]
              }
            }
          ],
          "Version": "1"
        }
    """,
        description="this is a role test.")
    default = random.index.Integer("default",
        min=10000,
        max=99999)
    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.RolePolicyAttachment("attach",
        policy_name=policy.policy_name,
        policy_type=policy.type,
        role_name=role.name)
    
    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 {
    		// Create a RAM Role Policy attachment.
    		role, err := ram.NewRole(ctx, "role", &ram.RoleArgs{
    			Name: pulumi.String("roleName"),
    			Document: pulumi.String(`    {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "apigateway.aliyuncs.com", 
                  "ecs.aliyuncs.com"
                ]
              }
            }
          ],
          "Version": "1"
        }
    `),
    			Description: pulumi.String("this is a role test."),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = random.NewInteger(ctx, "default", &random.IntegerArgs{
    			Min: 10000,
    			Max: 99999,
    		})
    		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
    		}
    		_, err = ram.NewRolePolicyAttachment(ctx, "attach", &ram.RolePolicyAttachmentArgs{
    			PolicyName: policy.PolicyName,
    			PolicyType: policy.Type,
    			RoleName:   role.Name,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    using Random = Pulumi.Random;
    
    return await Deployment.RunAsync(() => 
    {
        // Create a RAM Role Policy attachment.
        var role = new AliCloud.Ram.Role("role", new()
        {
            Name = "roleName",
            Document = @"    {
          ""Statement"": [
            {
              ""Action"": ""sts:AssumeRole"",
              ""Effect"": ""Allow"",
              ""Principal"": {
                ""Service"": [
                  ""apigateway.aliyuncs.com"", 
                  ""ecs.aliyuncs.com""
                ]
              }
            }
          ],
          ""Version"": ""1""
        }
    ",
            Description = "this is a role test.",
        });
    
        var @default = new Random.Index.Integer("default", new()
        {
            Min = 10000,
            Max = 99999,
        });
    
        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.RolePolicyAttachment("attach", new()
        {
            PolicyName = policy.PolicyName,
            PolicyType = policy.Type,
            RoleName = role.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.alicloud.ram.Role;
    import com.pulumi.alicloud.ram.RoleArgs;
    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.RolePolicyAttachment;
    import com.pulumi.alicloud.ram.RolePolicyAttachmentArgs;
    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) {
            // Create a RAM Role Policy attachment.
            var role = new Role("role", RoleArgs.builder()
                .name("roleName")
                .document("""
        {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "apigateway.aliyuncs.com", 
                  "ecs.aliyuncs.com"
                ]
              }
            }
          ],
          "Version": "1"
        }
                """)
                .description("this is a role test.")
                .build());
    
            var default_ = new Integer("default", IntegerArgs.builder()
                .min(10000)
                .max(99999)
                .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 RolePolicyAttachment("attach", RolePolicyAttachmentArgs.builder()
                .policyName(policy.policyName())
                .policyType(policy.type())
                .roleName(role.name())
                .build());
    
        }
    }
    
    resources:
      # Create a RAM Role Policy attachment.
      role:
        type: alicloud:ram:Role
        properties:
          name: roleName
          document: "    {\n      \"Statement\": [\n        {\n          \"Action\": \"sts:AssumeRole\",\n          \"Effect\": \"Allow\",\n          \"Principal\": {\n            \"Service\": [\n              \"apigateway.aliyuncs.com\", \n              \"ecs.aliyuncs.com\"\n            ]\n          }\n        }\n      ],\n      \"Version\": \"1\"\n    }\n"
          description: this is a role test.
      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:RolePolicyAttachment
        properties:
          policyName: ${policy.policyName}
          policyType: ${policy.type}
          roleName: ${role.name}
    

    Create RolePolicyAttachment Resource

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

    Constructor syntax

    new RolePolicyAttachment(name: string, args: RolePolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def RolePolicyAttachment(resource_name: str,
                             args: RolePolicyAttachmentArgs,
                             opts: Optional[ResourceOptions] = None)
    
    @overload
    def RolePolicyAttachment(resource_name: str,
                             opts: Optional[ResourceOptions] = None,
                             policy_name: Optional[str] = None,
                             policy_type: Optional[str] = None,
                             role_name: Optional[str] = None)
    func NewRolePolicyAttachment(ctx *Context, name string, args RolePolicyAttachmentArgs, opts ...ResourceOption) (*RolePolicyAttachment, error)
    public RolePolicyAttachment(string name, RolePolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public RolePolicyAttachment(String name, RolePolicyAttachmentArgs args)
    public RolePolicyAttachment(String name, RolePolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: alicloud:ram:RolePolicyAttachment
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args RolePolicyAttachmentArgs
    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 RolePolicyAttachmentArgs
    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 RolePolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args RolePolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args RolePolicyAttachmentArgs
    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 rolePolicyAttachmentResource = new AliCloud.Ram.RolePolicyAttachment("rolePolicyAttachmentResource", new()
    {
        PolicyName = "string",
        PolicyType = "string",
        RoleName = "string",
    });
    
    example, err := ram.NewRolePolicyAttachment(ctx, "rolePolicyAttachmentResource", &ram.RolePolicyAttachmentArgs{
    	PolicyName: pulumi.String("string"),
    	PolicyType: pulumi.String("string"),
    	RoleName:   pulumi.String("string"),
    })
    
    var rolePolicyAttachmentResource = new RolePolicyAttachment("rolePolicyAttachmentResource", RolePolicyAttachmentArgs.builder()
        .policyName("string")
        .policyType("string")
        .roleName("string")
        .build());
    
    role_policy_attachment_resource = alicloud.ram.RolePolicyAttachment("rolePolicyAttachmentResource",
        policy_name="string",
        policy_type="string",
        role_name="string")
    
    const rolePolicyAttachmentResource = new alicloud.ram.RolePolicyAttachment("rolePolicyAttachmentResource", {
        policyName: "string",
        policyType: "string",
        roleName: "string",
    });
    
    type: alicloud:ram:RolePolicyAttachment
    properties:
        policyName: string
        policyType: string
        roleName: string
    

    RolePolicyAttachment Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The RolePolicyAttachment resource accepts the following input properties:

    PolicyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    PolicyType string
    Type of the RAM policy. It must be Custom or System.
    RoleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    PolicyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    PolicyType string
    Type of the RAM policy. It must be Custom or System.
    RoleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName String
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType String
    Type of the RAM policy. It must be Custom or System.
    roleName String
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType string
    Type of the RAM policy. It must be Custom or System.
    roleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policy_name str
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policy_type str
    Type of the RAM policy. It must be Custom or System.
    role_name str
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName String
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType String
    Type of the RAM policy. It must be Custom or System.
    roleName String
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the RolePolicyAttachment 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 RolePolicyAttachment Resource

    Get an existing RolePolicyAttachment 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?: RolePolicyAttachmentState, opts?: CustomResourceOptions): RolePolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy_name: Optional[str] = None,
            policy_type: Optional[str] = None,
            role_name: Optional[str] = None) -> RolePolicyAttachment
    func GetRolePolicyAttachment(ctx *Context, name string, id IDInput, state *RolePolicyAttachmentState, opts ...ResourceOption) (*RolePolicyAttachment, error)
    public static RolePolicyAttachment Get(string name, Input<string> id, RolePolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static RolePolicyAttachment get(String name, Output<String> id, RolePolicyAttachmentState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    PolicyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    PolicyType string
    Type of the RAM policy. It must be Custom or System.
    RoleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    PolicyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    PolicyType string
    Type of the RAM policy. It must be Custom or System.
    RoleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName String
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType String
    Type of the RAM policy. It must be Custom or System.
    roleName String
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName string
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType string
    Type of the RAM policy. It must be Custom or System.
    roleName string
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policy_name str
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policy_type str
    Type of the RAM policy. It must be Custom or System.
    role_name str
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.
    policyName String
    Name of the RAM policy. This name can have a string of 1 to 128 characters, must contain only alphanumeric characters or hyphen "-", and must not begin with a hyphen.
    policyType String
    Type of the RAM policy. It must be Custom or System.
    roleName String
    Name of the RAM Role. This name can have a string of 1 to 64 characters, must contain only alphanumeric characters or hyphens, such as "-", "_", and must not begin with a hyphen.

    Import

    RAM Role Policy attachment can be imported using the id, e.g.

    $ pulumi import alicloud:ram/rolePolicyAttachment:RolePolicyAttachment example role:my-policy:Custom:my-role
    

    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.
    alicloud logo
    Alibaba Cloud v3.63.0 published on Monday, Sep 30, 2024 by Pulumi