hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.8k stars 9.15k forks source link

[Enhancement]: aws_wafv2_rule_group accept json similar to aws_iam_policy #27519

Open jreagan00 opened 1 year ago

jreagan00 commented 1 year ago

Description

Please add the capability to use a JSON file as a source for a WAF Rule similar to how i can with the IAM Policy

My aws_iam_policy code example:

variable "iam_pol_name" {type=string}
variable "json_pol_file" {type=string}

data "local_file" "json_pol_file" {filename = "${path.module}/${var.json_pol_file}"}

resource "aws_iam_policy" "policy" {
    name        = var.iam_pol_name
    policy = data.local_file.json_pol_file.content
}

Something similar to:

variable "rule_grp_name" {type=string}
variable "rule_grp_desc" {type=string}
variable "json_rule_file" {type=string}

data "local_file" "json_rule_file" {filename = "${path.module}/${var.json_rule_file}"}

resource "aws_wafv2_rule_group" "rule_grp" {
  name        = var.rule_grp_name
  description = var.rule_grp_desc
  scope       = "REGIONAL"
  capacity    = 500  

  rule = data.local_file.json_rule_file.content

}

Even using the jsonencode block would work:

policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "ec2:Describe*",
        ]
        Effect   = "Allow"
        Resource = "*"
      },
    ]
  })

Affected Resource(s) and/or Data Source(s)

aws_wafv2_web_acl aws_wafv2_rule_group

Potential Terraform Configuration

variable "rule_grp_name" {type=string}
variable "rule_grp_desc" {type=string}
variable "json_rule_file" {type=string}

data "local_file" "json_rule_file" {filename = "${path.module}/${var.json_rule_file}"}

resource "aws_wafv2_rule_group" "rule_grp" {
  name        = var.rule_grp_name
  description = var.rule_grp_desc
  scope       = "REGIONAL"
  capacity    = 500  

  rule = data.local_file.json_rule_file.content

}

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 day ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!