Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQS policies need access to their own ARN #4354

Closed
mdevs5531 opened this issue Dec 16, 2015 · 12 comments
Closed

SQS policies need access to their own ARN #4354

mdevs5531 opened this issue Dec 16, 2015 · 12 comments

Comments

@mdevs5531
Copy link

Moving from thread: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/terraform-tool/Pw6Ffuw1Muc

SQS policies require the 'Resource' value to be set to their own ARN, which doesn't exist until after the SQS is created. Because of this it's not possible to create a policy attached to an SQS with Terraform, either with an inline policy using ${self.arn} or rendered from a template resource as both result in circular dependencies.

From @phinze "...from a brief look at the code it looks like we just need to avoid setting the Policy attribute during our call to CreateQueue, instead delaying it for a subsequent SetQueueAttributes call."

@jemmyw
Copy link

jemmyw commented Jan 8, 2016

+1, this bit me today

@jemmyw
Copy link

jemmyw commented Jan 9, 2016

Actually, it's possible to set the arn in the policy on creation using known data.

"Resource": "arn:aws:sqs:${var.region}:${var.account_id}:queue-name"

@mdevs5531
Copy link
Author

That's similar to the workaround I'm using - however with that approach I still get a diff for the queue policy every time I run terraform plan.

@jemmyw
Copy link

jemmyw commented Jan 29, 2016

@mdevs5531 I'm not sure that is related. I had a similar problem, and it appeared to be a whitespace or formatting issue. In the end I fixed it by copying the policy directly from the state file, so it looks like:

  policy = "{\"Version\":\"2012-10-17\",\"Id\":\"arn:aws:sqs:${var.region}:${var.account_id}:${element(split(",", var.stage_names), count.index)}-save-results/policy\",\"Statement\":[{\"Sid\":\"Sid1452335512675\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"SQS:*\",\"Resource\":\"arn:aws:sqs:${var.region}:${var.account_id}:${element(split(",", var.stage_names), count.index)}-save-results\",\"Condition\":{\"StringLike\":{\"aws:SourceArn\":\"arn:aws:sns:${var.region}:${var.account_id}:*\"}}}]}"

Harder to manage, but it does work.

@sp-ludovic-ivain
Copy link

-> #3549

@mrwilby
Copy link

mrwilby commented Mar 10, 2016

Also bit me today.

@wsh
Copy link

wsh commented Mar 21, 2016

+1 this is annoying me right now.

@rcousens
Copy link

@phinze if I had to submit a PR to address this, would you prefer 2 step operation or a second resource type for an SQS queue policy?

@devinsba
Copy link

For anyone who is looking for a quick workaround, we came up with the following. Obviously its not terribly clean to have it as a stack but it will at least preserve the dependency tree:

resource "aws_cloudformation_stack" "security" {
  name = "security-settings"
  template_body = <<STACK
{
  "Resources" : {
    "sqsPolicy": {
       "Type" : "AWS::SQS::QueuePolicy",
       "Properties" : {
          "PolicyDocument" : {
            "Statement": [
              {
                "Effect": "Allow",
                "Principal": "*",
                "Action": [
                  "SQS:SendMessage",
                  "SQS:ReceiveMessage"
                ],
                "Resource": "${aws_sqs_queue.queue_resource.arn}"
              },
              {
                "Effect": "Allow",
                "Principal": "*",
                "Action": "SQS:*",
                "Resource": "${aws_sqs_queue.queue_resource.arn}"
              }
            ]
          },
          "Queues" : [ "${aws_sqs_queue.queue_resource.id}" ]
       }
    }
  }
}
STACK
}

@conorgil
Copy link

conorgil commented Sep 8, 2016

I think this issue may be resolved by #8657 released in v0.7.3

@radeksimko
Copy link
Member

radeksimko commented Sep 11, 2016

Correct @conorgil aws_sqs_queue_policy was meant to address this problem.
Documentation is at https://www.terraform.io/docs/providers/aws/r/sqs_queue_policy.html

Do let us know if you have any issues with this new resource.

@ghost
Copy link

ghost commented Apr 22, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants