RolePolicy

Provides an IAM role inline policy.

NOTE: For a given role, this resource is incompatible with using the aws.iam.Role resource inline_policy argument. When using that argument and this resource, both will attempt to manage the role’s inline policies and the provider will show a permanent difference.

Example Usage

using System.Collections.Generic;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var testRole = new Aws.Iam.Role("testRole", new Aws.Iam.RoleArgs
        {
            AssumeRolePolicy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                { "Version", "2012-10-17" },
                { "Statement", new[]
                    {
                        new Dictionary<string, object?>
                        {
                            { "Action", "sts:AssumeRole" },
                            { "Effect", "Allow" },
                            { "Sid", "" },
                            { "Principal", new Dictionary<string, object?>
                            {
                                { "Service", "ec2.amazonaws.com" },
                            } },
                        },
                    }
                 },
            }),
        });
        var testPolicy = new Aws.Iam.RolePolicy("testPolicy", new Aws.Iam.RolePolicyArgs
        {
            Role = testRole.Id,
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                { "Version", "2012-10-17" },
                { "Statement", new[]
                    {
                        new Dictionary<string, object?>
                        {
                            { "Action", new[]
                                {
                                    "ec2:Describe*",
                                }
                             },
                            { "Effect", "Allow" },
                            { "Resource", "*" },
                        },
                    }
                 },
            }),
        });
    }

}
package main

import (
	"encoding/json"

	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/iam"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		tmpJSON0, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Action": "sts:AssumeRole",
					"Effect": "Allow",
					"Sid":    "",
					"Principal": map[string]interface{}{
						"Service": "ec2.amazonaws.com",
					},
				},
			},
		})
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		testRole, err := iam.NewRole(ctx, "testRole", &iam.RoleArgs{
			AssumeRolePolicy: pulumi.String(json0),
		})
		if err != nil {
			return err
		}
		tmpJSON1, err := json.Marshal(map[string]interface{}{
			"Version": "2012-10-17",
			"Statement": []map[string]interface{}{
				map[string]interface{}{
					"Action": []string{
						"ec2:Describe*",
					},
					"Effect":   "Allow",
					"Resource": "*",
				},
			},
		})
		if err != nil {
			return err
		}
		json1 := string(tmpJSON1)
		_, err = iam.NewRolePolicy(ctx, "testPolicy", &iam.RolePolicyArgs{
			Role:   testRole.ID(),
			Policy: pulumi.String(json1),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import json
import pulumi_aws as aws

test_role = aws.iam.Role("testRole", assume_role_policy=json.dumps({
    "Version": "2012-10-17",
    "Statement": [{
        "Action": "sts:AssumeRole",
        "Effect": "Allow",
        "Sid": "",
        "Principal": {
            "Service": "ec2.amazonaws.com",
        },
    }],
}))
test_policy = aws.iam.RolePolicy("testPolicy",
    role=test_role.id,
    policy=json.dumps({
        "Version": "2012-10-17",
        "Statement": [{
            "Action": ["ec2:Describe*"],
            "Effect": "Allow",
            "Resource": "*",
        }],
    }))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const testRole = new aws.iam.Role("testRole", {assumeRolePolicy: JSON.stringify({
    Version: "2012-10-17",
    Statement: [{
        Action: "sts:AssumeRole",
        Effect: "Allow",
        Sid: "",
        Principal: {
            Service: "ec2.amazonaws.com",
        },
    }],
})});
const testPolicy = new aws.iam.RolePolicy("testPolicy", {
    role: testRole.id,
    policy: JSON.stringify({
        Version: "2012-10-17",
        Statement: [{
            Action: ["ec2:Describe*"],
            Effect: "Allow",
            Resource: "*",
        }],
    }),
});

Create a RolePolicy Resource

new RolePolicy(name: string, args: RolePolicyArgs, opts?: CustomResourceOptions);
@overload
def RolePolicy(resource_name: str,
               opts: Optional[ResourceOptions] = None,
               name: Optional[str] = None,
               name_prefix: Optional[str] = None,
               policy: Optional[str] = None,
               role: Optional[str] = None)
@overload
def RolePolicy(resource_name: str,
               args: RolePolicyArgs,
               opts: Optional[ResourceOptions] = None)
func NewRolePolicy(ctx *Context, name string, args RolePolicyArgs, opts ...ResourceOption) (*RolePolicy, error)
public RolePolicy(string name, RolePolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args RolePolicyArgs
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 RolePolicyArgs
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 RolePolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args RolePolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

RolePolicy Resource Properties

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

Inputs

The RolePolicy resource accepts the following input properties:

Policy string | string
The policy document. This is a JSON formatted string.
Role string | string
The IAM role to attach to the policy.
Name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
NamePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
Policy string | string
The policy document. This is a JSON formatted string.
Role string | string
The IAM role to attach to the policy.
Name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
NamePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
policy string | PolicyDocument
The policy document. This is a JSON formatted string.
role string | Role
The IAM role to attach to the policy.
name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
namePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
policy str | str
The policy document. This is a JSON formatted string.
role str | str
The IAM role to attach to the policy.
name str
The name of the role policy. If omitted, this provider will assign a random, unique name.
name_prefix str
Creates a unique name beginning with the specified prefix. Conflicts with name.

Outputs

All input properties are implicitly available as output properties. Additionally, the RolePolicy 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 str
The provider-assigned unique ID for this managed resource.

Look up an Existing RolePolicy Resource

Get an existing RolePolicy 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?: RolePolicyState, opts?: CustomResourceOptions): RolePolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        name: Optional[str] = None,
        name_prefix: Optional[str] = None,
        policy: Optional[str] = None,
        role: Optional[str] = None) -> RolePolicy
func GetRolePolicy(ctx *Context, name string, id IDInput, state *RolePolicyState, opts ...ResourceOption) (*RolePolicy, error)
public static RolePolicy Get(string name, Input<string> id, RolePolicyState? 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:

Name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
NamePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
Policy string | string
The policy document. This is a JSON formatted string.
Role string | string
The IAM role to attach to the policy.
Name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
NamePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
Policy string | string
The policy document. This is a JSON formatted string.
Role string | string
The IAM role to attach to the policy.
name string
The name of the role policy. If omitted, this provider will assign a random, unique name.
namePrefix string
Creates a unique name beginning with the specified prefix. Conflicts with name.
policy string | PolicyDocument
The policy document. This is a JSON formatted string.
role string | Role
The IAM role to attach to the policy.
name str
The name of the role policy. If omitted, this provider will assign a random, unique name.
name_prefix str
Creates a unique name beginning with the specified prefix. Conflicts with name.
policy str | str
The policy document. This is a JSON formatted string.
role str | str
The IAM role to attach to the policy.

Import

IAM Role Policies can be imported using the role_name:role_policy_name, e.g.

 $ pulumi import aws:iam/rolePolicy:RolePolicy mypolicy role_of_mypolicy_name:mypolicy_name

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.