1. Packages
  2. AWS IAM
  3. API Docs
  4. Policy
AWS IAM v0.0.3 published on Wednesday, Jun 1, 2022 by Pulumi

aws-iam.Policy

Explore with Pulumi AI

This resource helps you create an IAM policy.

Example Usage

using Pulumi;
using Pulumi.AwsIam;
using Pulumi.AwsIam.Inputs;

class MyStack : Stack
{
    public MyStack()
    {
        var policy = new Policy("policy", new PolicyArgs
        {
            Name = "example",
            Path = "/",
            Description = "My example policy",
            PolicyDocument =
                @"{
                ""Version"": ""2012-10-17"",
                ""Statement"": [
                {
                    ""Action"": [
                    ""ec2:Describe*""
                    ],
                    ""Effect"": ""Allow"",
                    ""Resource"": ""*""
                }
                ]
            }"
        });
    }

    [Output]
    public Output<Policy> Policy { get; set; }
}
Copy
package main

import (
    "encoding/json"

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

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        policyJSON, err := json.Marshal(map[string]interface{}{
            "Version": "2012-10-17",
            "Statement": []interface{}{
                map[string]interface{}{
                    "Effect":   "Allow",
                    "Action":   []string{"ec2:Describe"},
                    "Resource": []string{"*"},
                },
            },
        })
        if err != nil {
            return err
        }

        policy, err := iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
            Name:           pulumi.String("example"),
            Path:           pulumi.String("/"),
            Description:    pulumi.String("My example policy"),
            PolicyDocument: pulumi.String(string(policyJSON)),
        })
        if err != nil {
            return err
        }

        ctx.Export("policy", policy)

        return nil
    })
}
Copy

Coming soon!

import * as iam from "@pulumi/aws-iam";

export const policy = new iam.Policy("aws-iam-example-policy", {
    name: "aws-iam-example-policy",
    path: "/",
    description: "My example policy",
    policyDocument: `{
        "Version": "2012-10-17",
        "Statement": [
        {
            "Action": [
            "ec2:Describe*"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
        ]
    }`,
});
Copy
import json
import pulumi
import pulumi_aws_iam as iam

policy = iam.Policy(
    'policy',
    name='example',
    path='/',
    description='My example policy',
    policy_document=json.dumps({
        "Version": "2012-10-17",
        "Statement": [
        {
            "Action": [
            "ec2:Describe*"
            ],
            "Effect": "Allow",
            "Resource": "*"
        }
        ]
    })
)
Copy
name: awsiam-yaml
runtime: yaml
resources:
    policy:
        type: "aws-iam:index:Policy"
        properties:
            name: "example"
            path: "/"
            description: "My example policy"
            policyDocument: |
                {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
                            "Action": [
                                "ec2:Describe*"
                            ],
                            "Effect": "Allow",
                            "Resource": "*"
                        }
                    ]
                }                
outputs:
    policy: ${policy}
Copy

Create Policy Resource

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

Constructor syntax

new Policy(name: string, args: PolicyArgs, opts?: ComponentResourceOptions);
@overload
def Policy(resource_name: str,
           args: PolicyArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def Policy(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           name: Optional[str] = None,
           policy_document: Optional[str] = None,
           description: Optional[str] = None,
           path: Optional[str] = None,
           tags: Optional[Mapping[str, str]] = None)
func NewPolicy(ctx *Context, name string, args PolicyArgs, opts ...ResourceOption) (*Policy, error)
public Policy(string name, PolicyArgs args, ComponentResourceOptions? opts = null)
public Policy(String name, PolicyArgs args)
public Policy(String name, PolicyArgs args, ComponentResourceOptions options)
type: aws-iam:Policy
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. PolicyArgs
The arguments to resource properties.
opts ComponentResourceOptions
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. PolicyArgs
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. PolicyArgs
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. PolicyArgs
The arguments to resource properties.
opts ComponentResourceOptions
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. PolicyArgs
The arguments to resource properties.
options ComponentResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var policyResource = new AwsIam.Policy("policyResource", new()
{
    Name = "string",
    PolicyDocument = "string",
    Description = "string",
    Path = "string",
    Tags = 
    {
        { "string", "string" },
    },
});
Copy
example, err := awsiam.NewPolicy(ctx, "policyResource", &awsiam.PolicyArgs{
	Name:           pulumi.String("string"),
	PolicyDocument: pulumi.String("string"),
	Description:    pulumi.String("string"),
	Path:           pulumi.String("string"),
	Tags: pulumi.StringMap{
		"string": pulumi.String("string"),
	},
})
Copy
var policyResource = new Policy("policyResource", PolicyArgs.builder()
    .name("string")
    .policyDocument("string")
    .description("string")
    .path("string")
    .tags(Map.of("string", "string"))
    .build());
Copy
policy_resource = aws_iam.Policy("policyResource",
    name="string",
    policy_document="string",
    description="string",
    path="string",
    tags={
        "string": "string",
    })
Copy
const policyResource = new aws_iam.Policy("policyResource", {
    name: "string",
    policyDocument: "string",
    description: "string",
    path: "string",
    tags: {
        string: "string",
    },
});
Copy
type: aws-iam:Policy
properties:
    description: string
    name: string
    path: string
    policyDocument: string
    tags:
        string: string
Copy

Policy 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 Policy resource accepts the following input properties:

Name This property is required. string
The name of the policy.
PolicyDocument This property is required. string
The policy document.
Description string
The description of the policy.
Path string
The path of the policy in IAM.
Tags Dictionary<string, string>
A map of tags to add.
Name This property is required. string
The name of the policy.
PolicyDocument This property is required. string
The policy document.
Description string
The description of the policy.
Path string
The path of the policy in IAM.
Tags map[string]string
A map of tags to add.
name This property is required. String
The name of the policy.
policyDocument This property is required. String
The policy document.
description String
The description of the policy.
path String
The path of the policy in IAM.
tags Map<String,String>
A map of tags to add.
name This property is required. string
The name of the policy.
policyDocument This property is required. string
The policy document.
description string
The description of the policy.
path string
The path of the policy in IAM.
tags {[key: string]: string}
A map of tags to add.
name This property is required. str
The name of the policy.
policy_document This property is required. str
The policy document.
description str
The description of the policy.
path str
The path of the policy in IAM.
tags Mapping[str, str]
A map of tags to add.
name This property is required. String
The name of the policy.
policyDocument This property is required. String
The policy document.
description String
The description of the policy.
path String
The path of the policy in IAM.
tags Map<String>
A map of tags to add.

Outputs

All input properties are implicitly available as output properties. Additionally, the Policy resource produces the following output properties:

Arn string
The ARN assigned by AWS to this policy.
Id string
The policy's ID.
Arn string
The ARN assigned by AWS to this policy.
Id string
The policy's ID.
arn String
The ARN assigned by AWS to this policy.
id String
The policy's ID.
arn string
The ARN assigned by AWS to this policy.
id string
The policy's ID.
arn str
The ARN assigned by AWS to this policy.
id str
The policy's ID.
arn String
The ARN assigned by AWS to this policy.
id String
The policy's ID.

Package Details

Repository
aws-iam
License