gcp 的 Terraform 文件,如何输入 json 键的路径

Terraform file for gcp, how to input path for json key

我正在研究如何在 gcp 中使用 Terraform 进行部署。 谁知道如何在下面模板中提到的配置文件中为 json 键编写 path

我在第 11 行遇到错误

 credentials = file("C:\Users\Administrator\Desktop\Terraform\mykey.json")

输出:

│ Error: Invalid escape sequence
│
│   on main.tf line 11, in provider "google":
│   11:   credentials = file("C:\Users\Administrator\Desktop\Terraform\mykey.json")
│
│ The symbol "l" is not a valid escape sequence selector.

模板示例:

terraform {
  required_providers {
    google = {
      source = "hashicorp/google"
      version = "3.5.0"
    }
  }
}

provider "google" {
  credentials = file("<NAME>.json")

  project = "<PROJECT_ID>"
  region  = "us-central1"
  zone    = "us-central1-c"
}

resource "google_compute_network" "vpc_network" {
  name = "terraform-network"
}

字符 \ 通常是一个 escape 字符,并与下一个字符组合。

指定凭据文件:

credentials = file("C:\Users\Administrator\Desktop\Terraform\mykey.json")

或像这样 - file() 不是必需的:

credentials = "C:\Users\Administrator\Desktop\Terraform\mykey.json"

或使用 Unix 路径语法:

credentials = "C:/Users/Administrator/Desktop/Terraform/mykey.json"