您可以将Google云模拟器与Terraform一起使用吗?

发布于 2025-01-24 03:46:03 字数 114 浏览 0 评论 0原文

当我正确设置仿真器和Terraform时,我是否可以在模拟器内而不是在Google Cloud中的项目中运行Terraform?

我找不到网络上的答案,在我知道之前无法开始。

提前致谢!

When I setup the emulator and Terraform correctly, will I be able to run terraform with the results inside the emulator and not inside my project in Google Cloud?

I could not find an answer on the web and cannot start before I know.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏半生如梦愿梦如真 2025-01-31 03:46:03

是的,你可以!我们使用它来通过重复现有的生产环境配置来引导Google Pubsub仿真器。

诀窍是您需要覆盖提供商配置中的API端点:

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

provider "google" {
  project = "some-project-id"
  pubsub_custom_endpoint = "http://localhost:8085/v1/"
}

为了应用此操作,我以下启动模拟器:

$ gcloud beta emulators pubsub start --project=some-project-id

注意:

  • 项目-ID通过参数指定,并且必须匹配您在该项目中配置的项目-ID Terraform提供商
  • 端口8085是默认端口模拟器以

缺点

启动,因为您仅覆盖特定的端点,因此必须小心您创建的资源。例如,创建一个Google_service_account将发送请求发送到实际的Google端点。

有一些 Google服务的模拟器,但不是全部!另外,您可以覆盖Terraform提供商中的所有端点,以使其不存在本地端口。然后,这将无法应用计划,而不是在您可能不会期望的PREM上默默创建资源。

Yes you can! We use it to bootstrap the Google PubSub emulator by reusing our existing production environment configuration.

The trick is that you need to override the API Endpoints in the provider configuration:

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

provider "google" {
  project = "some-project-id"
  pubsub_custom_endpoint = "http://localhost:8085/v1/"
}

To apply this then, I start the emulator like this:

$ gcloud beta emulators pubsub start --project=some-project-id

Note:

  • The project-id is specified via the argument and must match the project-id you configure in the terraform provider
  • Port 8085 is the default port the emulator starts on

Drawbacks

Since you're overriding only specific endpoint, you must be careful which resources you create. For example, creating a google_service_account will sent that request to the actual Google endpoint.

There are emulators for some Google service, but not all! Alternatively, you can override all endpoints in the Terraform Provider to non-existing local ports. This will then fail to apply the plan instead of silently creating resources on prem that you might not expect.

三岁铭 2025-01-31 03:46:03

似乎用户想使用Terraform并将其指向仿真器。

https://cloud.google.com/spanner/docs/docs/emulator

请纠正我如果我错了。

It seems user want to play with terraform and point it to the emulator.

https://cloud.google.com/spanner/docs/emulator

Please correct me if I'm wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文