github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/sns/topicPolicy.go (about) 1 // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT. 2 // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! *** 3 4 package sns 5 6 import ( 7 "context" 8 "reflect" 9 10 "errors" 11 "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal" 12 "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 13 ) 14 15 // Provides an SNS topic policy resource 16 // 17 // > **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` 18 // 19 // ## Example Usage 20 // 21 // <!--Start PulumiCodeChooser --> 22 // ```go 23 // package main 24 // 25 // import ( 26 // 27 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam" 28 // "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns" 29 // "github.com/pulumi/pulumi/sdk/v3/go/pulumi" 30 // 31 // ) 32 // func main() { 33 // pulumi.Run(func(ctx *pulumi.Context) error { 34 // test, err := sns.NewTopic(ctx, "test", &sns.TopicArgs{ 35 // Name: pulumi.String("my-topic-with-policy"), 36 // }) 37 // if err != nil { 38 // return err 39 // } 40 // snsTopicPolicy := test.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) { 41 // return iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{ 42 // PolicyId: "__default_policy_ID", 43 // Statements: []iam.GetPolicyDocumentStatement{ 44 // { 45 // Actions: []string{ 46 // "SNS:Subscribe", 47 // "SNS:SetTopicAttributes", 48 // "SNS:RemovePermission", 49 // "SNS:Receive", 50 // "SNS:Publish", 51 // "SNS:ListSubscriptionsByTopic", 52 // "SNS:GetTopicAttributes", 53 // "SNS:DeleteTopic", 54 // "SNS:AddPermission", 55 // }, 56 // Conditions: []iam.GetPolicyDocumentStatementCondition{ 57 // { 58 // Test: "StringEquals", 59 // Variable: "AWS:SourceOwner", 60 // Values: interface{}{ 61 // account_id, 62 // }, 63 // }, 64 // }, 65 // Effect: "Allow", 66 // Principals: []iam.GetPolicyDocumentStatementPrincipal{ 67 // { 68 // Type: "AWS", 69 // Identifiers: []string{ 70 // "*", 71 // }, 72 // }, 73 // }, 74 // Resources: interface{}{ 75 // arn, 76 // }, 77 // Sid: "__default_statement_ID", 78 // }, 79 // }, 80 // }, nil), nil 81 // }).(iam.GetPolicyDocumentResultOutput) 82 // _, err = sns.NewTopicPolicy(ctx, "default", &sns.TopicPolicyArgs{ 83 // Arn: test.Arn, 84 // Policy: snsTopicPolicy.ApplyT(func(snsTopicPolicy iam.GetPolicyDocumentResult) (*string, error) { 85 // return &snsTopicPolicy.Json, nil 86 // }).(pulumi.StringPtrOutput), 87 // }) 88 // if err != nil { 89 // return err 90 // } 91 // return nil 92 // }) 93 // } 94 // ``` 95 // <!--End PulumiCodeChooser --> 96 // 97 // ## Import 98 // 99 // Using `pulumi import`, import SNS Topic Policy using the topic ARN. For example: 100 // 101 // ```sh 102 // $ pulumi import aws:sns/topicPolicy:TopicPolicy user_updates arn:aws:sns:us-west-2:0123456789012:my-topic 103 // ``` 104 type TopicPolicy struct { 105 pulumi.CustomResourceState 106 107 // The ARN of the SNS topic 108 Arn pulumi.StringOutput `pulumi:"arn"` 109 // The AWS Account ID of the SNS topic owner 110 Owner pulumi.StringOutput `pulumi:"owner"` 111 // The fully-formed AWS policy as JSON. 112 Policy pulumi.StringOutput `pulumi:"policy"` 113 } 114 115 // NewTopicPolicy registers a new resource with the given unique name, arguments, and options. 116 func NewTopicPolicy(ctx *pulumi.Context, 117 name string, args *TopicPolicyArgs, opts ...pulumi.ResourceOption) (*TopicPolicy, error) { 118 if args == nil { 119 return nil, errors.New("missing one or more required arguments") 120 } 121 122 if args.Arn == nil { 123 return nil, errors.New("invalid value for required argument 'Arn'") 124 } 125 if args.Policy == nil { 126 return nil, errors.New("invalid value for required argument 'Policy'") 127 } 128 opts = internal.PkgResourceDefaultOpts(opts) 129 var resource TopicPolicy 130 err := ctx.RegisterResource("aws:sns/topicPolicy:TopicPolicy", name, args, &resource, opts...) 131 if err != nil { 132 return nil, err 133 } 134 return &resource, nil 135 } 136 137 // GetTopicPolicy gets an existing TopicPolicy resource's state with the given name, ID, and optional 138 // state properties that are used to uniquely qualify the lookup (nil if not required). 139 func GetTopicPolicy(ctx *pulumi.Context, 140 name string, id pulumi.IDInput, state *TopicPolicyState, opts ...pulumi.ResourceOption) (*TopicPolicy, error) { 141 var resource TopicPolicy 142 err := ctx.ReadResource("aws:sns/topicPolicy:TopicPolicy", name, id, state, &resource, opts...) 143 if err != nil { 144 return nil, err 145 } 146 return &resource, nil 147 } 148 149 // Input properties used for looking up and filtering TopicPolicy resources. 150 type topicPolicyState struct { 151 // The ARN of the SNS topic 152 Arn *string `pulumi:"arn"` 153 // The AWS Account ID of the SNS topic owner 154 Owner *string `pulumi:"owner"` 155 // The fully-formed AWS policy as JSON. 156 Policy interface{} `pulumi:"policy"` 157 } 158 159 type TopicPolicyState struct { 160 // The ARN of the SNS topic 161 Arn pulumi.StringPtrInput 162 // The AWS Account ID of the SNS topic owner 163 Owner pulumi.StringPtrInput 164 // The fully-formed AWS policy as JSON. 165 Policy pulumi.Input 166 } 167 168 func (TopicPolicyState) ElementType() reflect.Type { 169 return reflect.TypeOf((*topicPolicyState)(nil)).Elem() 170 } 171 172 type topicPolicyArgs struct { 173 // The ARN of the SNS topic 174 Arn string `pulumi:"arn"` 175 // The fully-formed AWS policy as JSON. 176 Policy interface{} `pulumi:"policy"` 177 } 178 179 // The set of arguments for constructing a TopicPolicy resource. 180 type TopicPolicyArgs struct { 181 // The ARN of the SNS topic 182 Arn pulumi.StringInput 183 // The fully-formed AWS policy as JSON. 184 Policy pulumi.Input 185 } 186 187 func (TopicPolicyArgs) ElementType() reflect.Type { 188 return reflect.TypeOf((*topicPolicyArgs)(nil)).Elem() 189 } 190 191 type TopicPolicyInput interface { 192 pulumi.Input 193 194 ToTopicPolicyOutput() TopicPolicyOutput 195 ToTopicPolicyOutputWithContext(ctx context.Context) TopicPolicyOutput 196 } 197 198 func (*TopicPolicy) ElementType() reflect.Type { 199 return reflect.TypeOf((**TopicPolicy)(nil)).Elem() 200 } 201 202 func (i *TopicPolicy) ToTopicPolicyOutput() TopicPolicyOutput { 203 return i.ToTopicPolicyOutputWithContext(context.Background()) 204 } 205 206 func (i *TopicPolicy) ToTopicPolicyOutputWithContext(ctx context.Context) TopicPolicyOutput { 207 return pulumi.ToOutputWithContext(ctx, i).(TopicPolicyOutput) 208 } 209 210 // TopicPolicyArrayInput is an input type that accepts TopicPolicyArray and TopicPolicyArrayOutput values. 211 // You can construct a concrete instance of `TopicPolicyArrayInput` via: 212 // 213 // TopicPolicyArray{ TopicPolicyArgs{...} } 214 type TopicPolicyArrayInput interface { 215 pulumi.Input 216 217 ToTopicPolicyArrayOutput() TopicPolicyArrayOutput 218 ToTopicPolicyArrayOutputWithContext(context.Context) TopicPolicyArrayOutput 219 } 220 221 type TopicPolicyArray []TopicPolicyInput 222 223 func (TopicPolicyArray) ElementType() reflect.Type { 224 return reflect.TypeOf((*[]*TopicPolicy)(nil)).Elem() 225 } 226 227 func (i TopicPolicyArray) ToTopicPolicyArrayOutput() TopicPolicyArrayOutput { 228 return i.ToTopicPolicyArrayOutputWithContext(context.Background()) 229 } 230 231 func (i TopicPolicyArray) ToTopicPolicyArrayOutputWithContext(ctx context.Context) TopicPolicyArrayOutput { 232 return pulumi.ToOutputWithContext(ctx, i).(TopicPolicyArrayOutput) 233 } 234 235 // TopicPolicyMapInput is an input type that accepts TopicPolicyMap and TopicPolicyMapOutput values. 236 // You can construct a concrete instance of `TopicPolicyMapInput` via: 237 // 238 // TopicPolicyMap{ "key": TopicPolicyArgs{...} } 239 type TopicPolicyMapInput interface { 240 pulumi.Input 241 242 ToTopicPolicyMapOutput() TopicPolicyMapOutput 243 ToTopicPolicyMapOutputWithContext(context.Context) TopicPolicyMapOutput 244 } 245 246 type TopicPolicyMap map[string]TopicPolicyInput 247 248 func (TopicPolicyMap) ElementType() reflect.Type { 249 return reflect.TypeOf((*map[string]*TopicPolicy)(nil)).Elem() 250 } 251 252 func (i TopicPolicyMap) ToTopicPolicyMapOutput() TopicPolicyMapOutput { 253 return i.ToTopicPolicyMapOutputWithContext(context.Background()) 254 } 255 256 func (i TopicPolicyMap) ToTopicPolicyMapOutputWithContext(ctx context.Context) TopicPolicyMapOutput { 257 return pulumi.ToOutputWithContext(ctx, i).(TopicPolicyMapOutput) 258 } 259 260 type TopicPolicyOutput struct{ *pulumi.OutputState } 261 262 func (TopicPolicyOutput) ElementType() reflect.Type { 263 return reflect.TypeOf((**TopicPolicy)(nil)).Elem() 264 } 265 266 func (o TopicPolicyOutput) ToTopicPolicyOutput() TopicPolicyOutput { 267 return o 268 } 269 270 func (o TopicPolicyOutput) ToTopicPolicyOutputWithContext(ctx context.Context) TopicPolicyOutput { 271 return o 272 } 273 274 // The ARN of the SNS topic 275 func (o TopicPolicyOutput) Arn() pulumi.StringOutput { 276 return o.ApplyT(func(v *TopicPolicy) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput) 277 } 278 279 // The AWS Account ID of the SNS topic owner 280 func (o TopicPolicyOutput) Owner() pulumi.StringOutput { 281 return o.ApplyT(func(v *TopicPolicy) pulumi.StringOutput { return v.Owner }).(pulumi.StringOutput) 282 } 283 284 // The fully-formed AWS policy as JSON. 285 func (o TopicPolicyOutput) Policy() pulumi.StringOutput { 286 return o.ApplyT(func(v *TopicPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput) 287 } 288 289 type TopicPolicyArrayOutput struct{ *pulumi.OutputState } 290 291 func (TopicPolicyArrayOutput) ElementType() reflect.Type { 292 return reflect.TypeOf((*[]*TopicPolicy)(nil)).Elem() 293 } 294 295 func (o TopicPolicyArrayOutput) ToTopicPolicyArrayOutput() TopicPolicyArrayOutput { 296 return o 297 } 298 299 func (o TopicPolicyArrayOutput) ToTopicPolicyArrayOutputWithContext(ctx context.Context) TopicPolicyArrayOutput { 300 return o 301 } 302 303 func (o TopicPolicyArrayOutput) Index(i pulumi.IntInput) TopicPolicyOutput { 304 return pulumi.All(o, i).ApplyT(func(vs []interface{}) *TopicPolicy { 305 return vs[0].([]*TopicPolicy)[vs[1].(int)] 306 }).(TopicPolicyOutput) 307 } 308 309 type TopicPolicyMapOutput struct{ *pulumi.OutputState } 310 311 func (TopicPolicyMapOutput) ElementType() reflect.Type { 312 return reflect.TypeOf((*map[string]*TopicPolicy)(nil)).Elem() 313 } 314 315 func (o TopicPolicyMapOutput) ToTopicPolicyMapOutput() TopicPolicyMapOutput { 316 return o 317 } 318 319 func (o TopicPolicyMapOutput) ToTopicPolicyMapOutputWithContext(ctx context.Context) TopicPolicyMapOutput { 320 return o 321 } 322 323 func (o TopicPolicyMapOutput) MapIndex(k pulumi.StringInput) TopicPolicyOutput { 324 return pulumi.All(o, k).ApplyT(func(vs []interface{}) *TopicPolicy { 325 return vs[0].(map[string]*TopicPolicy)[vs[1].(string)] 326 }).(TopicPolicyOutput) 327 } 328 329 func init() { 330 pulumi.RegisterInputType(reflect.TypeOf((*TopicPolicyInput)(nil)).Elem(), &TopicPolicy{}) 331 pulumi.RegisterInputType(reflect.TypeOf((*TopicPolicyArrayInput)(nil)).Elem(), TopicPolicyArray{}) 332 pulumi.RegisterInputType(reflect.TypeOf((*TopicPolicyMapInput)(nil)).Elem(), TopicPolicyMap{}) 333 pulumi.RegisterOutputType(TopicPolicyOutput{}) 334 pulumi.RegisterOutputType(TopicPolicyArrayOutput{}) 335 pulumi.RegisterOutputType(TopicPolicyMapOutput{}) 336 }