Class QueuePolicy


  • public class QueuePolicy
    extends com.pulumi.resources.CustomResource
    Allows you to set a policy of an SQS Queue while referencing the ARN of the queue within the policy. > AWS will hang indefinitely when creating or updating an `aws.sqs.Queue` with an associated policy if `Version = "2012-10-17"` is not explicitly set in the policy. See below for an example of how to avoid this issue. ## Example Usage ### Basic Usage
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.sqs.Queue;
     import com.pulumi.aws.sqs.QueueArgs;
     import com.pulumi.aws.iam.IamFunctions;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementConditionArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
     import com.pulumi.aws.sqs.QueuePolicy;
     import com.pulumi.aws.sqs.QueuePolicyArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     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 q = new Queue("q", QueueArgs.builder()
                 .name("examplequeue")
                 .build());
     
             final var test = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                 .statements(GetPolicyDocumentStatementArgs.builder()
                     .conditions(GetPolicyDocumentStatementConditionArgs.builder()
                         .test("ArnEquals")
                         .variable("aws:SourceArn")
                         .values(example.arn())
                         .build())
                     .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                         .type("*")
                         .identifiers("*")
                         .build())
                     .sid("First")
                     .effect("Allow")
                     .actions("sqs:SendMessage")
                     .resources(q.arn())
                     .build())
                 .build());
     
             var testQueuePolicy = new QueuePolicy("testQueuePolicy", QueuePolicyArgs.builder()
                 .queueUrl(q.id())
                 .policy(test.applyValue(_test -> _test.json()))
                 .build());
     
         }
     }
     
     
    ### Timeout Problems Creating/Updating If `Version = "2012-10-17"` is not explicitly set in the policy, AWS may hang, causing the AWS provider to time out. To avoid this, make sure to include `Version` as shown in the example below.
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.s3.Bucket;
     import com.pulumi.aws.s3.BucketArgs;
     import com.pulumi.aws.sqs.Queue;
     import com.pulumi.aws.sqs.QueueArgs;
     import com.pulumi.aws.sqs.QueuePolicy;
     import com.pulumi.aws.sqs.QueuePolicyArgs;
     import static com.pulumi.codegen.internal.Serialization.*;
     import java.util.ArrayList;
     import java.util.Arrays;
     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 example = new Bucket("example", BucketArgs.builder()
                 .bucket("brodobaggins")
                 .build());
     
             var exampleQueue = new Queue("exampleQueue", QueueArgs.builder()
                 .name("be-giant")
                 .build());
     
             var exampleQueuePolicy = new QueuePolicy("exampleQueuePolicy", QueuePolicyArgs.builder()
                 .queueUrl(exampleQueue.id())
                 .policy(Output.tuple(exampleQueue.arn(), example.arn()).applyValue(values -> {
                     var exampleQueueArn = values.t1;
                     var exampleArn = values.t2;
                     return serializeJson(
                         jsonObject(
                             jsonProperty("Version", "2012-10-17"),
                             jsonProperty("Statement", jsonArray(jsonObject(
                                 jsonProperty("Sid", "Cejuwdam"),
                                 jsonProperty("Effect", "Allow"),
                                 jsonProperty("Principal", jsonObject(
                                     jsonProperty("Service", "s3.amazonaws.com")
                                 )),
                                 jsonProperty("Action", "SQS:SendMessage"),
                                 jsonProperty("Resource", exampleQueueArn),
                                 jsonProperty("Condition", jsonObject(
                                     jsonProperty("ArnLike", jsonObject(
                                         jsonProperty("aws:SourceArn", exampleArn)
                                     ))
                                 ))
                             )))
                         ));
                 }))
                 .build());
     
         }
     }
     
     
    ## Import ### Identity Schema #### Required * `queueUrl` (String) URL of the SQS Queue. Using `pulumi import`, import SQS Queue Policies using the queue URL. For example: ```sh $ pulumi import aws:sqs/queuePolicy:QueuePolicy test https://queue.amazonaws.com/123456789012/myqueue ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static QueuePolicy get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, QueuePolicyState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.lang.String> policy()  
      com.pulumi.core.Output<java.lang.String> queueUrl()  
      com.pulumi.core.Output<java.lang.String> region()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • QueuePolicy

        public QueuePolicy​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • QueuePolicy

        public QueuePolicy​(java.lang.String name,
                           QueuePolicyArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • QueuePolicy

        public QueuePolicy​(java.lang.String name,
                           QueuePolicyArgs args,
                           @Nullable
                           com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • policy

        public com.pulumi.core.Output<java.lang.String> policy()
        Returns:
        JSON policy for the SQS queue. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. Ensure that `Version = "2012-10-17"` is set in the policy or AWS may hang in creating the queue.
      • queueUrl

        public com.pulumi.core.Output<java.lang.String> queueUrl()
        Returns:
        URL of the SQS Queue to which to attach the policy.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • get

        public static QueuePolicy get​(java.lang.String name,
                                      com.pulumi.core.Output<java.lang.String> id,
                                      @Nullable
                                      QueuePolicyState state,
                                      @Nullable
                                      com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.