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

[Bug]: Error: only alphanumeric characters and hyphens allowed in "name" #38165

Closed
EugenKon opened this issue Jun 27, 2024 · 9 comments · Fixed by #38194
Closed

[Bug]: Error: only alphanumeric characters and hyphens allowed in "name" #38165

EugenKon opened this issue Jun 27, 2024 · 9 comments · Fixed by #38194
Labels
bug Addresses a defect in current functionality. service/rds Issues and PRs that pertain to the rds service.
Milestone

Comments

@EugenKon
Copy link

EugenKon commented Jun 27, 2024

Terraform Core Version

I do not remember already

AWS Provider Version

probably this happened on v4.67

Affected Resource(s)

  • aws_db_event_subscription

Expected Behavior

No error should be reported, because the name has only alphanumeric characters.

Actual Behavior

Error: only alphanumeric characters and hyphens allowed in "name"

Relevant Error/Panic Output Snippet

terraform plan
╷
│ Error: only alphanumeric characters and hyphens allowed in "name"
│
│   with aws_db_event_subscription.db_event_subs,
│   on rds.tf line 81, in resource "aws_db_event_subscription" "db_event_subs":
│   81:   name      = "db_event_subs"

Terraform Configuration Files

resource "aws_db_event_subscription" "db_event_subs" {
  name      = "db_event_subs"  << line 81
  sns_topic = aws_sns_topic.rds-events.arn

  source_type = "db-instance"
  source_ids  = [aws_db_instance.postgres_v15.identifier]

  event_categories = [
    "backup",
    "maintenance",
    "low storage",
    "failure",
  ]
}

Steps to Reproduce

terraform plan

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@EugenKon EugenKon added the bug Addresses a defect in current functionality. label Jun 27, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/rds Issues and PRs that pertain to the rds service. label Jun 27, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jun 27, 2024
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jun 27, 2024
@acwwat
Copy link
Contributor

acwwat commented Jun 28, 2024

@EugenKon By definition, alphanumeric would only include 0-9, a-z, and A-Z. Along with -, the validation regex is ^[0-9A-Za-z-]+$. Since the name db_event_subs in your example includes underscores (_), it does not match the regex.

@EugenKon
Copy link
Author

EugenKon commented Jun 28, 2024

@acwwat AFAIK all languages defines alphanumeric as \w and it is [a-zA-Z0-9_]. If you define something else then it should be spelled explicitly:
The name should contain characters from the next regex ^[0-9A-Za-z-]+$`

By the way, why I can use _ character in the name for security groups? This is very inconsistent!

resource "aws_security_group" "allow_all_internal" {
  name   = "${var.project_name}-allow-all_internal"
  vpc_id = aws_vpc.main.id
  ...

To my mind this is a bug that _ is not allowed for the name option of aws_db_event_subscription resource.

@acwwat
Copy link
Contributor

acwwat commented Jun 28, 2024

@EugenKon There certainly seems to be some inconsistencies within AWS, although the provider is technically somewhat adhering to the requirements.

What I can see is that the Console is the only place where it provides the specifications for the event subscription name. As you can see in the screenshot, the spec is "alphanumeric" + hyphens with max 255 characters, although the error message spells it out more explicitly:

Must contain only letters, digits, or hyphens. Must start with a letter.

More notable is that the provider validation does not enforce the "must start with a letter" requirement.

image

The API reference does not even mention the regex.

For consistency, I can update the validation and the error message in the provider to match the UI which I consider to be the current source of truth (best we got today anyway). However the general issue of inconsistency and API reference accuracy are more of upstream AWS issues to be addressed.

@EugenKon
Copy link
Author

Hm... Probably AWS_Provider documentation for this resource should be updated to mention this limitation. Probably it would worth to mention this limitation and provide a link to AWS documentation which will describe this. Thus on Terraform Doc site we do not need to change anything, because it will just refer to AWS.

Must contain only letters, digits, or hyphens. Must start with a letter.

Yeah, AWS error message is more informative than from Terraform.

@acwwat
Copy link
Contributor

acwwat commented Jun 29, 2024

Welp, there are apparently even more validation when I checked the error returned by the AWS API:

Error: creating RDS Event Subscription (db-event-subs--20240629040402468400000001): operation error RDS: CreateEventSubscription, https response error StatusCode: 400, RequestID: c3b55887-216e-4fdb-96c9-a47ec6b597fd, api error InvalidParameterValue: The parameter Subscription Identifier is not a valid identifier. Identifiers must begin with a letter; must contain only ASCII letters, digits, and hyphens; and must not end with a hyphen or contain two consecutive hyphens.

I feel that it's a fool's errand to update the validation code in the provider as I am sure there are many, many other cases in other AWS services, but nonetheless I'll try to fix just this one.

Copy link

Warning

This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.63.0 milestone Aug 15, 2024
Copy link

This functionality has been released in v5.63.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!

Copy link

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 Sep 15, 2024
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/rds Issues and PRs that pertain to the rds service.
Projects
None yet
3 participants