简体   繁体   English

如何使用 Terraform 修改谷歌云中现有存储桶的 CORS

[英]How to modify CORS of an existing bucket in google cloud using Terraform

I create app engine using Terraform which creates a default bucket.我使用创建默认存储桶的 Terraform 创建应用引擎。 I would like to modify its CORS in the same terraform code.我想在相同的 terraform 代码中修改它的 CORS。

When I use following code it tries to create a new bucket:当我使用以下代码时,它会尝试创建一个新存储桶:

resource "google_storage_bucket" "app_engine_bucket" {
  name     = local.app_engine_default_bucket
  location = "US"
  cors {
    origin          = ["*"]
    method          = ["GET", "PUT", "DELETE"]
    response_header = ["Content-Type"]
    max_age_seconds = 3600
  }
}

Since you've added a comment that you're using Appengine, you'd use the app configuration yaml to specify your CORS settings.由于您添加了您正在使用 Appengine 的评论,因此您将使用应用配置 yaml来指定您的 CORS 设置。

Example:例子:

handlers:
- url: /images
  static_dir: static/images
  http_headers:
    Access-Control-Allow-Origin: https://mygame.uc.r.appspot.com
  # ...

If you wanted to modify buckets not managed by AppEngine you could specify the CORS configuration in the configuration for the bucket as Marcin mentioned in the comments.如果您想修改不受 AppEngine 管理的存储桶,您可以在存储桶的配置中指定 CORS 配置,如 Marcin 在评论中提到的那样。

example:例子:

resource "google_storage_bucket" "static-site" {
  name          = "image-store.com"
  location      = "EU"
  force_destroy = true

  uniform_bucket_level_access = true

  website {
    main_page_suffix = "index.html"
    not_found_page   = "404.html"
  }
  cors {
    origin          = ["http://image-store.com"]
    method          = ["GET", "HEAD", "PUT", "POST", "DELETE"]
    response_header = ["*"]
    max_age_seconds = 3600
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用存储桶的情况下通过 Terraform 部署 Google Cloud Function? - How to deploy the Google Cloud Function via Terraform without using a bucket? 创建谷歌云存储桶并使用相同的 terraform 脚本将 terraform 状态保存到其中? - Create google cloud bucket and save terraform state to it with the same terraform script? 如何协调 Terraform 状态与现有存储桶? - How to reconcile the Terraform State with an existing bucket? 在 terraform 中导入现有存储桶 - import an existing bucket in terraform 使用terraform修改现有的AWS VPC - modify existing AWS VPC using terraform 使用 Terraform 的 Google Cloud Composer - Google Cloud Composer using Terraform 如何使用Terraform将多个外部IP分配给Google Cloud实例 - How to assign multiple external IP to a google cloud instances using terraform 如何在 Google Cloud 中使用 Terraform 应用 kubernetes DaemonSet - How to apply kubernetes DaemonSet using Terraform in Google Cloud 有没有办法使用 terraform 对现有语句进行 append IAM 存储桶策略语句? - Is there a way to append IAM Bucket Policy Statement to Existing Statements using terraform? 如何将现有的谷歌云平台基础设施转换/迁移到 terraform 或其他 IaC - How to convert/migrate existing google cloud platform infrastructure to terraform or other IaC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM