Firstly, you should post code in code blocks like I have below so it it legible
According to AWS, there are three situations this can happen.
When you are creating a bucket with a name that this already being used as a bucket name in your AWS account or in any other AWS account (Please note that S3 bucket names are globally unique).
When you are doing an operation on your S3 bucket and you have set the Region variable (either when configuring the SDK or while using environment variables etc) to a region other than the one in which the bucket is actually present.
You have recently deleted a S3 bucket in a particular region (say us-east-1) and you are trying to create a bucket (with the same name as the the bucket that was deleted) in another region right after deleting the bucket.
My guess is that you hit #1, due to
variable "bucket_name" {
description = "The name of the S3 bucket"
type = string
default = "tfstate-s3-bucket"
}
and that some other AWS account has a bucket called tfstate-s3-bucket in the eu-central-1 region.
One way to pretty much ensure that your bucket name is unique is to suffix it with your AWS account number.
I see also that you want to enable versioning. While this can be a good thing, it can make buckets very hard to delete as they won’t delete unless all the versions are also deleted. It is a good option to add lifecycle rules to ensure old versions of files don’t hang around for too long.
I was able to create TF state bucket and created another bucket to store TF state bucket. Tried to create and delete at the same time to test S3 native lock testing. Works like a charm.