forked from gruntwork-io/terraform-aws-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
39 lines (33 loc) · 1.47 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# RUN PEX BINARY AS A local-exec PROVISIONER
# This terraform module runs the provided pex binary in the context of a local-exec provisioner on a null_resource.
# This utilizes the `prepare-pex-environment` module to ensure the execution of the binary is done in a portable manner.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
terraform {
# This module is now only being tested with Terraform 0.15.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 0.15.x code.
required_version = ">= 0.12.26"
}
module "pex_env" {
source = "../prepare-pex-environment"
python2_pex_path_parts = var.python2_pex_path_parts
python3_pex_path_parts = var.python3_pex_path_parts
pex_module_path_parts = var.pex_module_path_parts
}
resource "null_resource" "run_pex" {
count = var.enabled ? 1 : 0
triggers = var.triggers
provisioner "local-exec" {
command = "${local.python_call} ${var.command_args}"
environment = merge(
{
PYTHONPATH = module.pex_env.python_path
},
var.env,
)
}
}
locals {
python_call = "python ${module.pex_env.pex_path} ${module.pex_env.entrypoint_path} ${var.script_main_function}"
}