terraform-google-cloud-storage icon indicating copy to clipboard operation
terraform-google-cloud-storage copied to clipboard

Allow CORS and website configurations only for one bucket

Open Kamaradeivanov opened this issue 1 year ago • 8 comments

TL;DR

Actually, when we use your module to create multiple buckets, we can't enable CORS for only one bucket. Could you add an enhancement to specify which bucket should be affected by the CORS ?

In the code below, I don't want my datastore bucket to have a website and cors configuration

Terraform Resources

module "buckets" {
  source           = "terraform-google-modules/cloud-storage/google"
  version          = "~> 3.3"
  project_id       = var.project_id
  randomize_suffix = true
  names = [
    "website1",
    "website2",
    "datastore",
  ]
  force_destroy = {
    "website1"  = true,
    "website2"  = true,
    "datastore" = true,
  }
  prefix   = var.prefix
  location = var.region

  # Read only access by bucket
  set_viewer_roles = true
  viewers = [
    "group:${var.organisation_groups["viewers"]}",
  ]
  bucket_viewers = {
    "website1" = "allUsers",
    "website2" = "allUsers",
  }

  # Write access by bucket
  set_creator_roles = true
  bucket_creators = {
    "website1" = "group:${var.organisation_groups["website1"]}",
    "website2" = "group:${var.organisation_groups["website2"]}",
  }

  # Read, write and delete access by bucket
  set_admin_roles = true
  bucket_admins = {
    "website1"  = "serviceAccount:${var.adminweb}",
    "website2"  = "serviceAccount:${var.adminweb}",
    "datastore" = "serviceAccount:${var.admindata}",
  }
  labels = local.labels

  versioning = {
    "website1"  = true,
    "website2"  = true,
    "datastore" = false,
  }

  website = {
    main_page_suffix = "index.html"
    not_found_page   = "404.html"
  }

  cors = [
    {
      max_age_seconds = 3600
      method          = ["*"]
      origin          = ["*"]
      response_header = [
        "Access-Control-Allow-Origin",
        "Origin",
        "Content-Type",
        "Content-MD5",
        "Content-Disposition",
        "X-Goog-Content-Length-Range",
      ]
    }
  ]
}

Detailed design

Proposition of syntax

module "buckets" {
  source           = "terraform-google-modules/cloud-storage/google"
  version          = "~> 3.3"
  project_id       = var.project_id
  randomize_suffix = true
  names = [
    "website1",
    "website2",
    "datastore",
  ]
  force_destroy = {
    "website1"  = true,
    "website2"  = true,
    "datastore" = true,
  }
  prefix   = var.prefix
  location = var.region

  # Read only access by bucket
  set_viewer_roles = true
  viewers = [
    "group:${var.organisation_groups["viewers"]}",
  ]
  bucket_viewers = {
    "website1" = "allUsers",
    "website2" = "allUsers",
  }

  # Write access by bucket
  set_creator_roles = true
  bucket_creators = {
    "website1" = "group:${var.organisation_groups["website1"]}",
    "website2" = "group:${var.organisation_groups["website2"]}",
  }

  # Read, write and delete access by bucket
  set_admin_roles = true
  bucket_admins = {
    "website1"  = "serviceAccount:${var.adminweb}",
    "website2"  = "serviceAccount:${var.adminweb}",
    "datastore" = "serviceAccount:${var.admindata}",
  }
  labels = local.labels

  versioning = {
    "website1"  = true,
    "website2"  = true,
    "datastore" = false,
  }

  website = {
    "website1" = {
      main_page_suffix = "index.html"
      not_found_page   = "404.html"
    }
    "website2" = {
      main_page_suffix = "web2.html"
      not_found_page   = "w404.html"
    }
  }

  cors = {
    "website1" = {
      [
        {
          max_age_seconds = 3600
          method          = ["*"]
          origin          = ["*"]
          response_header = [
            "Access-Control-Allow-Origin",
            "Origin",
            "Content-Type",
            "Content-MD5",
            "Content-Disposition",
            "X-Goog-Content-Length-Range",
         ]
      }
    ]
  }
}

Additional information

No response

Kamaradeivanov avatar Jan 08 '24 15:01 Kamaradeivanov

PR to segment buckets by CORS: https://github.com/terraform-google-modules/terraform-google-cloud-storage/pull/296

bruno561 avatar Jan 20 '24 13:01 bruno561

PR to segment buckets by website configurations https://github.com/terraform-google-modules/terraform-google-cloud-storage/pull/297

bruno561 avatar Jan 20 '24 17:01 bruno561

Hello, do you know who is able to review your PRs ?

mehdicopter avatar Feb 19 '24 16:02 mehdicopter

@mehdicopter I guess the Google team.

bruno561 avatar Feb 22 '24 12:02 bruno561

Guys, I need revision. Can you help? In 7 days the PR will close automatically as it has been suspended for 60 days.

bruno561 avatar Apr 03 '24 23:04 bruno561

@bharathkkb

mehdicopter avatar Apr 12 '24 13:04 mehdicopter

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Jun 11 '24 23:06 github-actions[bot]

Any news regarding this improvement ?

Kamaradeivanov avatar Jun 13 '24 07:06 Kamaradeivanov

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Aug 12 '24 23:08 github-actions[bot]