RolePolicyAttachment
Attaches a Managed IAM Policy to an IAM role
NOTE: The usage of this resource conflicts with the
aws.iam.PolicyAttachmentresource and will permanently show a difference if both are defined.
Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var role = new Aws.Iam.Role("role", new Aws.Iam.RoleArgs
{
AssumeRolePolicy = @" {
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""Service"": ""ec2.amazonaws.com""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}
",
});
var policy = new Aws.Iam.Policy("policy", new Aws.Iam.PolicyArgs
{
Description = "A test policy",
Policy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": [
""ec2:Describe*""
],
""Effect"": ""Allow"",
""Resource"": ""*""
}
]
}
",
});
var test_attach = new Aws.Iam.RolePolicyAttachment("test-attach", new Aws.Iam.RolePolicyAttachmentArgs
{
PolicyArn = policy.Arn,
Role = role.Name,
});
}
}
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
role, err := iam.NewRole(ctx, "role", &iam.RoleArgs{
AssumeRolePolicy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v", " {\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": \"sts:AssumeRole\",\n", " \"Principal\": {\n", " \"Service\": \"ec2.amazonaws.com\"\n", " },\n", " \"Effect\": \"Allow\",\n", " \"Sid\": \"\"\n", " }\n", " ]\n", " }\n", "\n")),
})
if err != nil {
return err
}
policy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
Description: pulumi.String("A test policy"),
Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": [\n", " \"ec2:Describe*\"\n", " ],\n", " \"Effect\": \"Allow\",\n", " \"Resource\": \"*\"\n", " }\n", " ]\n", "}\n", "\n")),
})
if err != nil {
return err
}
_, err = iam.NewRolePolicyAttachment(ctx, "test_attach", &iam.RolePolicyAttachmentArgs{
PolicyArn: policy.Arn,
Role: role.Name,
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
role = aws.iam.Role("role", assume_role_policy=""" {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
""")
policy = aws.iam.Policy("policy",
description="A test policy",
policy="""{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
""")
test_attach = aws.iam.RolePolicyAttachment("test-attach",
policy_arn=policy.arn,
role=role.name)import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const role = new aws.iam.Role("role", {
assumeRolePolicy: ` {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
`,
});
const policy = new aws.iam.Policy("policy", {
description: "A test policy",
policy: `{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
`,
});
const test_attach = new aws.iam.RolePolicyAttachment("test-attach", {
policyArn: policy.arn,
role: role.name,
});Create a RolePolicyAttachment Resource
new RolePolicyAttachment(name: string, args: RolePolicyAttachmentArgs, opts?: CustomResourceOptions);def RolePolicyAttachment(resource_name, opts=None, policy_arn=None, role=None, __props__=None);func NewRolePolicyAttachment(ctx *Context, name string, args RolePolicyAttachmentArgs, opts ...ResourceOption) (*RolePolicyAttachment, error)public RolePolicyAttachment(string name, RolePolicyAttachmentArgs args, CustomResourceOptions? opts = null)- 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.
- opts ResourceOptions
- A bag of options that control this 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.
RolePolicyAttachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The RolePolicyAttachment resource accepts the following input properties:
- policy_
arn str The ARN of the policy you want to apply
- role string | str
The role the policy should be applied to
Outputs
All input properties are implicitly available as output properties. Additionally, the RolePolicyAttachment resource produces the following output properties:
Look up an 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): RolePolicyAttachmentstatic get(resource_name, id, opts=None, policy_arn=None, role=None, __props__=None);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)- 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.
The following state arguments are supported:
- policy_
arn str The ARN of the policy you want to apply
- role string | str
The role the policy should be applied to
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.