You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行terraform apply时遇Google Provider OAuth2令牌获取超时错误求助

Terraform 部署GCP存储桶时出现OAuth2令牌获取超时错误

我被这个问题卡了两天:按照课程指引创建了项目服务账号,给它分配了BigQuery Admin、Compute Admin等必要权限,把密钥放在main.tf同级的keys子文件夹里,并且在provider块配置了credentials = "./keys/my-creds.json"。但执行terraform apply时出现以下超时错误:

google_storage_bucket.demo-bucket: Creating...
google_storage_bucket.demo-bucket: Still creating... [10s elapsed]
google_storage_bucket.demo-bucket: Still creating... [20s elapsed]
google_storage_bucket.demo-bucket: Still creating... [30s elapsed]
╷
│ Error: Post "https://storage.googleapis.com/storage/v1/b?alt=json&prettyPrint=false&project=coherent-ascent-379901": oauth2: cannot fetch token: Post "https://oauth2.googleapis.com/token": dial tcp 172.217.163.42:443: i/o timeout

我的main.tf内容如下:

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

provider "google" {
  credentials = "./keys/my-creds.json" # Credentials only needs to be set if you do not have the GOOGLE_APPLICATION_CREDENTIALS set
  project     = "coherent-ascent-379901"
  region      = "us-central1"
}

resource "google_storage_bucket" "demo-bucket" {
  name          = "coherent-ascent-379901-terra-bucket"
  location      = "US"
  force_destroy = true

  lifecycle_rule {
    condition {
      age = 2 //days
    }
    action {
      type = "AbortIncompleteMultipartUpload"
    }
  }
}

我已经尝试了以下操作,但错误依然存在:

  • 用gcloud auth list确认服务账号和用户账号均处于活跃状态
  • 执行gcloud components update将SDK更新至最新版本
  • 通过gcloud auth application-default print-access-token成功获取到访问令牌
  • 执行gcloud auth application-default login重新完成授权

有没有人遇到过类似的问题?

内容的提问来源于Stack Exchange,提问作者Lili Li

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 07:26:13