diff --git a/.github/workflows/tests_terraform_examples.yml b/.github/workflows/tests_terraform_examples.yml index 12790048e..be5fb23bb 100644 --- a/.github/workflows/tests_terraform_examples.yml +++ b/.github/workflows/tests_terraform_examples.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - service: ["acm", "route53"] + service: ["acm", "cloudfront", "route53"] steps: - uses: actions/checkout@v4 diff --git a/moto/cloudfront/exceptions.py b/moto/cloudfront/exceptions.py index b8e7f634d..6e9104eba 100644 --- a/moto/cloudfront/exceptions.py +++ b/moto/cloudfront/exceptions.py @@ -33,14 +33,6 @@ class OriginDoesNotExist(CloudFrontException): ) -class InvalidOriginServer(CloudFrontException): - def __init__(self) -> None: - super().__init__( - "InvalidOrigin", - message="The specified origin server does not exist or is not valid.", - ) - - class DomainNameNotAnS3Bucket(CloudFrontException): def __init__(self) -> None: super().__init__( diff --git a/moto/cloudfront/models.py b/moto/cloudfront/models.py index 4fc6fcdcd..45f5b9da0 100644 --- a/moto/cloudfront/models.py +++ b/moto/cloudfront/models.py @@ -12,7 +12,6 @@ from .exceptions import ( DistributionAlreadyExists, DomainNameNotAnS3Bucket, InvalidIfMatchVersion, - InvalidOriginServer, NoSuchDistribution, NoSuchOriginAccessControl, OriginDoesNotExist, @@ -121,9 +120,6 @@ class Origin: self.connection_attempts = origin.get("ConnectionAttempts") or 3 self.connection_timeout = origin.get("ConnectionTimeout") or 10 - if "S3OriginConfig" not in origin and "CustomOriginConfig" not in origin: - raise InvalidOriginServer - if "S3OriginConfig" in origin: # Very rough validation if not self.domain_name.endswith("amazonaws.com"): diff --git a/other_langs/terraform/cloudfront/cloudfront.tf b/other_langs/terraform/cloudfront/cloudfront.tf new file mode 100644 index 000000000..8409f4216 --- /dev/null +++ b/other_langs/terraform/cloudfront/cloudfront.tf @@ -0,0 +1,19 @@ +resource "aws_s3_bucket" "bucket" { + bucket = "test-bucket" +} + +module "cloudfront" { + source = "terraform-aws-modules/cloudfront/aws" + version = "3.2.1" + + default_cache_behavior = { + target_origin_id = "s3-bucket" + viewer_protocol_policy = "allow-all" + } + + origin = { + s3-bucket = { + domain_name = aws_s3_bucket.bucket.bucket_domain_name + } + } +} \ No newline at end of file diff --git a/other_langs/terraform/cloudfront/providers.tf b/other_langs/terraform/cloudfront/providers.tf new file mode 100644 index 000000000..4c760b605 --- /dev/null +++ b/other_langs/terraform/cloudfront/providers.tf @@ -0,0 +1,24 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + # version = "5.18.1" # with this line uncommented, the destroy works + } + } +} + +provider "aws" { + region = "us-east-1" + s3_use_path_style = true + skip_credentials_validation = true + skip_metadata_api_check = true + skip_requesting_account_id = true + + endpoints { + s3 = "http://localhost:5000" + cloudfront = "http://localhost:5000" + } + + access_key = "my-access-key" + secret_key = "my-secret-key" +} \ No newline at end of file diff --git a/tests/test_cloudfront/test_cloudfront_distributions.py b/tests/test_cloudfront/test_cloudfront_distributions.py index 1ad6d5b7a..d4680976b 100644 --- a/tests/test_cloudfront/test_cloudfront_distributions.py +++ b/tests/test_cloudfront/test_cloudfront_distributions.py @@ -368,36 +368,6 @@ def test_get_distribution_config_with_mismatched_originid(): ) -@mock_aws -def test_create_origin_without_origin_config(): - client = boto3.client("cloudfront", region_name="us-west-1") - - with pytest.raises(ClientError) as exc: - client.create_distribution( - DistributionConfig={ - "CallerReference": "ref", - "Origins": { - "Quantity": 1, - "Items": [{"Id": "origin1", "DomainName": "https://getmoto.org"}], - }, - "DefaultCacheBehavior": { - "TargetOriginId": "origin1", - "ViewerProtocolPolicy": "allow-all", - }, - "Comment": "an optional comment that's not actually optional", - "Enabled": False, - } - ) - - metadata = exc.value.response["ResponseMetadata"] - assert metadata["HTTPStatusCode"] == 400 - err = exc.value.response["Error"] - assert err["Code"] == "InvalidOrigin" - assert ( - err["Message"] == "The specified origin server does not exist or is not valid." - ) - - @mock_aws def test_create_distribution_with_invalid_s3_bucket(): client = boto3.client("cloudfront", region_name="us-west-1")