TopicPolicy

Provides an SNS topic policy resource

NOTE: If a Principal is specified as just an AWS account ID rather than an ARN, AWS silently converts it to the ARN for the root user, causing future deployments to differ. To avoid this problem, just specify the full ARN, e.g. arn:aws:iam::123456789012:root

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var test = new Aws.Sns.Topic("test", new Aws.Sns.TopicArgs
        {
        });
        var snsTopicPolicy = test.Arn.Apply(arn => Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
        {
            PolicyId = "__default_policy_ID",
            Statements = 
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
                {
                    Actions = 
                    {
                        "SNS:Subscribe",
                        "SNS:SetTopicAttributes",
                        "SNS:RemovePermission",
                        "SNS:Receive",
                        "SNS:Publish",
                        "SNS:ListSubscriptionsByTopic",
                        "SNS:GetTopicAttributes",
                        "SNS:DeleteTopic",
                        "SNS:AddPermission",
                    },
                    Conditions = 
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionArgs
                        {
                            Test = "StringEquals",
                            Values = 
                            {
                                @var.Account_id,
                            },
                            Variable = "AWS:SourceOwner",
                        },
                    },
                    Effect = "Allow",
                    Principals = 
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalArgs
                        {
                            Identifiers = 
                            {
                                "*",
                            },
                            Type = "AWS",
                        },
                    },
                    Resources = 
                    {
                        arn,
                    },
                    Sid = "__default_statement_ID",
                },
            },
        }));
        var @default = new Aws.Sns.TopicPolicy("default", new Aws.Sns.TopicPolicyArgs
        {
            Arn = test.Arn,
            Policy = snsTopicPolicy.Apply(snsTopicPolicy => snsTopicPolicy.Json),
        });
    }

}
package main

import (
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam"
    "github.com/pulumi/pulumi-aws/sdk/v2/go/aws/sns"
    "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        test, err := sns.NewTopic(ctx, "test", nil)
        if err != nil {
            return err
        }
        _, err = sns.NewTopicPolicy(ctx, "_default", &sns.TopicPolicyArgs{
            Arn: test.Arn,
            Policy: snsTopicPolicy.ApplyT(func(snsTopicPolicy iam.GetPolicyDocumentResult) (string, error) {
                return snsTopicPolicy.Json, nil
            }).(pulumi.StringOutput),
        })
        if err != nil {
            return err
        }
        return nil
    })
}
import pulumi
import pulumi_aws as aws

test = aws.sns.Topic("test")
sns_topic_policy = test.arn.apply(lambda arn: aws.iam.get_policy_document(policy_id="__default_policy_ID",
    statements=[{
        "actions": [
            "SNS:Subscribe",
            "SNS:SetTopicAttributes",
            "SNS:RemovePermission",
            "SNS:Receive",
            "SNS:Publish",
            "SNS:ListSubscriptionsByTopic",
            "SNS:GetTopicAttributes",
            "SNS:DeleteTopic",
            "SNS:AddPermission",
        ],
        "conditions": [{
            "test": "StringEquals",
            "values": [var["account-id"]],
            "variable": "AWS:SourceOwner",
        }],
        "effect": "Allow",
        "principals": [{
            "identifiers": ["*"],
            "type": "AWS",
        }],
        "resources": [arn],
        "sid": "__default_statement_ID",
    }]))
default = aws.sns.TopicPolicy("default",
    arn=test.arn,
    policy=sns_topic_policy.json)
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const test = new aws.sns.Topic("test", {});
const snsTopicPolicy = test.arn.apply(arn => aws.iam.getPolicyDocument({
    policyId: "__default_policy_ID",
    statements: [{
        actions: [
            "SNS:Subscribe",
            "SNS:SetTopicAttributes",
            "SNS:RemovePermission",
            "SNS:Receive",
            "SNS:Publish",
            "SNS:ListSubscriptionsByTopic",
            "SNS:GetTopicAttributes",
            "SNS:DeleteTopic",
            "SNS:AddPermission",
        ],
        conditions: [{
            test: "StringEquals",
            values: [var_account_id],
            variable: "AWS:SourceOwner",
        }],
        effect: "Allow",
        principals: [{
            identifiers: ["*"],
            type: "AWS",
        }],
        resources: [arn],
        sid: "__default_statement_ID",
    }],
}, { async: true }));
const defaultTopicPolicy = new aws.sns.TopicPolicy("default", {
    arn: test.arn,
    policy: snsTopicPolicy.json,
});

Create a TopicPolicy Resource

def TopicPolicy(resource_name, opts=None, arn=None, policy=None, __props__=None);
func NewTopicPolicy(ctx *Context, name string, args TopicPolicyArgs, opts ...ResourceOption) (*TopicPolicy, error)
public TopicPolicy(string name, TopicPolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args TopicPolicyArgs
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 TopicPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args TopicPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

TopicPolicy Resource Properties

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

Inputs

The TopicPolicy resource accepts the following input properties:

Arn string

The ARN of the SNS topic

Policy string

The fully-formed AWS policy as JSON.

Arn string

The ARN of the SNS topic

Policy string

The fully-formed AWS policy as JSON.

arn string

The ARN of the SNS topic

policy string

The fully-formed AWS policy as JSON.

arn str

The ARN of the SNS topic

policy str

The fully-formed AWS policy as JSON.

Outputs

All input properties are implicitly available as output properties. Additionally, the TopicPolicy 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 TopicPolicy Resource

Get an existing TopicPolicy 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?: TopicPolicyState, opts?: CustomResourceOptions): TopicPolicy
static get(resource_name, id, opts=None, arn=None, policy=None, __props__=None);
func GetTopicPolicy(ctx *Context, name string, id IDInput, state *TopicPolicyState, opts ...ResourceOption) (*TopicPolicy, error)
public static TopicPolicy Get(string name, Input<string> id, TopicPolicyState? 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:

Arn string

The ARN of the SNS topic

Policy string

The fully-formed AWS policy as JSON.

Arn string

The ARN of the SNS topic

Policy string

The fully-formed AWS policy as JSON.

arn string

The ARN of the SNS topic

policy string

The fully-formed AWS policy as JSON.

arn str

The ARN of the SNS topic

policy str

The fully-formed AWS policy as JSON.

Package Details

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