1. Packages
  2. Volcengine
  3. API Docs
  4. iam
  5. RolePolicyAttachment
Volcengine v0.0.27 published on Tuesday, Dec 10, 2024 by Volcengine

volcengine.iam.RolePolicyAttachment

Explore with Pulumi AI

Provides a resource to manage iam role policy attachment

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as volcengine from "@volcengine/pulumi";

const role = new volcengine.iam.Role("role", {
    roleName: "TerraformTestRole",
    displayName: "terraform role",
    trustPolicyDocument: "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sts:AssumeRole\"],\"Principal\":{\"Service\":[\"auto_scaling\"]}}]}",
    description: "created by terraform",
    maxSessionDuration: 43200,
});
const policy = new volcengine.iam.Policy("policy", {
    policyName: "TerraformResourceTest1",
    description: "created by terraform 1",
    policyDocument: "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}",
});
const foo = new volcengine.iam.RolePolicyAttachment("foo", {
    roleName: role.id,
    policyName: policy.id,
    policyType: policy.policyType,
});
Copy
import pulumi
import pulumi_volcengine as volcengine

role = volcengine.iam.Role("role",
    role_name="TerraformTestRole",
    display_name="terraform role",
    trust_policy_document="{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sts:AssumeRole\"],\"Principal\":{\"Service\":[\"auto_scaling\"]}}]}",
    description="created by terraform",
    max_session_duration=43200)
policy = volcengine.iam.Policy("policy",
    policy_name="TerraformResourceTest1",
    description="created by terraform 1",
    policy_document="{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}")
foo = volcengine.iam.RolePolicyAttachment("foo",
    role_name=role.id,
    policy_name=policy.id,
    policy_type=policy.policy_type)
Copy
package main

import (
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
	"github.com/volcengine/pulumi-volcengine/sdk/go/volcengine/iam"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		role, err := iam.NewRole(ctx, "role", &iam.RoleArgs{
			RoleName:            pulumi.String("TerraformTestRole"),
			DisplayName:         pulumi.String("terraform role"),
			TrustPolicyDocument: pulumi.String("{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sts:AssumeRole\"],\"Principal\":{\"Service\":[\"auto_scaling\"]}}]}"),
			Description:         pulumi.String("created by terraform"),
			MaxSessionDuration:  pulumi.Int(43200),
		})
		if err != nil {
			return err
		}
		policy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
			PolicyName:     pulumi.String("TerraformResourceTest1"),
			Description:    pulumi.String("created by terraform 1"),
			PolicyDocument: pulumi.String("{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}"),
		})
		if err != nil {
			return err
		}
		_, err = iam.NewRolePolicyAttachment(ctx, "foo", &iam.RolePolicyAttachmentArgs{
			RoleName:   role.ID(),
			PolicyName: policy.ID(),
			PolicyType: policy.PolicyType,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Volcengine = Pulumi.Volcengine;

return await Deployment.RunAsync(() => 
{
    var role = new Volcengine.Iam.Role("role", new()
    {
        RoleName = "TerraformTestRole",
        DisplayName = "terraform role",
        TrustPolicyDocument = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sts:AssumeRole\"],\"Principal\":{\"Service\":[\"auto_scaling\"]}}]}",
        Description = "created by terraform",
        MaxSessionDuration = 43200,
    });

    var policy = new Volcengine.Iam.Policy("policy", new()
    {
        PolicyName = "TerraformResourceTest1",
        Description = "created by terraform 1",
        PolicyDocument = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}",
    });

    var foo = new Volcengine.Iam.RolePolicyAttachment("foo", new()
    {
        RoleName = role.Id,
        PolicyName = policy.Id,
        PolicyType = policy.PolicyType,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.volcengine.iam.Role;
import com.pulumi.volcengine.iam.RoleArgs;
import com.pulumi.volcengine.iam.Policy;
import com.pulumi.volcengine.iam.PolicyArgs;
import com.pulumi.volcengine.iam.RolePolicyAttachment;
import com.pulumi.volcengine.iam.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) {
        var role = new Role("role", RoleArgs.builder()        
            .roleName("TerraformTestRole")
            .displayName("terraform role")
            .trustPolicyDocument("{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"sts:AssumeRole\"],\"Principal\":{\"Service\":[\"auto_scaling\"]}}]}")
            .description("created by terraform")
            .maxSessionDuration(43200)
            .build());

        var policy = new Policy("policy", PolicyArgs.builder()        
            .policyName("TerraformResourceTest1")
            .description("created by terraform 1")
            .policyDocument("{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"auto_scaling:DescribeScalingGroups\"],\"Resource\":[\"*\"]}]}")
            .build());

        var foo = new RolePolicyAttachment("foo", RolePolicyAttachmentArgs.builder()        
            .roleName(role.id())
            .policyName(policy.id())
            .policyType(policy.policyType())
            .build());

    }
}
Copy
resources:
  role:
    type: volcengine:iam:Role
    properties:
      roleName: TerraformTestRole
      displayName: terraform role
      trustPolicyDocument: '{"Statement":[{"Effect":"Allow","Action":["sts:AssumeRole"],"Principal":{"Service":["auto_scaling"]}}]}'
      description: created by terraform
      maxSessionDuration: 43200
  policy:
    type: volcengine:iam:Policy
    properties:
      policyName: TerraformResourceTest1
      description: created by terraform 1
      policyDocument: '{"Statement":[{"Effect":"Allow","Action":["auto_scaling:DescribeScalingGroups"],"Resource":["*"]}]}'
  foo:
    type: volcengine:iam:RolePolicyAttachment
    properties:
      roleName: ${role.id}
      policyName: ${policy.id}
      policyType: ${policy.policyType}
Copy

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: volcengine:iam:RolePolicyAttachment
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. RolePolicyAttachmentArgs
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. 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 This property is required. string
The unique name of the resource.
args This property is required. RolePolicyAttachmentArgs
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. RolePolicyAttachmentArgs
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. 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 Volcengine.Iam.RolePolicyAttachment("rolePolicyAttachmentResource", new()
{
    PolicyName = "string",
    PolicyType = "string",
    RoleName = "string",
});
Copy
example, err := iam.NewRolePolicyAttachment(ctx, "rolePolicyAttachmentResource", &iam.RolePolicyAttachmentArgs{
	PolicyName: pulumi.String("string"),
	PolicyType: pulumi.String("string"),
	RoleName:   pulumi.String("string"),
})
Copy
var rolePolicyAttachmentResource = new RolePolicyAttachment("rolePolicyAttachmentResource", RolePolicyAttachmentArgs.builder()
    .policyName("string")
    .policyType("string")
    .roleName("string")
    .build());
Copy
role_policy_attachment_resource = volcengine.iam.RolePolicyAttachment("rolePolicyAttachmentResource",
    policy_name="string",
    policy_type="string",
    role_name="string")
Copy
const rolePolicyAttachmentResource = new volcengine.iam.RolePolicyAttachment("rolePolicyAttachmentResource", {
    policyName: "string",
    policyType: "string",
    roleName: "string",
});
Copy
type: volcengine:iam:RolePolicyAttachment
properties:
    policyName: string
    policyType: string
    roleName: string
Copy

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

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The RolePolicyAttachment resource accepts the following input properties:

PolicyName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Policy.
PolicyType
This property is required.
Changes to this property will trigger replacement.
string
The type of the Policy.
RoleName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Role.
PolicyName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Policy.
PolicyType
This property is required.
Changes to this property will trigger replacement.
string
The type of the Policy.
RoleName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Role.
policyName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Policy.
policyType
This property is required.
Changes to this property will trigger replacement.
String
The type of the Policy.
roleName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Role.
policyName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Policy.
policyType
This property is required.
Changes to this property will trigger replacement.
string
The type of the Policy.
roleName
This property is required.
Changes to this property will trigger replacement.
string
The name of the Role.
policy_name
This property is required.
Changes to this property will trigger replacement.
str
The name of the Policy.
policy_type
This property is required.
Changes to this property will trigger replacement.
str
The type of the Policy.
role_name
This property is required.
Changes to this property will trigger replacement.
str
The name of the Role.
policyName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Policy.
policyType
This property is required.
Changes to this property will trigger replacement.
String
The type of the Policy.
roleName
This property is required.
Changes to this property will trigger replacement.
String
The name of the Role.

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)
resources:  _:    type: volcengine:iam:RolePolicyAttachment    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:
PolicyName Changes to this property will trigger replacement. string
The name of the Policy.
PolicyType Changes to this property will trigger replacement. string
The type of the Policy.
RoleName Changes to this property will trigger replacement. string
The name of the Role.
PolicyName Changes to this property will trigger replacement. string
The name of the Policy.
PolicyType Changes to this property will trigger replacement. string
The type of the Policy.
RoleName Changes to this property will trigger replacement. string
The name of the Role.
policyName Changes to this property will trigger replacement. String
The name of the Policy.
policyType Changes to this property will trigger replacement. String
The type of the Policy.
roleName Changes to this property will trigger replacement. String
The name of the Role.
policyName Changes to this property will trigger replacement. string
The name of the Policy.
policyType Changes to this property will trigger replacement. string
The type of the Policy.
roleName Changes to this property will trigger replacement. string
The name of the Role.
policy_name Changes to this property will trigger replacement. str
The name of the Policy.
policy_type Changes to this property will trigger replacement. str
The type of the Policy.
role_name Changes to this property will trigger replacement. str
The name of the Role.
policyName Changes to this property will trigger replacement. String
The name of the Policy.
policyType Changes to this property will trigger replacement. String
The type of the Policy.
roleName Changes to this property will trigger replacement. String
The name of the Role.

Import

Iam role policy attachment can be imported using the id, e.g.

$ pulumi import volcengine:iam/rolePolicyAttachment:RolePolicyAttachment default TerraformTestRole:TerraformTestPolicy:Custom
Copy

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

Package Details

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