Terraform with Fedora CoreOS
what if a reinstallation is required
此文为上文的一点补充。
As far as I understand the sole purpose of cloud-init or user-data scripts is to do early initialization of instances. From that perspective, it may not make sense to use it as a way to re-provision or re-configure instances since that’s what tools like Puppet, Chef, Ansiable and Salt are for. Terraform was thought out as a way of creating and destroying infrastructure resources, and resource immutability is all over the place. https://github.com/terraform-providers/terraform-provider-aws/issues/23#issuecomment-308115064
然而Fedora CoreOS这样的immutable system的加入改变了这一现状,我们不再需要ansible/puppet或是其他的配置管理工具,而terraform,很遗憾,尚未对此作出相应的改变。我们所需求的特性即是:在资源特定元数据改变时,重新初始化资源,而非重新创建。幸运的是,terraform提供了provisioner与null resource,他们可以实现这一行为。
TL;DR
resource "null_resource" "reinstall" {
triggers = {
user_data = <provider>_server.server.user_data
}
provisioner "local-exec" {
command = "curl <api call to reinstall the given server>/${<provider>_server.server.id}"
}
}