RolePolicy
Provides an IAM role inline policy.
Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var testRole = new Aws.Iam.Role("testRole", new Aws.Iam.RoleArgs
{
AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""Service"": ""ec2.amazonaws.com""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}
",
});
var testPolicy = new Aws.Iam.RolePolicy("testPolicy", new Aws.Iam.RolePolicyArgs
{
Role = testRole.Id,
Policy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": [
""ec2:Describe*""
],
""Effect"": ""Allow"",
""Resource"": ""*""
}
]
}
",
});
}
}
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 {
testRole, err := iam.NewRole(ctx, "testRole", &iam.RoleArgs{
AssumeRolePolicy: 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\": \"sts:AssumeRole\",\n", " \"Principal\": {\n", " \"Service\": \"ec2.amazonaws.com\"\n", " },\n", " \"Effect\": \"Allow\",\n", " \"Sid\": \"\"\n", " }\n", " ]\n", "}\n")),
})
if err != nil {
return err
}
_, err = iam.NewRolePolicy(ctx, "testPolicy", &iam.RolePolicyArgs{
Role: testRole.ID(),
Policy: pulumi.String(fmt.Sprintf("%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")),
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
test_role = aws.iam.Role("testRole", assume_role_policy="""{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
""")
test_policy = aws.iam.RolePolicy("testPolicy",
role=test_role.id,
policy="""{
"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: `{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
`});
const testPolicy = new aws.iam.RolePolicy("testPolicy", {
role: testRole.id,
policy: `{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
`,
});Create a RolePolicy Resource
new RolePolicy(name: string, args: RolePolicyArgs, opts?: CustomResourceOptions);def RolePolicy(resource_name, opts=None, name=None, name_prefix=None, policy=None, role=None, __props__=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.
- 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 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
The policy document. This is a JSON formatted string.
- Role 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.
- Name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.
- Policy interface{}
The policy document. This is a JSON formatted string.
- Role interface{}
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.
- Name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.
- policy
string | Policy
Document 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.
- name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.
- policy string | str
The policy document. This is a JSON formatted string.
- role string | 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:
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): RolePolicystatic get(resource_name, id, opts=None, name=None, name_prefix=None, policy=None, role=None, __props__=None);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.
- Name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.- Policy string
The policy document. This is a JSON formatted string.
- Role 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.
- Name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.- Policy interface{}
The policy document. This is a JSON formatted string.
- Role interface{}
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.
- name
Prefix string Creates a unique name beginning with the specified prefix. Conflicts with
name.- policy
string | Policy
Document 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 string | str
The policy document. This is a JSON formatted string.
- role string | str
The IAM role to attach to the policy.
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.