Add new users as members to GCP Cloud Identity Group using Terraform

I have the gcp-organization-admins Cloud Identity User Group to which I want to add a new user [email protected] as a Member using Terraform.

Getting error - Error creating GroupMembership: googleapi: got HTTP response code 404. The requested URL /v1beta1/[email protected]/memberships?alt=json was not found on this server. Can anyone suggest how to resolve this please.

fyi...Just as a test, I was able to create new Cloud Identity user groups and added some test users into it without any problems using Terraform module https://github.com/terraform-google-modules/terraform-google-group

#=====================
# terraform.tfvars
#=====================
org_admin_user = ["[email protected]"]
org_admin_group = "[email protected]"

#=========================================================
# add-member.tf (adds user to google group as a member)
#=========================================================
resource "google_cloud_identity_group_membership" "user-01" {
  for_each = toset(var.org_admin_user)
  provider = google-beta
  group = var.org_admin_group
  preferred_member_key {
    id = each.key
  }
  roles {
    name = "MEMBER"
  }
}

This might to be the same issue as documented here: https://github.com/hashicorp/terraform-provider-google/issues/7616

A comment in that bug mentions the following:

I can work around the above issue by switching the order of the two roles in the resource, i.e.

From

  roles { name = "MANAGER" }
  roles { name = "MEMBER" }
to

  roles { name = "MEMBER" }
  roles { name = "MANAGER" }

https://github.com/hashicorp/terraform-provider-google/issues/7616#issuecomment-742779169


I ran into this same problem. Turns out that Terraform wants the GCP Group "name" and not the email address.

So the group attribute of the google_cloud_identity_group_membership resource block should look something like "groups/23097432uwhwiyo" and not "[email protected]"

You can look up the group "name" with the following gcloud command:

gcloud identity groups describe "[email protected]"