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

Allow aws_iam_policy_document to merge on a per statement level #11942

Closed
shadycuz opened this issue Feb 6, 2020 · 3 comments
Closed

Allow aws_iam_policy_document to merge on a per statement level #11942

shadycuz opened this issue Feb 6, 2020 · 3 comments
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@shadycuz
Copy link
Contributor

shadycuz commented Feb 6, 2020

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

Description

aws_iam_policy_document allows you to combine policies with the source_json attribute and to replace statements with the overide_json attribute. One feature that could really open up the possibilities is the ability to merge together two statements with the same sid. This would allow you to create a "template" aws_iam_policy_document and then re-use that over and over again to create your IAM policies. A simple example is included below.

New or Affected Resource(s)

  • aws_iam_policy_document

Potential Terraform Configuration

data "aws_iam_policy_document" "cloudwatch_logs" {
  statement {
    sid = "CloudWatch"

    actions = [
      "logs:CreateLogStream",
      "logs:PutLogEvents"
    ]
  }
}

data "aws_iam_policy_document" "s3_rw" {
  statement {
    sid = "S3"

    actions = [
      "s3:*Object",
      "s3:ListBucket"
    ]
  }
}

data "aws_iam_policy_document" "create_identity" {

  merge_json = [
                 data.aws_iam_policy_document.cloudwatch_logs.json,
                 data.aws_iam_policy_document.s3_rw.json
                ]

  statement {
    sid = "CloudWatch"

    resources = [aws_cloudwatch_log_group.create_identity.arn]
  }

  statement {
    sid = "S3"

    resources = [aws_s3_bucket.identity_backup.arn]
  }

  statement {
    sid = "Cognito"

    actions = [
      "cognito-idp:SignUp"
    ]

    resources = ["*"]
  }
}

The resulting json would have a CloudWatch statement that was the combination of CloudWatch statements from the aws_iam_policy_document.cloudwatch_logs and aws_iam_policy_document.create_identity. This would allow you to reuse aws_iam_policy_document.cloudwatch_logs for any resource that needed access to create Cloudwatch logs.

This is just a simple example, a more complex example would make better use of this new functionality.

References

@shadycuz shadycuz added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 6, 2020
@ghost ghost added the service/iam Issues and PRs that pertain to the iam service. label Feb 6, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 6, 2020
@YakDriver YakDriver added this to the v3.28.0 milestone Feb 10, 2021
@YakDriver YakDriver removed the needs-triage Waiting for first response or review from a maintainer. label Feb 10, 2021
@YakDriver YakDriver self-assigned this Feb 10, 2021
@YakDriver
Copy link
Member

YakDriver commented Feb 10, 2021

We have merged #12055 in to the Terraform AWS Provider. With this, aws_iam_policy_document provides the ability to merge multiple source and override policy documents. This is available now on the main branch and when version 3.28.0 is released (likely Feb. 11, 2021). If you have problems with the functionality or need further enhancements, please open a new issue. Thanks for your interest in the AWS Provider! 🎉

@ghost
Copy link

ghost commented Feb 12, 2021

This has been released in version 3.28.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 for triage. Thanks!

@ghost
Copy link

ghost commented Mar 13, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

2 participants