在出现中断时,我手动添加了一个新的用户数据脚本。我想把这个脚本添加回地形,以便地形状态是最新的。
我不确定这里出了什么问题,它试图重新创建实例。
我的地形变化怎么了?
在ec2实例中手动添加user_data脚本:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
iptables -F
echo "UserData is Executed"
--//
现有配置:
cloud-init.tpl
#cloud-config
---
package_update: true
packages:
- docker
#This runs on every boot
bootcmd:
- sh -c "sudo service docker start"
#These do not run on every boot
runcmd:
- curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- sh -c "sudo service docker start"
- mkdir /data
- ${format_command}
- echo "/dev/xvdf /data ext4 defaults,noatime 0 2" >> /etc/fstab
- mount -a
#ihr-deployer key
ssh_authorized_keys:
- ssh-rsa
AAxxxx
数据
data "template_file" "cloud_init" {
template = "${file("${path.module}/cloud-init.tpl")}"
vars = {
format_command = "${local.new_volume == 1 ? "sudo mkfs -t ext4 /dev/xvdf" : "echo DEVICE HAS ALREADY BEEN FORMATTED"}"
}
}
data "template_cloudinit_config" "cloud_init" {
part {
content = "${data.template_file.cloud_init.rendered}"
}
}
主.tf
user_data = "${data.template_cloudinit_config.cloud_init.rendered}"
更改:
data "template_cloudinit_config" "cloud_init" {
part {
content = "${data.template_file.cloud_init.rendered}"
}
part {
filename = "userdata.txt"
content_type = "text/x-shellscript"
content = "iptables -Fnecho "UserData is Executed"n"
}
}
输出:
user_data:"c3b472b9b74264b21237d7e71f0f89d76b83b2"=>quot;231c0e27943da00a4c0df284bf194729020ed105";(强制新资源(
您需要忽略user_data更改:
resource "aws_instance" "blah" {
...
lifecycle {
ignore_changes = ["user_data"]
}
}