Terraform

由於無效字元,打包程序無法解析 json

  • July 9, 2019

我想使用打包器來建構一個 ami。

AMI 最初是由aws_instanceterraform 中的資源建構的。它包含以下內容user_data

<powershell>
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
net stop winrm
sc.exe config winrm start=auto
net start winrm
</powershell>

當我將其複制並粘貼到打包器 json 文件中時,打包器不喜歡它:

$ packer build windows-2012.json
Failed to parse template: Error parsing JSON: invalid character '\n' in string literal
At line 22, column 1 (offset 560):
  21:     "user_data": "<powershell>
  22:

我該如何解決?

我轉而使用user_data_file並將內容放在本地文件中。

引用自:https://serverfault.com/questions/974499