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.source_policy_documents that contain multiple conditions are dropped on output #26485

Closed
mikeknoll opened this issue Aug 25, 2022 · 2 comments · Fixed by #26657
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@mikeknoll
Copy link

I am using aws_iam_policy_document to combine multiple JSON policy documents into a single aws_organizations_policy. Everything worked until I introduced a policy with a StringNotLike and Null condition. The Null condition is being dropped.

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

Terraform v1.2.7
on windows_amd64
provider registry.terraform.io/hashicorp/aws v4.27.0

Affected Resource(s)

  • aws_iam_policy_document

Terraform Configuration Files

provider "aws" {
  region = "eu-west-1"
}

data "aws_iam_policy_document" "doc" {
    source_policy_documents = [file("${path.module}/scp.json")]
}

output "json" {
  value = data.aws_iam_policy_document.doc.json
}

scp.json:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "RestrictAccessToSpecialTag",
      "Effect": "Deny",
      "Action": [
        "ec2:CreateTags",
        "ec2:DeleteTags"
      ],
      "Resource": "arn:aws:ec2:*:*:vpc/*",
      "Condition": {
        "StringNotLike": {
          "aws:ResourceAccount": [
            "123456"
          ],
          "aws:PrincipalArn": "arn:aws:iam::*:role/AWSAFTExecution"
        },
        "Null": {
          "aws:ResourceTag/SpecialTag": false
        }
      }
    }
  ]
}

Plan Output

        {
          + Statement = [       
              + {
                  + Action    = [
                      + "ec2:CreateTags",
                      + "ec2:DeleteTags",
                    ]
                  + Condition = {
                      + StringNotLike = {
                          + "aws:PrincipalArn"    = [
                              + "arn:aws:iam::*:role/AWSAFTExecution",
                            ]
                          + "aws:ResourceAccount" = [
                              + "123456",
                            ]
                        }
                    }

                  + Effect    = "Deny"
                  + Resource  = "arn:aws:ec2:*:*:vpc/*"
                  + Sid       = "RestrictAccessToSpecialTag"
                },
            ]

          + Version   = "2012-10-17"
        }
    )

Expected Behavior

Both the StringNotLike condition and the Null condition present in the output.

Actual Behavior

Only the StringNotLike condition present in the output, the Null condition is dropped.

Steps to Reproduce

  1. terraform plan
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/iam Issues and PRs that pertain to the iam service. labels Aug 25, 2022
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Aug 30, 2022
@github-actions github-actions bot added this to the v4.30.0 milestone Sep 6, 2022
@github-actions
Copy link

github-actions bot commented Sep 9, 2022

This functionality has been released in v4.30.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants