我有一个资源“ aws_instance”,其中包括供应者“ file”。当最初不存在EC2实例时,所有这些都可以正常工作。
如果从VM中删除了文件,如何重新运行预配器?
resource "aws_instance" "example" {
ami = "ami-0b0a60c0a2bd40612"
instance_type = "t2.micro"
key_name = "secret"
security_groups = ["terraform-basic-ssh-http"]
provisioner "file" {
source = "install-nginx.sh"
destination = "/tmp/install-nginx.sh"
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("/local/path/to/my/key.pem")}"
}
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/install-nginx.sh",
"/tmp/install-nginx.sh"
]
connection {
type = "ssh"
user = "ubuntu"
private_key = "${file("/local/path/to/mykey.pem")}"
}
}
}
答案 0 :(得分:0)
您还可以为此使用terraform taint
命令:terraform taint provisioner.file
如果您的资源位于模块中,请使用terraform taint -module=[MODULE_NAME] provisioner.file
这将使Terraform“重新创建”配置程序。