github.com/terraform-linters/tflint@v0.51.2-0.20240520175844-3750771571b6/terraform/tfhcl/public.go (about)

     1  // Package tfhcl is a fork of hcl/ext/dynblock.
     2  // Like dynblock, it supports dynamic block expansion, but also resource
     3  // expansion via count/for_each meta-arguments.
     4  // This package is defined separately from hclext because meta-arguments
     5  // are a Terraform concern.
     6  package tfhcl
     7  
     8  import "github.com/hashicorp/hcl/v2"
     9  
    10  // Expand "dynamic" blocks and count/for_for_each meta-arguments resources
    11  // in the given body, returning a new body that has those blocks expanded.
    12  //
    13  // The given EvalContext is used when evaluating attributes within the given
    14  // body. If the body has a dynamic block or an expandable resource, its
    15  // contents are evaluated immediately.
    16  //
    17  // Expand returns no diagnostics because no blocks are actually expanded
    18  // until a call to Content or PartialContent on the returned body, which
    19  // will then expand only the blocks selected by the schema.
    20  func Expand(body hcl.Body, ctx *hcl.EvalContext) hcl.Body {
    21  	return &expandBody{
    22  		original: body,
    23  		ctx:      ctx,
    24  	}
    25  }