terraform - Terraform:flatcar OS 的容器 linux 配置的存储部分中的 YAML 文件渲染问题
问题描述
我正在尝试通过模板渲染生成文件以传递给 ec2 实例的用户数据。我正在使用第三方 terraform 提供程序从 YAML 生成点火文件。
data "ct_config" "worker" {
content = data.template_file.file.rendered
strict = true
pretty_print = true
}
data "template_file" "file" {
...
...
template = file("${path.module}/example.yml")
vars = {
script = file("${path.module}/script.sh")
}
}
例子.yml
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: |
${script}
错误:
Error: Error unmarshaling yaml: yaml: line 187: could not find expected ':'
on ../../modules/launch_template/launch_template.tf line 22, in data "ct_config" "worker":
22: data "ct_config" "worker" {
如果我更改${script}
为示例数据,那么它可以工作。另外,无论我在 script.sh 中放什么,我都会遇到同样的错误。
解决方案
我有这个确切的问题ct_config
,今天解决了。您需要确保脚本在没有base64encode
换行符的情况下正确编写- 否则,脚本中的换行符将进入 CT,CT 会尝试构建一个不能有换行符的 Ignition 文件,从而导致您最初遇到的错误。
编码后,您只需告诉 CT!!binary
文件以确保 Ignition 在部署时正确地对其进行 base64 解码:
data "template_file" "file" {
...
...
template = file("${path.module}/example.yml")
vars = {
script = base64encode(file("${path.module}/script.sh"))
}
}
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: !!binary |
${script}
推荐阅读
- laravel - Laravel:如何使用 vendor:publish 更新错误视图
- c# - 在带有 Angular JS 的 ASP.NET Core 中使用 SignalR
- javascript - 如何在 Angular 8 应用程序中添加移动访问令牌?
- python - 如何将此 mongo 查询转换为 pymongo 代码?
- ag-grid - 我可以在 ag-grid 中拖动单元格内的内容以便复制它吗?
- sql - 如何在 SQL Server 中使用 TimeZone 将默认约束设置为 UTC 时间
- python - 如何从 DataLoader 获取样本的文件名?
- enums - 是否可以在 yaml 中使用枚举作为路径参数?
- swift - 在 Mac OS 上的 smb 服务器中获取 DFS 连接挂载通知的适当方法是什么?
- regex - 匹配两个字符之间的字符串(如果存在)