hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.33k stars 1.74k forks source link

google_access_context_manager_access_level_condition should provide an option to add the new condition to the existing condition with an "OR" operator #8125

Open anubbhavm opened 3 years ago

anubbhavm commented 3 years ago

Community Note

Description

Introduce a new parameter "operator" to "google_access_context_manager_access_level_condition" to provide an option to add the new condition to the existing condition with an "OR" operator. Currently, the new condition gets added with an "AND" operator. See below for example.

Include all the following attributes
Regions match CH (Switzerland), IT (Italy), and US (United States)
Device screen lock
OS restrictions match Chrome OS (any version)
Members match vpc-sc@XXXX.iam.gserviceaccount.com
AND
Include all the following attributes
IP Subnetworks match 192.0.4.0/24
Regions match IT (Italy) and US (United States)
Device corp owned
OS restrictions match Chrome OS (any version)
Members match test@google.com, test2@google.com, and tf-test-123@XXXX.iam.gserviceaccount.com

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_access_context_manager_access_level" "access-level-service-account" {
  parent = "accessPolicies/410809943175"
  name   = "accessPolicies/410809943175/accessLevels/tf_test_new_resource"
  title  = "tf_test_new_resource"
  basic {
    conditions {
      device_policy {
        require_screen_lock = true
        os_constraints {
          os_type = "DESKTOP_CHROME_OS"
        }
      }
      members = ["serviceAccount:vpc-sc@XXXX.iam.gserviceaccount.com"]
      regions = [
  "CH",
  "IT",
  "US",
      ]
    }
  }

  lifecycle {
    ignore_changes = [basic.0.conditions]
  }
}

resource "google_service_account" "created-later" {
  account_id = "tf-test-123"
}

resource "google_access_context_manager_access_level_condition" "access-level-conditions" {
  access_level = google_access_context_manager_access_level.access-level-service-account.name
  operator = "OR"
  ip_subnetworks = ["192.0.4.0/24"]
  members = ["user:test@google.com", "user:test2@google.com", "serviceAccount:${google_service_account.created-later.email}"]
  negate = false
  device_policy {
    require_screen_lock = false
    require_admin_approval = false
    require_corp_owned = true
    os_constraints {
      os_type = "DESKTOP_CHROME_OS"
    }
  }
  regions = [
    "IT",
    "US",
  ]
}

b/359383500

ggtisc commented 2 months ago

The user is looking too add a new argument called operator to manage different operators like OR to the google_access_context_manager_access_level_condition resource.

roaks3 commented 1 month ago

Note that this should technically be possible through the API by using combiningFunction, but I believe it should be a change to google_access_context_manager_access_level. Adding it to the condition presents 2 problems: it becomes unclear which resource controls the behavior, and the combiningFunction field exists one level up from the fields that the condition resource interacts with.