Skip to content

Cloudfront multi-tenant distribution: schema-level defaults on origins Set-element sub-attributes causes flip-flopping plans #47735

@dsp0x4

Description

@dsp0x4

Terraform and AWS Provider Version

Terraform v1.15.1
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v6.43.0

Affected Resource(s) or Data Source(s)

  • aws_cloudfront_multitenant_distribution

Expected Behavior

The user explicitly set values for one of these origin attributes:

  • connection_attempts
  • connection_timeout
  • custom_origin_config.origin_keepalive_timeout
  • custom_origin_config.origin_read_timeout

and the provider preserves that value across applies, without generating a diff on each plan.

Actual Behavior

The user explicitly set values for one of these origin attributes:

  • connection_attempts
  • connection_timeout
  • custom_origin_config.origin_keepalive_timeout
  • custom_origin_config.origin_read_timeout

and running a plan after each apply shows a "flip-flopping" configuration between the schema-level default value and the user-set value.

Relevant Error/Panic Output

n/a

Sample Terraform Configuration

Click to expand configuration
provider "aws" {
  region = "us-east-1"
}

data "aws_cloudfront_cache_policy" "caching_optimized" {
  name = "Managed-CachingOptimized"
}

resource "aws_cloudfront_multitenant_distribution" "example" {
  comment = "example multi-tenant distribution"
  enabled = false

  origin {
    domain_name = "example.com"
    id          = "example-origin"

    custom_origin_config {
      http_port              = 80
      https_port             = 443
      origin_protocol_policy = "https-only"
      origin_ssl_protocols   = ["TLSv1.2"]
      origin_read_timeout    = 120   # any non-default value (30)
    }
  }

  default_cache_behavior {
    target_origin_id       = "example-origin"
    viewer_protocol_policy = "redirect-to-https"
    cache_policy_id        = data.aws_cloudfront_cache_policy.caching_optimized.id

    allowed_methods {
      items          = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
      cached_methods = ["GET", "HEAD"]
    }
  }

  restrictions {
    geo_restriction {
      restriction_type = "none"
    }
  }

  tenant_config {}

  viewer_certificate {
    cloudfront_default_certificate = true
  }

  tags = {
    Name = "example"
  }
}

Steps to Reproduce

  1. Apply the configuration with any non-default value for one of the origin attributes that has schema-level defaults
  2. Run a new plan/apply
  3. Observe the perpetual plan diff after every apply

Debug Logging

n/a

GenAI / LLM Assisted Development

n/a

Important Facts and References

This is likely related to:

and the bug was introduced for this resource when origin blocks were (rightfully) converted from List to Set.

Would you like to implement a fix?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/cloudfrontIssues and PRs that pertain to the cloudfront service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions