【问题标题】:Error while using Terraform provisioner file for GCP Windows VM为 GCP Windows VM 使用 Terraform 配置文件时出错
【发布时间】:2021-08-14 02:13:09
【问题描述】:

我在本地有一个文件,想通过 Terraform 在 GCP 中新创建的 Windows VM 中复制该文件。

该虚拟机已成功创建,但它不会在虚拟机中复制文件。

我尝试了很多方法,但不知道我做错了什么。

首先我尝试使用资源块。 示例:

resource "google_compute_instance" "vm_instance2" {
   name         = "instance1"
   machine_type = "n1-standard-4"
   zone         = "europe-west2-a"
   tags         =  ["web"]
   boot_disk {
      initialize_params {
         image = "abcd"
         size = "100"
         type = "pd-standard"
      }
   }
   network_interface {
       subnetwork  = google_compute_subnetwork.gcp_subnet2.name
       access_config {}
   }
   provisioner "file" {
     source = "test"
     destination = "C:/"

     connection {
       type     = "winrm"
       port    = "5985"
       user     = "UserName"
       password = "Password"
       timeout  = "60s"
       host     =  google_compute_instance.vm_instance2.network_interface.0.access_config.0.nat_ip
   }
 }
 }

但它不起作用,所以我尝试使用“null_resource”,但它也不起作用。

resource "null_resource" "provision_config" {
provisioner "file" {
source = "test"
destination = "C:/"

connection {
  type     = "winrm"
  port    = "5985"
  user     = "UserName"
  password = "pass@123"
  timeout  = "30s"
  host     =  google_compute_instance.vm_instance2.network_interface.0.access_config.0.nat_ip
}
}
}

我没有发现我做错了什么。

【问题讨论】:

  • 我面临错误:超时 - 最后一个错误:http 响应错误:401 - 内容类型无效
  • 你能检查一下用绝对路径替换源位置“test”是否有区别吗?见其他StackOverflow's Post
  • @Pedro 感谢您的意见,我也检查了绝对路径,但它也不起作用
  • 请您检查一下为什么代码资源顶部的“vm_instance2”与名称“instance1”不同?

标签: windows google-cloud-platform terraform google-compute-engine terraform-provider-gcp


【解决方案1】:

看起来与Github's issue 类似。看来Windows Image需要SSL,也就是说你需要设置

"winrm_use_ssl": true 

除了拥有证书之外,如果您没有证书,它可以是自签名的,添加“winrm_insecure”以跳过检查证书真实性。

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 2021-10-19
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2018-07-31
    • 2020-11-08
    相关资源
    最近更新 更多