Answers: <p>I'm resolved my question like bellow:</p>
  <ul>
  <li>I discovered that some arguments that I used before not was used when you use the <strong>s3_origin</strong> and them are used with <strong>custom_orogin</strong></li>
  </ul>
  <p>Was necessary used too variables <code>type=list(object({foo=bar})</code> for my dynamic blocks lists.</p>
  <p>Part of my module bellow:</p>
  <p><strong>main.tf</strong></p>
  <pre><code> dynamic &quot;origin&quot; {
      for_each = var.origin
      content {
  
        domain_name = origin.value.domain_name
        origin_id   = origin.value.origin_id
  
        s3_origin_config {
          origin_access_identity = origin.value.origin_access_identity
        }
      }
    }
  </code></pre>
  <p><strong>vars.tf</strong></p>
  <pre><code>variable &quot;origin&quot; {
    type        = list(object({ domain_name = any, origin_id = string, origin_access_identity = string }))
    description = &quot;One or more origins for this distribution (multiples allowed).&quot;
  }
  </code></pre>
  <p>Another thing that I learned it's when you set a <code>default=value</code> onto variable <code>type</code> same this <em>var</em> is (optional) you turn them (required).</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-05T20:37:41.333Z
Answers: 2020-11-05T20:37:41.333Z
Answers: Vader
Body: <p>I'm creating a AWS Cloudfront module and some troubles are happening because have some Cloudfront parameters that are &quot;dynamics/optional&quot; too.</p>
  <p>When I'm trying run the <code>$ terraform validate</code> show me the error:</p>
  <pre><code>on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 24, in resource &quot;aws_cloudfront_distribution&quot; &quot;cdn&quot;:
    24:   dynamic &quot;custom_origin_config&quot; {
  
  Blocks of type &quot;custom_origin_config&quot; are not expected here.
  </code></pre>
  <p>Following my <strong>module</strong> <code>main.tf</code>:</p>
  <pre><code>resource &quot;aws_cloudfront_distribution&quot; &quot;cdn&quot; {
  
    enabled               = var.enabled
    comment               = var.comment
    default_root_object   = var.default_root_object
    aliases               = var.aliases
    is_ipv6_enabled       = var.is_ipv6_enabled
    http_version          = var.http_version
    price_class           = var.price_class
    web_acl_id            = var.web_acl_id
    retain_on_delete      = var.retain_on_delete
    wait_for_deployment   = var.wait_for_deployment
  
    dynamic &quot;origin&quot; {
      for_each  = var.origin
      content {
  
        domain_name   = origin.value.domain_name
        origin_id     = origin.value.origin_id
        origin_path   = origin.value.origin_path
      }
    }
  
    dynamic &quot;custom_origin_config&quot; {
      for_each  = var.custom_origin_config
      content {
        
        http_port                 = custom_origin_config.value.http_port
        https_port                = custom_origin_config.value.https_port
        origin_protocol_policy    = custom_origin_config.value.origin_protocol_policy
        origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
        origin_keepalive_timeout  = custom_origin_config.value.origin_keepalive_timeout
        origin_read_timeout       = custom_origin_config.value.origin_read_timeout
  
      }
    }
  </code></pre>
  <p>My <code>vars.tf</code> :</p>
  <pre><code>variable &quot;origin&quot;   {
      type        = any
      default     = []
      description = &quot;One or more origins for this distribution (multiples allowed).&quot;
  }
  
  variable &quot;custom_origin_config&quot; {
      type        = any
      default     = []
      description = &quot;The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead.&quot;
  }
  </code></pre>
  <p><strong>EDIT 1</strong></p>
  <p>A made a little changes <code>main.tf</code></p>
  <pre><code> dynamic &quot;origin&quot; {
      for_each  = var.origin
      content {
  
        domain_name   = origin.value.domain_name
        origin_id     = origin.value.origin_id
        origin_path   = origin.value.origin_path
  
        dynamic &quot;custom_origin_config&quot; {
          for_each  = var.custom_origin_config
          content {
        
          http_port                 = custom_origin_config.value.http_port
          https_port                = custom_origin_config.value.https_port
          origin_protocol_policy    = custom_origin_config.value.origin_protocol_policy
          origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
          origin_keepalive_timeout  = custom_origin_config.value.origin_keepalive_timeout
          origin_read_timeout       = custom_origin_config.value.origin_read_timeout
  
          }
        }
      }
    }
  </code></pre>
  <p>and onto <code>vars.tf</code>:</p>
  <pre><code>variable &quot;origin&quot;   {
      type        = any
  #    default     = []
      description = &quot;One or more origins for this distribution (multiples allowed).&quot;
  }
  
  variable &quot;custom_origin_config&quot; {
      type        = list
  #    default     = []
      description = &quot;The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead.&quot;
  }
  </code></pre>
  <p><strong>And now the output error change:</strong></p>
  <pre><code>Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 29, in resource &quot;aws_cloudfront_distribution&quot; &quot;cdn&quot;:
    29:         origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
  
  Inappropriate value for attribute &quot;origin_ssl_protocols&quot;: set of string
  required.
  
  
  Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 43, in resource &quot;aws_cloudfront_distribution&quot; &quot;cdn&quot;:
    43:         locations          = geo_restriction.value.location
  
  Inappropriate value for attribute &quot;locations&quot;: set of string required.
  
  
  Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 55, in resource &quot;aws_cloudfront_distribution&quot; &quot;cdn&quot;:
    55:       cloudfront_default_certificate  = viewer_certificate.value.cloudfront_default_certificate
  
  Inappropriate value for attribute &quot;cloudfront_default_certificate&quot;: a bool is
  required.
  </code></pre>
  <p><strong>Someone has been through this problem, managed to solve it?</strong></p>
  
Tags: <amazon-web-services><terraform><terraform-module>
Title: Terraform Dynamic Block with list intro them
UserDisplayName: Vader
ThreadText: # Terraform Dynamic Block with list intro them
  
  (Asked by: username_0 on 2020-10-30)
  
  I'm creating a AWS Cloudfront module and some troubles are happening because have some Cloudfront parameters that are "dynamics/optional" too.
  
  When I'm trying run the `$ terraform validate` show me the error:
  
  ```
  on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 24, in resource "aws_cloudfront_distribution" "cdn":
    24:   dynamic "custom_origin_config" {
  
  Blocks of type "custom_origin_config" are not expected here.
  
  ```
  
  Following my **module** `main.tf`:
  
  ```
  resource "aws_cloudfront_distribution" "cdn" {
  
    enabled               = var.enabled
    comment               = var.comment
    default_root_object   = var.default_root_object
    aliases               = var.aliases
    is_ipv6_enabled       = var.is_ipv6_enabled
    http_version          = var.http_version
    price_class           = var.price_class
    web_acl_id            = var.web_acl_id
    retain_on_delete      = var.retain_on_delete
    wait_for_deployment   = var.wait_for_deployment
  
    dynamic "origin" {
      for_each  = var.origin
      content {
  
        domain_name   = origin.value.domain_name
        origin_id     = origin.value.origin_id
        origin_path   = origin.value.origin_path
      }
    }
  
    dynamic "custom_origin_config" {
      for_each  = var.custom_origin_config
      content {
        
        http_port                 = custom_origin_config.value.http_port
        https_port                = custom_origin_config.value.https_port
        origin_protocol_policy    = custom_origin_config.value.origin_protocol_policy
        origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
        origin_keepalive_timeout  = custom_origin_config.value.origin_keepalive_timeout
        origin_read_timeout       = custom_origin_config.value.origin_read_timeout
  
      }
    }
  
  ```
  
  My `vars.tf` :
  
  ```
  variable "origin"   {
      type        = any
      default     = []
      description = "One or more origins for this distribution (multiples allowed)."
  }
  
  variable "custom_origin_config" {
      type        = any
      default     = []
      description = "The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead."
  }
  
  ```
  
  **EDIT 1**
  
  A made a little changes `main.tf`
  
  ```
   dynamic "origin" {
      for_each  = var.origin
      content {
  
        domain_name   = origin.value.domain_name
        origin_id     = origin.value.origin_id
        origin_path   = origin.value.origin_path
  
        dynamic "custom_origin_config" {
          for_each  = var.custom_origin_config
          content {
        
          http_port                 = custom_origin_config.value.http_port
          https_port                = custom_origin_config.value.https_port
          origin_protocol_policy    = custom_origin_config.value.origin_protocol_policy
          origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
          origin_keepalive_timeout  = custom_origin_config.value.origin_keepalive_timeout
          origin_read_timeout       = custom_origin_config.value.origin_read_timeout
  
          }
        }
      }
    }
  
  ```
  
  and onto `vars.tf`:
  
  ```
  variable "origin"   {
      type        = any
  #    default     = []
      description = "One or more origins for this distribution (multiples allowed)."
  }
  
  variable "custom_origin_config" {
      type        = list
  #    default     = []
      description = "The CloudFront custom origin configuration information. If an S3 origin is required, use s3_origin_config instead."
  }
  
  ```
  
  **And now the output error change:**
  
  ```
  Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 29, in resource "aws_cloudfront_distribution" "cdn":
    29:         origin_ssl_protocols      = custom_origin_config.value.origin_ssl_protocols
  
  Inappropriate value for attribute "origin_ssl_protocols": set of string
  required.
  
  Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 43, in resource "aws_cloudfront_distribution" "cdn":
    43:         locations          = geo_restriction.value.location
  
  Inappropriate value for attribute "locations": set of string required.
  
  Error: Incorrect attribute value type
  
    on ../../../../../terraform-aws-modules/cloudfront_distribution/main.tf line 55, in resource "aws_cloudfront_distribution" "cdn":
    55:       cloudfront_default_certificate  = viewer_certificate.value.cloudfront_default_certificate
  
  Inappropriate value for attribute "cloudfront_default_certificate": a bool is
  required.
  
  ```
  
  **Someone has been through this problem, managed to solve it?**
  
  **Tags:** amazon-web-services, terraform, terraform-module
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-05. Score: 0 | Accepted answer
  
  I'm resolved my question like bellow:
  
  * I discovered that some arguments that I used before not was used when you use the **s3\_origin** and them are used with **custom\_orogin**
  
  Was necessary used too variables `type=list(object({foo=bar})` for my dynamic blocks lists.
  
  Part of my module bellow:
  
  **main.tf**
  
  ```
   dynamic "origin" {
      for_each = var.origin
      content {
  
        domain_name = origin.value.domain_name
        origin_id   = origin.value.origin_id
  
        s3_origin_config {
          origin_access_identity = origin.value.origin_access_identity
        }
      }
    }
  
  ```
  
  **vars.tf**
  
  ```
  variable "origin" {
    type        = list(object({ domain_name = any, origin_id = string, origin_access_identity = string }))
    description = "One or more origins for this distribution (multiples allowed)."
  }
  
  ```
  
  Another thing that I learned it's when you set a `default=value` onto variable `type` same this *var* is (optional) you turn them (required).
  
  
  ---
  
  