最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

github actions - Python3 not found when creating external resource using terraform - Stack Overflow

programmeradmin1浏览0评论

I am trying to run some python script using external resource in terraform on github actions workflow but it throws Python3 not found error.

This works fine from local linux system.

module.tf

data "external" "debug_path" {
  program = ["/bin/bash", "-c", "echo \"{\\\"PATH\\\": \\\"$PATH\\\", \\\"PYTHON\\\": \\\"$(which python3)\\\"}\""]
}

output "debug_info" {
  value = data.external.debug_path.result
}

My terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "."
}

When I do terragrunt plan from local system, I get:

  + debug_info = {
      + PATH   = "/home/myuser/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/Rancher Desktop/resources/resources/win32/bin/:/mnt/c/Program Files/Rancher Desktop/resources/resources/win32/docker-cli-plugins/:/mnt/c/Program Files/Rancher Desktop/resources/resources/linux/bin/:/mnt/c/Program Files/Rancher Desktop/resources/resources/linux/docker-cli-plugins/:/mnt/c/Program Files/Amazon/AWSCLIV2/:/mnt/c/Users/myuser/AppData/Local/Programs/Python/Python312:/mnt/c/Users/myuser/AppData/Local/Programs/Python/Python312/Scripts:/mnt/c/Program Files/Amazon/SessionManagerPlugin/bin/:/mnt/c/Users/myuser/AppData/Local/Programs/Python/Launcher/:/mnt/c/Users/myuser/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/myuser/AppData/Local/Programs/Git/cmd:/mnt/c/Users/myuser/AppData/Local/JetBrains/Toolbox/scripts:/mnt/c/Program Files/JetBrains/IntelliJ IDEA 2024.2.3/bin:/mnt/c/Users/myuser/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/myuser/AppData/Local/Programs/Python/Python312:/snap/bin:/usr/local/bin"
      **+ PYTHON = "/usr/bin/python3"**
    }

This path and python location match what I have locally..

But when I use below github actions workflow:

  - name: Init
    uses: gruntwork-io/terragrunt-action@v2
    with:
      tf_version: ${{ env.tf_version }}
      tg_command: 'init'
      tg_comment: true
      tg_dir: accounts/${{ github.event.inputs.aws_account_name }}/${{ github.event.inputs.aws_region }}/service
      tg_version: ${{ env.tg_version }}
    
  - name: Plan
    uses: gruntwork-io/terragrunt-action@v2
    with:
      tf_version: ${{env.tf_version}}
      tg_command: 'plan'
      tg_comment: true
      tg_dir: accounts/${{ github.event.inputs.aws_account_name }}/${{ github.event.inputs.aws_region }}/service
      tg_version: ${{env.tg_version}}

I get:

  + debug_info = {
      + PATH   = "/github/home/.local/share/mise/installs/terraform/1.7.5/bin:/github/home/.local/share/mise/installs/terragrunt/0.55.16/bin:~/.local/share/mise/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
      **+ PYTHON = ""**
    }

That is python is not available. I have tried installing python3 in workflow and checked the path, and that path does not match to path I get from terragrunt plan.

I am not sure why this doesn't work, anybody any clue?

TF version: 1.7.5 TG version: 0.55.16

发布评论

评论列表(0)

  1. 暂无评论