Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.pulumi.aws.sns.kotlin.TopicPolicy.kt Maven / Gradle / Ivy
@file:Suppress("NAME_SHADOWING", "DEPRECATION")
package com.pulumi.aws.sns.kotlin
import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
/**
* Builder for [TopicPolicy].
*/
@PulumiTagMarker
public class TopicPolicyResourceBuilder internal constructor() {
public var name: String? = null
public var args: TopicPolicyArgs = TopicPolicyArgs()
public var opts: CustomResourceOptions = CustomResourceOptions()
/**
* @param name The _unique_ name of the resulting resource.
*/
public fun name(`value`: String) {
this.name = value
}
/**
* @param block The arguments to use to populate this resource's properties.
*/
public suspend fun args(block: suspend TopicPolicyArgsBuilder.() -> Unit) {
val builder = TopicPolicyArgsBuilder()
block(builder)
this.args = builder.build()
}
/**
* @param block A bag of options that control this resource's behavior.
*/
public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
}
internal fun build(): TopicPolicy {
val builtJavaResource = com.pulumi.aws.sns.TopicPolicy(
this.name,
this.args.toJava(),
this.opts.toJava(),
)
return TopicPolicy(builtJavaResource)
}
}
/**
* 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
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
* const test = new aws.sns.Topic("test", {name: "my-topic-with-policy"});
* const snsTopicPolicy = test.arn.apply(arn => aws.iam.getPolicyDocumentOutput({
* 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",
* variable: "AWS:SourceOwner",
* values: [account_id],
* }],
* effect: "Allow",
* principals: [{
* type: "AWS",
* identifiers: ["*"],
* }],
* resources: [arn],
* sid: "__default_statement_ID",
* }],
* }));
* const _default = new aws.sns.TopicPolicy("default", {
* arn: test.arn,
* policy: snsTopicPolicy.apply(snsTopicPolicy => snsTopicPolicy.json),
* });
* ```
* ```python
* import pulumi
* import pulumi_aws as aws
* test = aws.sns.Topic("test", name="my-topic-with-policy")
* sns_topic_policy = test.arn.apply(lambda arn: aws.iam.get_policy_document_output(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",
* "variable": "AWS:SourceOwner",
* "values": [account_id],
* }],
* "effect": "Allow",
* "principals": [{
* "type": "AWS",
* "identifiers": ["*"],
* }],
* "resources": [arn],
* "sid": "__default_statement_ID",
* }]))
* default = aws.sns.TopicPolicy("default",
* arn=test.arn,
* policy=sns_topic_policy.json)
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Aws = Pulumi.Aws;
* return await Deployment.RunAsync(() =>
* {
* var test = new Aws.Sns.Topic("test", new()
* {
* Name = "my-topic-with-policy",
* });
* var snsTopicPolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
* {
* PolicyId = "__default_policy_ID",
* Statements = new[]
* {
* new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
* {
* Actions = new[]
* {
* "SNS:Subscribe",
* "SNS:SetTopicAttributes",
* "SNS:RemovePermission",
* "SNS:Receive",
* "SNS:Publish",
* "SNS:ListSubscriptionsByTopic",
* "SNS:GetTopicAttributes",
* "SNS:DeleteTopic",
* "SNS:AddPermission",
* },
* Conditions = new[]
* {
* new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
* {
* Test = "StringEquals",
* Variable = "AWS:SourceOwner",
* Values = new[]
* {
* account_id,
* },
* },
* },
* Effect = "Allow",
* Principals = new[]
* {
* new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
* {
* Type = "AWS",
* Identifiers = new[]
* {
* "*",
* },
* },
* },
* Resources = new[]
* {
* test.Arn,
* },
* Sid = "__default_statement_ID",
* },
* },
* });
* var @default = new Aws.Sns.TopicPolicy("default", new()
* {
* Arn = test.Arn,
* Policy = snsTopicPolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
* "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* test, err := sns.NewTopic(ctx, "test", &sns.TopicArgs{
* Name: pulumi.String("my-topic-with-policy"),
* })
* if err != nil {
* return err
* }
* snsTopicPolicy := test.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
* return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
* PolicyId: "__default_policy_ID",
* Statements: []iam.GetPolicyDocumentStatement{
* {
* Actions: []string{
* "SNS:Subscribe",
* "SNS:SetTopicAttributes",
* "SNS:RemovePermission",
* "SNS:Receive",
* "SNS:Publish",
* "SNS:ListSubscriptionsByTopic",
* "SNS:GetTopicAttributes",
* "SNS:DeleteTopic",
* "SNS:AddPermission",
* },
* Conditions: []iam.GetPolicyDocumentStatementCondition{
* {
* Test: "StringEquals",
* Variable: "AWS:SourceOwner",
* Values: interface{}{
* account_id,
* },
* },
* },
* Effect: "Allow",
* Principals: []iam.GetPolicyDocumentStatementPrincipal{
* {
* Type: "AWS",
* Identifiers: []string{
* "*",
* },
* },
* },
* Resources: interface{}{
* arn,
* },
* Sid: "__default_statement_ID",
* },
* },
* }, nil))), nil
* }).(iam.GetPolicyDocumentResultOutput)
* _, err = sns.NewTopicPolicy(ctx, "default", &sns.TopicPolicyArgs{
* Arn: test.Arn,
* Policy: pulumi.String(snsTopicPolicy.ApplyT(func(snsTopicPolicy iam.GetPolicyDocumentResult) (*string, error) {
* return &snsTopicPolicy.Json, nil
* }).(pulumi.StringPtrOutput)),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.aws.sns.Topic;
* import com.pulumi.aws.sns.TopicArgs;
* import com.pulumi.aws.iam.IamFunctions;
* import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
* import com.pulumi.aws.sns.TopicPolicy;
* import com.pulumi.aws.sns.TopicPolicyArgs;
* import java.util.List;
* import java.util.ArrayList;
* import java.util.Map;
* import java.io.File;
* import java.nio.file.Files;
* import java.nio.file.Paths;
* public class App {
* public static void main(String[] args) {
* Pulumi.run(App::stack);
* }
* public static void stack(Context ctx) {
* var test = new Topic("test", TopicArgs.builder()
* .name("my-topic-with-policy")
* .build());
* final var snsTopicPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
* .policyId("__default_policy_ID")
* .statements(GetPolicyDocumentStatementArgs.builder()
* .actions(
* "SNS:Subscribe",
* "SNS:SetTopicAttributes",
* "SNS:RemovePermission",
* "SNS:Receive",
* "SNS:Publish",
* "SNS:ListSubscriptionsByTopic",
* "SNS:GetTopicAttributes",
* "SNS:DeleteTopic",
* "SNS:AddPermission")
* .conditions(GetPolicyDocumentStatementConditionArgs.builder()
* .test("StringEquals")
* .variable("AWS:SourceOwner")
* .values(account_id)
* .build())
* .effect("Allow")
* .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
* .type("AWS")
* .identifiers("*")
* .build())
* .resources(test.arn())
* .sid("__default_statement_ID")
* .build())
* .build());
* var default_ = new TopicPolicy("default", TopicPolicyArgs.builder()
* .arn(test.arn())
* .policy(snsTopicPolicy.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult).applyValue(snsTopicPolicy -> snsTopicPolicy.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json())))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* test:
* type: aws:sns:Topic
* properties:
* name: my-topic-with-policy
* default:
* type: aws:sns:TopicPolicy
* properties:
* arn: ${test.arn}
* policy: ${snsTopicPolicy.json}
* variables:
* snsTopicPolicy:
* fn::invoke:
* Function: aws:iam:getPolicyDocument
* Arguments:
* 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
* variable: AWS:SourceOwner
* values:
* - ${["account-id"]}
* effect: Allow
* principals:
* - type: AWS
* identifiers:
* - '*'
* resources:
* - ${test.arn}
* sid: __default_statement_ID
* ```
*
* ## Import
* Using `pulumi import`, import SNS Topic Policy using the topic ARN. For example:
* ```sh
* $ pulumi import aws:sns/topicPolicy:TopicPolicy user_updates arn:aws:sns:us-west-2:0123456789012:my-topic
* ```
*/
public class TopicPolicy internal constructor(
override val javaResource: com.pulumi.aws.sns.TopicPolicy,
) : KotlinCustomResource(javaResource, TopicPolicyMapper) {
/**
* The ARN of the SNS topic
*/
public val arn: Output
get() = javaResource.arn().applyValue({ args0 -> args0 })
/**
* The AWS Account ID of the SNS topic owner
*/
public val owner: Output
get() = javaResource.owner().applyValue({ args0 -> args0 })
/**
* The fully-formed AWS policy as JSON.
*/
public val policy: Output
get() = javaResource.policy().applyValue({ args0 -> args0 })
}
public object TopicPolicyMapper : ResourceMapper {
override fun supportsMappingOfType(javaResource: Resource): Boolean =
com.pulumi.aws.sns.TopicPolicy::class == javaResource::class
override fun map(javaResource: Resource): TopicPolicy = TopicPolicy(
javaResource as
com.pulumi.aws.sns.TopicPolicy,
)
}
/**
* @see [TopicPolicy].
* @param name The _unique_ name of the resulting resource.
* @param block Builder for [TopicPolicy].
*/
public suspend fun topicPolicy(name: String, block: suspend TopicPolicyResourceBuilder.() -> Unit): TopicPolicy {
val builder = TopicPolicyResourceBuilder()
builder.name(name)
block(builder)
return builder.build()
}
/**
* @see [TopicPolicy].
* @param name The _unique_ name of the resulting resource.
*/
public fun topicPolicy(name: String): TopicPolicy {
val builder = TopicPolicyResourceBuilder()
builder.name(name)
return builder.build()
}