I'm not able to use a previous created S3 Bucket (it's not a website S3 Bucket!) for one of my CloudFront Distribution Origins:
Error: error creating CloudFront Distribution: InvalidArgument: The parameter Origin DomainName does not refer to a valid S3 bucket.
status code: 400, request id: xxxx
on modules/cloudfront/main.tf line 20, in resource "aws_cloudfront_distribution" "app":
20: resource "aws_cloudfront_distribution" "app" {
Notice: I successfully created a CloudFront Distribution with an Origin using the same S3 Bucket through the Web console to verify the S3 Bucket.
resource "aws_s3_bucket" "static" {
bucket = "static.any-domain.tld"
acl = "public-read"
}
resource "aws_cloudfront_distribution" "app" {
enabled = true
is_ipv6_enabled = true
comment = "k8s test"
# without this origin, cloudfront distribution is successfully created
origin {
# tried different dns domain names:
# static.any-domain.tld.s3.eu-west-1.amazonaws.com
# or static.any-domain.tld.s3-eu-west-1.amazonaws.com
# or static.any-domain.tld.s3.amazonaws.com
domain_name = aws_s3_bucket.static.bucket_regional_domain_name
origin_id = "S3-${aws_s3_bucket.static.bucket}/any/path"
origin_path = "/any/path"
# tried with and without the following:
s3_origin_config {
origin_access_identity = "origin-access-identity/cloudfront/${aws_cloudfront_distribution.app.id}"
}
}
origin {
domain_name = "any-valid-stuff.eu-west-1.elb.amazonaws.com"
origin_id = "ELB-any-valid-stuff"
custom_origin_config {
origin_read_timeout = 30
origin_keepalive_timeout = 30
http_port = 80
https_port = 443
origin_protocol_policy = "http-only"
origin_ssl_protocols = ["TLSv1"]
}
}
...
}