gruntwork-io/terraform-aws-utilities

The require-executable module forces an external program lookup on the terraform running environment even not used

kewei5zhang opened this issue · 0 comments

We are trying to use Terraform Cloud to plan and apply the eks-cluster-control-plane module and require-executable is a hard downstream dependency. It always fails because TFC runner has no python installed and there is no way we can disable terraform from checking the python executable even we are not using the required-executable functions.

Understand that we could just use the tf resources directly if not leveraging those basic validations gruntwork provided out of the box, but It is always good to provide options for users to work around without affecting the default behavior, especially for the use cases where people are migrating from self-hosted runners to terraform cloud.

Error Log:

with module.eks_cluster.module.require_kubergrunt.data.external.required_executable
on .terraform/modules/eks_cluster.require_kubergrunt/modules/require-executable/main.tf line 9, in data "external" "required_executable":
  program = ["python", "${path.module}/require_executable.py"]
The data source received an unexpected error while attempting to find the program.
Platform: linux
Program: python
Error: exec: "python": executable file not found in $PATH

Proposed Solution:
Using count to mute terraform plan if length(required_executable) == 0. (inspired by the executable-dependency module)

data "external" "required_executable" {
  count = length(var.required_executables) > 0 ? 1 : 0
  program = ["python3", "${path.module}/require_executable.py"]

  # Currently the external data source provider does not support list values in the query, so we convert the input list
  # to be a comma separated string.
  # See https://github.com/terraform-providers/terraform-provider-external/issues/2
  query = {
    required_executables = join(",", var.required_executables)
    error_message        = var.error_message
  }
}

Let me know what do you guys think, happy to contribute PRs.