使用 Terraform Cloud 和 Google 提供商向 GCP 进行身份验证

问题描述 投票:0回答:1

我有以下代码用于在我的 GCP 项目中配置 GCS 存储桶

我正在使用 Terraform Cloud,并且已使用 GCP 的应用程序默认凭据进行了身份验证 我在 TF Cloud 中创建了一个环境变量,其值如下:

GOOGLE_CLOUD_KEYFILE_JSON =“C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json”

我的 Terraform 代码如下:

provider "google" {
  project     = "strange-flame-167811"
  region      = "us-east1"
  credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
}


resource "google_storage_bucket" "test" {
  name     = "my-project-id-test-bucket"
  location = "us-east1"
}

当我运行 Terraform 计划时,我收到以下错误:

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The \U escape sequence must be followed by eight hexadecimal digits.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "p" is not a valid escape sequence selector.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "D" is not a valid escape sequence selector.
╵

╷
│ Error: Invalid escape sequence
│ 
│   on main.tf line 4, in provider "google":
│    4:   credentials = "C:\Users\palla\Downloads\strange-flame-167811-26139c8660b2.json"
│ 
│ The symbol "s" is not a valid escape sequence selector.
google-cloud-platform terraform terraform-provider-gcp
1个回答
0
投票

由于反斜杠 (

\
) 是 Terraform 中的转义字符,因此您需要通过在前面添加另一个反斜杠来对其进行转义。

\\
文字反斜杠

参见:https://developer.hashicorp.com/terraform/language/expressions/strings#escape-sequences

© www.soinside.com 2019 - 2024. All rights reserved.