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

Improve managed and common rule aliases Error messaging #29

Closed
aidanmelen opened this issue Oct 11, 2022 · 2 comments
Closed

Improve managed and common rule aliases Error messaging #29

aidanmelen opened this issue Oct 11, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@aidanmelen
Copy link
Owner

aidanmelen commented Oct 11, 2022

Is your feature request related to a problem? Please describe.

The following example:

#tfsec:ignore:aws-ec2-no-public-egress-sgr
module "security_group" {
  source  = "aidanmelen/security-group-v2/aws"
  version = "2.0.0"

  name        = local.name
  description = "Allow TLS inbound traffic"
  vpc_id      = data.aws_vpc.default.id

  # recommended
  unpack = true

  ingress = [
    {
      rule             = "this-is-not-a-rule"
      cidr_blocks      = [data.aws_vpc.default.cidr_block]
      ipv6_cidr_blocks = [data.aws_vpc.default.ipv6_cidr_block]
    }
  ]

  egress = [
    { rule = "all-all-to-public" }
  ]
}

with produce these Terraform Errors:

╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["172.31.0.0/16"],
│   on ../../main.tf line 89, in resource "aws_security_group_rule" "ingress":
│   89:   from_port                = try(each.value.from_port, null)
│ 
│ The argument "from_port" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["2600:1f13:b21:6500::/56"],
│   on ../../main.tf line 89, in resource "aws_security_group_rule" "ingress":
│   89:   from_port                = try(each.value.from_port, null)
│ 
│ The argument "from_port" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["172.31.0.0/16"],
│   on ../../main.tf line 90, in resource "aws_security_group_rule" "ingress":
│   90:   to_port                  = try(each.value.to_port, null)
│ 
│ The argument "to_port" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["2600:1f13:b21:6500::/56"],
│   on ../../main.tf line 90, in resource "aws_security_group_rule" "ingress":
│   90:   to_port                  = try(each.value.to_port, null)
│ 
│ The argument "to_port" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["172.31.0.0/16"],
│   on ../../main.tf line 91, in resource "aws_security_group_rule" "ingress":
│   91:   protocol                 = try(each.value.protocol, null)
│ 
│ The argument "protocol" is required, but no definition was found.
╵
╷
│ Error: Missing required argument
│ 
│   with module.security_group.aws_security_group_rule.ingress["2600:1f13:b21:6500::/56"],
│   on ../../main.tf line 91, in resource "aws_security_group_rule" "ingress":
│   91:   protocol                 = try(each.value.protocol, null)
│ 
│ The argument "protocol" is required, but no definition was found.
╵

Describe the solution you'd like

It would be great to tell the user the specific rule alias(s) lookup(s) that failed.

@aidanmelen aidanmelen added the enhancement New feature or request label Oct 11, 2022
@aidanmelen aidanmelen changed the title Validate Managed and common rule aliases Improve managed and common rule aliases Error messaging Oct 11, 2022
@aidanmelen
Copy link
Owner Author

Fix coming in v2.0.1. Improved output:

╷
│ Error: Incorrect attribute value type
│ 
│   on ../../main.tf line 89, in resource "aws_security_group_rule" "ingress":
│   89:   from_port                = try(each.value.from_port, null)
│     ├────────────────
│     │ each.value.from_port is "The rule alias is invalid: this-is-not-a-rule. https://github.com/aidanmelen/terraform-aws-security-group-v2#rule-aliases"
│ 
│ Inappropriate value for attribute "from_port": a number is required.
╵
╷
│ Error: Incorrect attribute value type
│ 
│   on ../../main.tf line 89, in resource "aws_security_group_rule" "ingress":
│   89:   from_port                = try(each.value.from_port, null)
│     ├────────────────
│     │ each.value.from_port is "The rule alias is invalid: this-is-not-a-rule. https://github.com/aidanmelen/terraform-aws-security-group-v2#rule-aliases"
│ 
│ Inappropriate value for attribute "from_port": a number is required.

@aidanmelen
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant