具有 Beta 参数的 Google Cloud Platform 资源的正确 Terraform 提供程序配置是啥?

     2023-03-22     159

关键词:

【中文标题】具有 Beta 参数的 Google Cloud Platform 资源的正确 Terraform 提供程序配置是啥?【英文标题】:What is the Correct Terraform Provider Configuration for Google Cloud Platform Resources with Beta Arguments?具有 Beta 参数的 Google Cloud Platform 资源的正确 Terraform 提供程序配置是什么? 【发布时间】:2021-11-07 07:51:32 【问题描述】:

改造任何由任何 beta 参数定义的 Google Cloud Platform (GCP) 资源都需要 google-beta 提供程序。是否应该使用google-beta 提供程序而不是google 提供程序一起使用?

换句话说,假设某个 Google Kubernetes Engine (GKE) 集群 $GKE_CLUSTER_NAME 存在于 GCP 项目 $GCP_PROJECT_NAME 中:

gcloud container clusters list \
--format="value(name)" \
--project=$GCP_PROJECT_NAME

#=>

. . .
$GKE_CLUSTER_NAME
. . .

启用配置连接器:

gcloud container clusters describe $GKE_CLUSTER_NAME \
--format=“value(addonsConfig.configConnectorConfig.enabled)” \
--zone=$GKE_CLUSTER_ZONE

#=>

True

地形化$GKE_CLUSTER_NAME 需要在container_cluster.tf 内定义google_container_cluster 资源定义,其中包括config_connector_config 参数(在addons_config 块内;更多here)和provider 参数(从官方缺少参考文档):

resource "google_container_cluster" "test" 
  addons_config 
    config_connector_config 
      enabled = true
    
    . . .
  
  . . .
  provider        = google-beta
  . . .

不需要providers.tf 中需要google-beta provider 定义:

provider "google" 
  project = ". . ."


terraform 
  required_providers 
    google = 
      version = "~> 3.83.0"
    
  

这与缺少来自其他资源定义的provider 参数(例如在container_node_pool.tf 中找到的google_container_node_pool)导致providers 命令的以下输出:

terraform providers

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/google] ~> 3.83.0
└── provider[registry.terraform.io/hashicorp/google-beta]

Providers required by state:

    provider[registry.terraform.io/hashicorp/google]

    provider[registry.terraform.io/hashicorp/google-beta]

apply 命令刷新terraform.tfstate 状态文件之后。

使用 beta 参数对 GCP 资源进行地形改造是更正确且不易出错的方法吗?或者,我是否应该运行 replace-provider 子命令:

terraform state replace-provider \
-auto-approve \
"hashicorp/google" \
"hashicorp/google-beta"

#=>

Terraform will perform the following actions:

  ~ Updating provider:
    - registry.terraform.io/hashicorp/google
    + registry.terraform.io/hashicorp/google-beta

Changing 2 resources:

  google_container_node_pool.$GKE_NODE_POOL_NAME

Successfully replaced provider for 1 resources.

并修改providers.tf:

provider "google-beta" 
  project = ". . ."


terraform 
  required_providers 
    google-beta = 
      version = "~> 3.83.0"
    
  

所以providers 命令的输出是:

terraform providers

#=>

Providers required by configuration:
.
└── provider[registry.terraform.io/hashicorp/google-beta] ~> 3.83.0

Providers required by state:

    provider[registry.terraform.io/hashicorp/google-beta]

apply 命令刷新terraform.state 中的状态之后?

【问题讨论】:

【参考方案1】:

应该使用googlegoogle-beta 提供程序。

在同一个providers.tf 中同时使用googlegoogle-beta 提供程序是安全。 Terraform 向 Beta 端点发送对任何需要 google-beta 提供程序的资源的请求:https://. . .googleapis.com/v1beta1/. . .;即,使用 google-beta 提供程序类似于使用 beta gcloud 组。

应该

providers.tf 中包含googlegoogle-beta 提供程序:

provider "google" 
  project = ". . ."


provider "google-beta" 
  project = ". . ."


terraform 
  required_providers 
    google = 
      version = "~> 3.83.0"
    
    google-beta = 
      version = "~> 3.83.0"
    
  

每个 GCP 资源使用provider 参数:google-beta 用于具有 至少一项启用的 Beta 功能:

resource "google_container_cluster" "beta_cluster" 
   . . .
   provider        = google-beta
   . . .

google 表示其他所有资源:

resource "google_container_node_pool" "general_availability_node_pool" 
. . .
  provider       = google
. . .

在完成上述建议的两个然后运行refresh后,输出 providers 命令现在应该如下所示:

terraform providers

#=>

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/google] ~> 3.83.0
└── provider[registry.terraform.io/hashicorp/google-beta] ~> 3.83.0

Providers required by state:

    provider[registry.terraform.io/hashicorp/google]

    provider[registry.terraform.io/hashicorp/google-beta]

应该通读官方文档。对于提供程序版本here。

【讨论】:

具有 Trace Agent 连接的 Google Cloud Functions

】具有TraceAgent连接的GoogleCloudFunctions【英文标题】:GoogleCloudFunctionswithTraceAgentconnection【发布时间】:2017-11-1720:33:24【问题描述】:我需要为我们的应用程序连接监控和跟踪工具。我们的主要代码在运行在GoogleCloudFunctions上的Expre... 查看详情

您可以在具有服务角色的项目之间共享 Google Cloud KMS 密钥吗?

】您可以在具有服务角色的项目之间共享GoogleCloudKMS密钥吗?【英文标题】:CanyoushareGoogleCloudKMSkeysacrossprojectswithserviceroles?【发布时间】:2018-08-1905:27:36【问题描述】:ThisGCParticle建议使用两个独立的项目:一个用于密钥管理,... 查看详情

删除 Google Cloud Datalab SQL 模块参数中的引号?

】删除GoogleCloudDatalabSQL模块参数中的引号?【英文标题】:RemovequotemarksinGoogleCloudDatalabSQLmoduleparameters?【发布时间】:2015-12-1512:01:58【问题描述】:datalabgithub存储库(位于datalab/tutorials/BigQuery/下)的“SQL参数”IPython笔记本中的... 查看详情

在 Google Cloud Spanner 中定义具有不同外键的交错表

】在GoogleCloudSpanner中定义具有不同外键的交错表【英文标题】:DefininginterleavedtablewithdifferentforeignkeyinGoogleCloudSpanner【发布时间】:2020-11-3018:32:54【问题描述】:我正在尝试定义交错表,当父表主表和交错表外键的列名相同时,... 查看详情

具有单一 cloudbuild 的 Mono-repository 架构中的 Google Cloud Build 管道

】具有单一cloudbuild的Mono-repository架构中的GoogleCloudBuild管道【英文标题】:GoogleCloudBuildpipelineinMono-repositoryarchitecturewithsinglecloudbuild【发布时间】:2021-09-1917:50:45【问题描述】:我们使用多个python部署到具有文件夹结构的单个GitHub... 查看详情

具有自动缩放功能的 Google Cloud Messaging Server 密钥白名单 IP 地址

】具有自动缩放功能的GoogleCloudMessagingServer密钥白名单IP地址【英文标题】:GoogleCloudMessagingServerkeywhitelistIPaddresseswithautoscaling【发布时间】:2013-06-0919:21:44【问题描述】:我正在迁移我的AWSbeanstalk应用程序以在服务器端使用GCM进... 查看详情

同时创建多个具有私有 IP 的 Google Cloud SQL 实例时如何解决“发生未知错误”?

】同时创建多个具有私有IP的GoogleCloudSQL实例时如何解决“发生未知错误”?【英文标题】:Howtofix"AnUnknownErrorOccurred"whencreatingmultipleGoogleCloudSQLinstanceswithprivateIPsimultaneously?【发布时间】:2019-09-2305:37:24【问题描述】:我们... 查看详情

连接需要具有 ssl 模式的 laravel google cloud postgres 中的有效客户端证书

】连接需要具有ssl模式的laravelgooglecloudpostgres中的有效客户端证书【英文标题】:connectionrequiresavalidclientcertificateinlaravelgooglecloudpostgreswithsslmode【发布时间】:2022-01-2205:34:29【问题描述】:我在尝试连接到gcloudpostgresdb时遇到问题... 查看详情

从具有私有和公共 IP 的虚拟机连接到私有 IP 上的 Google Cloud SQL 实例失败

】从具有私有和公共IP的虚拟机连接到私有IP上的GoogleCloudSQL实例失败【英文标题】:ConnectingtoGoogleCloudSQLinstanceonprivateIPfromaVMwithbothprivateandpublicIPsfails【发布时间】:2020-12-3008:06:15【问题描述】:我要设置的内容:具有私有IP、Post... 查看详情

将参数从 Google Cloud 函数 GET 请求传递到 BigQuery

】将参数从GoogleCloud函数GET请求传递到BigQuery【英文标题】:PassingparamsfromaGoogleCloudFunctionGETRequesttoBigQuery【发布时间】:2020-06-0215:49:48【问题描述】:我已经成功部署了一个谷歌云函数,它接收来自POST请求的参数。我现在正在尝... 查看详情

Google Cloud Functions - 为啥 GCF 将两个位置参数传递给我的函数?

】GoogleCloudFunctions-为啥GCF将两个位置参数传递给我的函数?【英文标题】:GoogleCloudFunctions-WhyaretwopositionalargumentspassedintomyfunctionbyGCF?GoogleCloudFunctions-为什么GCF将两个位置参数传递给我的函数?【发布时间】:2019-03-1011:06:25【问题... 查看详情

如何从 Google bigquery(google-cloud-ruby gem)的视图表(具有 resource_full)中获取数据

】如何从Googlebigquery(google-cloud-rubygem)的视图表(具有resource_full)中获取数据【英文标题】:howtogetdatafromaviewtable(whichhasresource_full)fromGooglebigquery(google-cloud-rubygem)【发布时间】:2018-02-1312:05:29【问题描述】:我正在开发Sinatra,r... 查看详情

Google Cloud Run (GCR) 的 Gunicorn (with Flask) 参数 - 在 Dockerfile 中放置啥? [关闭]

】GoogleCloudRun(GCR)的Gunicorn(withFlask)参数-在Dockerfile中放置啥?[关闭]【英文标题】:Gunicorn(withFlask)parametersforGoogleCloudRun(GCR)-whattoputinDockerfile?[closed]GoogleCloudRun(GCR)的Gunicorn(withFlask)参数-在Dockerfile中放置什么?[关闭]【发布时间 查看详情

使用 Google.Cloud.BigQuery.V2 的 BigQuery 加载作业的幂等性

...5-1410:07:29【问题描述】:您可以使用Google.Cloud.BigQuery.V2中具有CreateLoadJob方法的BigQueryClient创建csv加载作业,以从Goog 查看详情

Google Cloud Video API 在使用“input_content”参数时出错

】GoogleCloudVideoAPI在使用“input_content”参数时出错【英文标题】:GoogleCloudVideoAPIgiveserroronusing"input_content"argument【发布时间】:2022-01-1302:58:23【问题描述】:我正在尝试使用GoogleVideoAPI并使用"input_content"参数传递我... 查看详情

如何让 Google Cloud Functions 保持温暖?

...Next.js与FirebaseHosting连接起来的唯一方法。我不需要让它具有成本效益,等 查看详情

Google Cloud SQL 维护时段

...犹豫不决的原因是,我找不到如果我将CloudSQL实例设置为具有只读副本的高可用性,计划的维护将如何进行。在阅读了几个小时的SO和文档之后,我相信即使在HA实例的情况下,您也可能会因计划维护而遇到中断,因此您无法将任... 查看详情

带有服务帐户的 Google Cloud Pub Sub

...了一个让我发疯的pubsub问题。基本上我有一个用于pubsub的具有管理员权限的服务帐户,但我无法正常工作,并且出现以下错误:ERROR:root:AuthMetadataPluginCallback""引发异常!回溯(最近一 查看详情