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

aws_iam_policy_document orders actions anti-alphabetically #6107

Open
hubertgrzeskowiak opened this issue Oct 10, 2018 · 6 comments
Open

aws_iam_policy_document orders actions anti-alphabetically #6107

hubertgrzeskowiak opened this issue Oct 10, 2018 · 6 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service.

Comments

@hubertgrzeskowiak
Copy link

When describing an IAM policy document in HCL using the data statement, the entries are sorted from Z to A. If you happen to sort normally sort things alphabetically, this will cause confusion and diffs in plans.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.7

  • provider.aws v1.39.0

Affected Resource(s)

  • aws_iam_policy_document

Terraform Configuration Files

data "aws_iam_policy_document" "policy_doc" {
  statement {
    actions = [
      "autoscaling:Describe*",
      "cloudwatch:Describe*",
      "cloudwatch:Get*",
      "cloudwatch:List*",
      ...
      "sqs:GetQueueAttributes",
      "sqs:ListQueues",
      "sqs:ReceiveMessage",
      "tag:GetResources"
    ]
    effect = "Allow"
    resources = ["*"]
  }
}

output "user_policy_json" {
  value = "${data.aws_iam_policy_document.policy_doc.json}"
}

Expected Behavior

Actions sorted alphabetically.

user_policy_json = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Action": [
        "autoscaling:Describe*",
        "cloudwatch:Describe*",
        "cloudwatch:Get*",
        "cloudwatch:List*",
       ...
        "sqs:GetQueueAttributes",
        "sqs:ListQueues",
        "sqs:ReceiveMessage",
        "tag:GetResources"
      ],
      "Resource": "*"
    }
  ]
}

Actual Behavior

Actions sorted reverse alphabetically.

user_policy_json = {
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Action": [
        "tag:GetResources",
        "sqs:ReceiveMessage",
        "sqs:ListQueues",
        "sqs:GetQueueAttributes",
       ...
        "cloudwatch:List*",
        "cloudwatch:Get*",
        "cloudwatch:Describe*",
        "autoscaling:Describe*"
      ],
      "Resource": "*"
    }
  ]
}

Steps to Reproduce

  1. terraform refresh
@nywilken nywilken added enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service. labels Feb 5, 2019
@2rs2ts
Copy link
Contributor

2rs2ts commented Jan 7, 2020

Possibly related, we're seeing our list of actions that isn't sorted in any particular manner in our configuration being sorted, but alphabetically (the opposite ordering of your example)

@nitrocode
Copy link
Contributor

Similar to this issue hashicorp/terraform#22931

I'm seeing this issue too with aws_iam_policy_document with aws_kms_key. The data source iam policy seems to preserve the reverse order but the kms key resource seems to impose a random order within the policy.

@handlerbot
Copy link
Contributor

My read is close this in favor of #11801?

@elkh510
Copy link

elkh510 commented Nov 16, 2021

hi
any updates here?

@YakDriver
Copy link
Member

@handlerbot I do not think this should be closed in favor of #11801 since that has the broader idea of order verses specifically the anti-alphabetical here.

ALL: I would love to hear thoughts on whether switching the order would be a breaking change in any situations?

@jorhett
Copy link

jorhett commented Dec 8, 2023

Of note, the data source retains the original order -- it's being reversed in the json output only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
Development

No branches or pull requests

8 participants