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.77k stars 9.12k forks source link

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

Closed EugenKon closed 1 month ago

EugenKon commented 3 months ago

Terraform Core Version

I do not remember already

AWS Provider Version

probably this happened on v4.67

Affected Resource(s)

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

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

acwwat commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

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.

github-actions[bot] commented 1 month ago

[!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[bot] commented 1 month ago

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!

github-actions[bot] commented 3 weeks ago

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.