Skip to content

allow import terraform block passing locals from child module #5227

@chell0veck

Description

@chell0veck

Describe the enhancement

I'm looking the way to move following section next to root.hcl and import that across all child files.

terraform {
  source = (
    include.root.locals.tf_local_deploy ?
    format(include.root.locals.tf_local_ref,
      include.root.locals.tfmodules_name, local.module_name

    ) :
    format(
      include.root.locals.tf_remote_ref,
      include.root.locals.tfmodules_name, local.module_name, include.root.locals.tfmodules_version
    )
  )
}

Additional context

Here is a common pattern we use across 100-ish modules.

include "root" {
  path   = find_in_parent_folders("root.hcl")
  expose = true
}

include "region" {
  path   = find_in_parent_folders("region.hcl")
  expose = true
}

terraform {
  source = (
    include.root.locals.tf_local_deploy ?
    format(include.root.locals.tf_local_ref,
      include.root.locals.tfmodules_name, local.module_name

    ) :
    format(
      include.root.locals.tf_remote_ref,
      include.root.locals.tfmodules_name, local.module_name, include.root.locals.tfmodules_version
    )
  )
}

locals {
  module_name = "aws-vpc-endpoint"
}

inputs = {
...
}

following way to optimise the block does not allow to pass locals from child module and only works if content of terraform.hcl hardcoded.

include "terraform" {
  path   = find_in_parent_folders("terraform.hcl")
}

Things you might want to address include:

Changing around this block would definitely save a lots of redundant code and will allow to maintain huge projects easier and make code more DRY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions