terraform - 如何使用 template_file 从另一个 shell 执行 shell 脚本?
问题描述
我正在使用 TEMPLATE_FILE 指令为新的 GCP Compute Engine 实例执行引导 bash 脚本(称为“startup-script.sh”)。我创建了一个包含我的脚本的数据模板文件条目(见下文)。但是,从我的“startup-script.sh”脚本中,我想执行另一个包含函数和环境变量的脚本。换句话说,类似“.../some-directory/some-script.sh”这样的函数和变量可用于我的 startup-script.sh 脚本。我不清楚如何做到这一点。如果我尝试从我的 startup-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 个 data source template_file
,一个用于main ,other_script.sh
一个用于 main 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
}
推荐阅读
- php - 如何循环遍历自定义帖子类型的自定义元框值
- java - 如何汇总 Map 对象中的数字属性?
- ios - Swift Combine 中 combineLatest 的线程安全
- javascript - 如果在微调器运行时单击另一个组件的链接,如何避免错误?
- wso2 - 无法从管理控制台添加/更改 WSO2 5.10 中的用户角色
- android - 有没有办法让用户注册免费试用而无需自动续订(在 App/Google Play 商店中)
- spring-boot - 使用 java 11 设置 HTTPS 以在 Spring Boot 中启用 HTTP/2 的问题,
- android - 使用 TouchableOpacity 的所有选项(道具)制作一个新的 android 原生组件
- javascript - 在 Javascript 中手动操作输入时,如何确保触发键盘事件?
- amazon-web-services - Secrets Manager 资源策略:“此资源策略包含语法错误”