如何使用Terraform停止GCP实例,或者创建已停止的GCP实例



今天我正在我的涡轮模式GCP设置和绊倒与以下情况:

以现在的方式,如果我运行terraform plan,那么计划将显示必须替换或重新创建实例。我已经设置了一个变量来传递我想要停止实例的命令。这个变量变成了desired_status。如果我尝试planapplydesired_status设置为STOPPED,那么terraform会给我这个错误:

google_compute_instance.vps: Refreshing state... [id=projects/artimanhas-do-lucaum/zones/us-central1-a/instances/vps]
╷
│ Error: 1 error occurred:
│   * When creating an instance, desired_status can only accept RUNNING value
│ 
│ 
│ 
│   with google_compute_instance.vps,
│   on gcp.tf line 59, in resource "google_compute_instance" "vps":
│   59: resource "google_compute_instance" "vps" {
│ 
╵

作为参考,这是我的tf文件:https://github.com/lucasew/nixcfg/blob/master/infra/gcp.tf

一切正常。在我的"擦除你亲爱的"NixOS设置中有一些东西需要解决,但这是另一个不太相关的问题。

目前,没有办法做到这一点,即使你直接创建虚拟机没有Terraform:

遗憾的是,我们没有在不立即运行的情况下创建VM实例的功能。最好的方法是在启动脚本中添加shutdown命令。

你可以尝试上面建议的启动脚本,在Terraform中有一个参数。

最新更新