部署Google Cloud Functions Gen2时Terraform报错:不支持指定资源类型
Terraform部署Google Cloud Functions Gen2时提示资源类型不支持
环境配置
gcloud -v Google Cloud SDK 402.0.0 alpha 2022.09.12 beta 2022.09.12 bq 2.0.75 core 2022.09.12 gsutil 5.13 pubsub-emulator 0.7.0 terraform -v Terraform v0.14.11 terraform init Initializing provider plugins... - Reusing previous version of hashicorp/archive from the dependency lock file - Reusing previous version of hashicorp/google from the dependency lock file - Reusing previous version of hashicorp/google-beta from the dependency lock file - Reusing previous version of hashicorp/null from the dependency lock file - Reusing previous version of hashicorp/random from the dependency lock file - Reusing previous version of hashicorp/time from the dependency lock file - Reusing previous version of hashicorp/template from the dependency lock file - Using previously-installed hashicorp/archive v2.2.0 - Using previously-installed hashicorp/google v3.90.1 - Using previously-installed hashicorp/google-beta v3.90.1 - Using previously-installed hashicorp/null v3.1.1 - Using previously-installed hashicorp/random v3.4.3 - Using previously-installed hashicorp/time v0.8.0 - Using previously-installed hashicorp/template v2.2.0
错误信息
terraform plan Error: Invalid resource type on modules/shared/functions/main.tf line 206, in resource "google_cloudfunctions2_function" "mergeopenapi_trigger_function": 206: resource "google_cloudfunctions2_function" "mergeopenapi_trigger_function" { *The provider provider.google does not support resource type "google_cloudfunctions2_function".*
解决方案
1. 切换到google-beta provider
google_cloudfunctions2_function是Google Cloud Functions Gen2对应的Terraform资源,该资源仅在google-beta provider中提供,需在资源块中指定使用google-beta provider:
resource "google_cloudfunctions2_function" "mergeopenapi_trigger_function" { provider = google-beta # 你的其他资源配置内容 }
2. 升级provider版本(可选但推荐)
当前使用的google-beta provider v3.90.1已支持GCF Gen2,但为避免兼容性问题,建议升级到较新的稳定版本,同时注意版本匹配:
- 若保留Terraform v0.14.11,需指定google-beta provider版本为v3.x系列的兼容版本:
provider "google-beta" { version = "~> 3.90" # 项目、区域等其他配置 } - 若可以升级Terraform,建议升级到v0.15+(推荐最新1.x稳定版),然后使用google-beta provider v4.x系列:
执行provider "google-beta" { version = "~> 4.0" # 项目、区域等其他配置 }terraform init -upgrade完成provider升级。
3. 确认Terraform版本兼容性
Terraform v0.14.11已停止维护,若使用google-beta provider v4.x,必须升级Terraform到v0.15或更高版本,否则会出现兼容性错误。
内容的提问来源于stack exchange,提问作者anthony44
相关产品推荐
相关产品推荐

