Terraform with Python - can't find external program "python3"


I’m using the notify-slack module with Bitbucket Pipeline and the image: hashicorp/terraform docker image.

- step:
          name: Terraform plan
          oidc: true
            - cd network
            - export AWS_REGION=$TF_VAR_AWS_REGION
            - export AWS_ROLE_ARN=$TF_VAR_AWS_ROLE_ARN_production
            - export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
            - echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
            - terraform init -backend-config="access_key=$TF_VAR_aws_access_key_old_prod" -backend-config="secret_key=$TF_VAR_aws_secret_key_old_prod"
            - terraform workspace select prod || terraform workspace new prod
            - terraform plan -out plan.tfplan

When Bitbucke pipeline executes the terraform plan, I get the following error:

`│ Error: can't find external program "python3"`

`│ `

`│   with module.database.module.notify_slack.module.lambda.data.external.archive_prepare[0],`

`│   on .terraform/modules/database.notify_slack.lambda/package.tf line 7, in data "external" "archive_prepare":`

`│    7: data "external" "archive_prepare" {`

Can I get Python working in that docker image? Is my only solution to use another Docker image and to manually install Terraform and Python?


Hi @lpossamai,

The official Terraform Docker images contain only Terraform and Git, along with a minimal base operating system based on Alpine Linux.

If you need a different set of software for your Terraform runs then indeed you’ll need to construct your own Docker images which meet your needs. You could do that either by building on top of the official images (to add Python) or by starting from a general Linux distribution image which ships with python3 and adding Terraform to it.

I would recommend the second option because the Terraform Docker images are not really designed for customization, and so I expect it will not be straightforward to add new software to them, whereas general Linux distribution images typically are intended as a starting point for customizations.

1 Like

Thanks for your reply!

@lpossamai I’m having the same issue. Were you able to resolve it by creating a new Docker image?
If you have created a Docker image and it is public would you mind sharing it?