-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
aws_sns_topic: Name validation fails if the topic name has hyphen #19416
Comments
I'm getting the same error, but with or without the hyphens. Same for underscores. In other words, nothing is working for me: │ Error: invalid topic name: topicwithouthyphens
│
│ on sns.tf line 28, in resource "aws_sns_topic" "sns":
│ 28: resource "aws_sns_topic" "sns" {
-- edit -- never mind 😢 it was my config (I was inadvertently forcing FIFO ) |
this is also an issue for fifo topics and data aws_sns_topic- it doesn't like the period in it that is in the required ".fifo"
|
@timoguin Thanks for raising this! However, I'm unable to duplicate the problem. Test config: resource "aws_sns_topic" "test" {
name = "topic-with-hyphens"
}
data "aws_sns_topic" "test" {
name = aws_sns_topic.test.name
}
resource "aws_sns_topic" "test-fifo" {
name = "topic-name.fifo"
fifo_topic = true
}
data "aws_sns_topic" "test-fifo" {
name = aws_sns_topic.test-fifo.name
} The results: % terraform -version
Terraform v0.15.4
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.42.0
% terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
+ create
<= read (data resources)
Terraform will perform the following actions:
# data.aws_sns_topic.test will be read during apply
# (config refers to values not yet known)
<= data "aws_sns_topic" "test" {
+ arn = (known after apply)
+ id = (known after apply)
+ name = "topic-with-hyphens"
}
# data.aws_sns_topic.test-fifo will be read during apply
# (config refers to values not yet known)
<= data "aws_sns_topic" "test-fifo" {
+ arn = (known after apply)
+ id = (known after apply)
+ name = "topic-name.fifo"
}
# aws_sns_topic.test will be created
+ resource "aws_sns_topic" "test" {
+ arn = (known after apply)
+ content_based_deduplication = false
+ fifo_topic = false
+ id = (known after apply)
+ name = "topic-with-hyphens"
+ name_prefix = (known after apply)
+ policy = (known after apply)
+ tags_all = (known after apply)
}
# aws_sns_topic.test-fifo will be created
+ resource "aws_sns_topic" "test-fifo" {
+ arn = (known after apply)
+ content_based_deduplication = false
+ fifo_topic = true
+ id = (known after apply)
+ name = "topic-name.fifo"
+ name_prefix = (known after apply)
+ policy = (known after apply)
+ tags_all = (known after apply)
}
Plan: 2 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
aws_sns_topic.test-fifo: Creating...
aws_sns_topic.test: Creating...
aws_sns_topic.test: Creation complete after 2s [id=arn:aws:sns:us-west-2:067819342479:topic-with-hyphens]
data.aws_sns_topic.test: Reading...
aws_sns_topic.test-fifo: Creation complete after 2s [id=arn:aws:sns:us-west-2:067819342479:topic-name.fifo]
data.aws_sns_topic.test-fifo: Reading...
data.aws_sns_topic.test: Read complete after 0s [id=arn:aws:sns:us-west-2:067819342479:topic-with-hyphens]
data.aws_sns_topic.test-fifo: Read complete after 0s [id=arn:aws:sns:us-west-2:067819342479:topic-name.fifo]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed. |
I think the difference is in the code you provided, terraform is creating the FIFO SNS resource. In my case I’m trying to grab the ARN of an existing one not managed by TF to setup a subscription to it. |
Is this old guy still an issue anymore? 😊 |
I faced the same issue, while create sns-topic If you are using |
Community Note
Terraform CLI and Terraform AWS Provider Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
None
Panic Output
None
Expected Behavior
The topic should be created.
Actual Behavior
The name of the topic fails validation during plan.
Steps to Reproduce
terraform plan
Important Factoids
None
References
#15828 added support for Fifo topics (issue #15805), as well as some additional logic for the name validation. It looks like that's the source of the error, so this bug affects v3.37.0+.
Here is the offending code: https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_sns_topic.go#L586-L594
I think the hyphen in each character class needs to be escaped to fix this.
The text was updated successfully, but these errors were encountered: