我正在使用template_file指令执行一个新的GCP Compute Engine实例来执行Bootstrap Bash脚本(称其为" startup-script.sh")。我已经创建了一个包含我脚本的数据Template_file条目(请参见下文)。但是,从我的" startup-script.sh"脚本内部,我想执行另一个包含函数和环境变量的脚本。换句话说,诸如" ../some-directory/some-script.sh"之类的东西,以便我的startup-script.sh脚本可以使用这些函数和变量。我不清楚如何做到这一点。如果我尝试从启动script.sh内部执行" some-script.sh",则找不到。任何建议都将不胜感激。
data "template_file" "startup-script" {
template = "${file("startup-script.sh")}"
vars {....
" startup-script.sh"只是一个bash脚本,发出" Terraform Apply"时失败的呼叫看起来很简单:
#!/bin/bash
. ../other_dir/other_script.sh
我会创建2个数据源template_file
s,一个用于other_script.sh
,一个用于主startup-script.sh
,然后组合它们。
data "template_file" "startup-script" {
template = "${file("startup-script.sh")}"
}
data "template_file" "other_script" {
template = "${file("other_script.sh")}"
}
resource "aws_instance" "app" {
user_data = <<EOF
${data.template_file.other_script.rendered}
${data.template_file.startup-script.rendered}
EOF
}