title: Terraform reusing config blocks
body: <p>Terraform noob here. I have a datadog config along the line of (shamelessly copied from terraform website):</p>
  <pre><code>resource &quot;datadog_dashboard&quot; &quot;ordered_dashboard&quot; {
    title        = &quot;Ordered Layout Dashboard&quot;
    description  = &quot;Created using the Datadog provider in Terraform&quot;
    layout_type  = &quot;ordered&quot;
    is_read_only = true
  
    widget { # SIMILAR GRAPH
      alert_graph_definition {
        alert_id  = &quot;895605&quot;
        viz_type  = &quot;timeseries&quot;
        title     = &quot;Widget Title&quot;
        live_span = &quot;1h&quot;
      }
    }
  
    widget { # SIMILAR GRAPH
      alert_graph_definition {
        alert_id  = &quot;895605&quot;
        viz_type  = &quot;timeseries&quot;
        title     = &quot;Widget Title&quot;
        live_span = &quot;2h&quot;
      }
    }
  
    widget {
      alert_value_definition {
        alert_id   = &quot;895605&quot;
        precision  = 3
        unit       = &quot;b&quot;
        text_align = &quot;center&quot;
        title      = &quot;Widget Title&quot;
      }
    }
  
    widget { # SIMILAR GRAPH
      alert_graph_definition {
        alert_id  = &quot;895605&quot;
        viz_type  = &quot;timeseries&quot;
        title     = &quot;Widget Title&quot;
        live_span = &quot;1w&quot;
      }
    }
  
    widget { # SIMILAR GRAPH
      alert_graph_definition {
        alert_id  = &quot;895605&quot;
        viz_type  = &quot;timeseries&quot;
        title     = &quot;Widget Title&quot;
        live_span = &quot;2w&quot;
      }
    }
  }
  </code></pre>
  <p>As seen, we have 5 graphs: graph 1,2,4 and 5 are very similar, and only differ at 1 attribute, whereas graph 3 is very different. Is there a strategy in TF to reuse all the configs for graph 1,2 4 and 5?</p>
  <p>I have attempted at using dynamic blocks, but while dynamic blocks can generate graphs 1 and 2 well, graph 3 is so different that I cannot fit it in the dynamic block.</p>
  <p>In practice, the graphs are much more complex, and there are more of them, hence I find the config to be too hard to manage.</p>
  <p>This is what I tried:</p>
  <pre><code>resource &quot;datadog_dashboard&quot; &quot;ordered_dashboard&quot; {
    title        = &quot;Ordered Layout Dashboard&quot;
    description  = &quot;Created using the Datadog provider in Terraform&quot;
    layout_type  = &quot;ordered&quot;
    is_read_only = true
  
    dynamic widget {
      for_each = [&quot;1h&quot;, &quot;2h&quot;]
      iterator = live_span_iterator
      content {
        alert_graph_definition {
          alert_id  = &quot;895605&quot;
          viz_type  = &quot;timeseries&quot;
          title     = &quot;Widget Title&quot;
          live_span = live_span_iterator.value
        }
      }
    }
  
    widget {
      alert_value_definition {
        alert_id   = &quot;895605&quot;
        precision  = 3
        unit       = &quot;b&quot;
        text_align = &quot;center&quot;
        title      = &quot;Widget Title&quot;
      }
    }
  
    dynamic widget {
      for_each = [&quot;1w&quot;, &quot;2w&quot;]
      iterator = live_span_iterator
      content {
        alert_graph_definition {
          alert_id  = &quot;895605&quot;
          viz_type  = &quot;timeseries&quot;
          title     = &quot;Widget Title&quot;
          live_span = live_span_iterator.value
        }
      }
    }
  }
  </code></pre>
  <p>Are there any other strategies that might help me reduce the code duplication? I hope to retain the order of the graphs if possible.</p>