Group API: creation delay

Summary

In the terraform-gitlab-provider we have an open bug report that after creating a new group (with a valid 201 CREATED response and valid body), it is getting a 404 when trying to get the group immediately.

Some of the debug output:

2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:06 [DEBUG] create gitlab group "tfgroup"
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:06 [DEBUG] GitLab API Request Details:
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: ---[ REQUEST ]---------------------------------------
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: POST /api/v4/groups HTTP/1.1
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Host: gitlab.domain
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: User-Agent: HashiCorp Terraform/1.0.3 (+https://www.terraform.io) Terraform Plugin SDK/1.16.1 TFE/v202107-1 terraform-provider-gitlab
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Length: 219
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Accept: application/json
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Type: application/json
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Private-Token: <private-token>
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Accept-Encoding: gzip
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: {
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "name": "tfgroup",
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "path": "tfgroup",
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "description": "An example group",
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "two_factor_grace_period": 48,
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "project_creation_level": "maintainer",
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "subgroup_creation_level": "owner",
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "lfs_enabled": true,
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "request_access_enabled": false
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: }
2021-08-04T16:28:06.636Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: -----------------------------------------------------
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:07 [DEBUG] GitLab API Response Details:
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: ---[ RESPONSE ]--------------------------------------
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: HTTP/2.0 201 Created
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Length: 906
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Cache-Control: max-age=0, private, must-revalidate
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Type: application/json
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Date: Wed, 04 Aug 2021 16:28:07 GMT
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Etag: W/"<e-tag>"
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Referrer-Policy: strict-origin-when-cross-origin
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Server: nginx
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Strict-Transport-Security: max-age=63072000
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Vary: Origin
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Content-Type-Options: nosniff
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Frame-Options: SAMEORIGIN
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Request-Id: 01FC8ZWP3D7P474P64TB387EEQ
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Runtime: 0.422062
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: {
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "id": 52,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "web_url": "https://gitlab.domain/groups/tfgroup",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "name": "tfgroup",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "path": "tfgroup",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "description": "An example group",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "visibility": "private",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "share_with_group_lock": false,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "require_two_factor_authentication": false,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "two_factor_grace_period": 48,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "project_creation_level": "maintainer",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "auto_devops_enabled": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "subgroup_creation_level": "owner",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "emails_disabled": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "mentions_disabled": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "lfs_enabled": true,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "default_branch_protection": 2,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "avatar_url": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "request_access_enabled": false,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "full_name": "tfgroup",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "full_path": "tfgroup",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "created_at": "2021-08-04T16:28:06.699Z",
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "parent_id": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "ldap_cn": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "ldap_access": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "marked_for_deletion_on": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "shared_with_groups": [],
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "prevent_sharing_groups_outside_hierarchy": false,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "projects": [],
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "shared_projects": [],
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "shared_runners_minutes_limit": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "extra_shared_runners_minutes_limit": null,
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "prevent_forking_outside_group": false
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: }
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: -----------------------------------------------------
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:07 [DEBUG] read gitlab group 52
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:07 [DEBUG] GitLab API Request Details:
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: ---[ REQUEST ]---------------------------------------
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: GET /api/v4/groups/52 HTTP/1.1
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Host: gitlab.domain
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: User-Agent: HashiCorp Terraform/1.0.3 (+https://www.terraform.io) Terraform Plugin SDK/1.16.1 TFE/v202107-1 terraform-provider-gitlab
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Accept: application/json
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Private-Token: <private-token>
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Accept-Encoding: gzip
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 
2021-08-04T16:28:07.064Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: -----------------------------------------------------
{"@level":"info","@message":"gitlab_group.tfgroup: Creation errored after 0s","@module":"terraform.ui","@timestamp":"2021-08-04T16:28:07.207749Z","hook":{"resource":{"addr":"gitlab_group.tfgroup","module":"","resource":"gitlab_group.tfgroup","implied_provider":"gitlab","resource_type":"gitlab_group","resource_name":"tfgroup","resource_key":null},"action":"create","elapsed_seconds":0},"type":"apply_errored"}
{"@level":"error","@message":"Error: Provider produced inconsistent result after apply","@module":"terraform.ui","@timestamp":"2021-08-04T16:28:07.208086Z","diagnostic":{"severity":"error","summary":"Provider produced inconsistent result after apply","detail":"When applying changes to gitlab_group.tfgroup, provider \"provider[\\\"registry.terraform.io/gitlabhq/gitlab\\\"]\" produced an unexpected new value: Root resource was present, but now absent.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker."},"type":"diagnostic"}
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:07 [DEBUG] GitLab API Response Details:
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: ---[ RESPONSE ]--------------------------------------
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: HTTP/2.0 404 Not Found
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Length: 33
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Cache-Control: no-cache
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Content-Type: application/json
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Date: Wed, 04 Aug 2021 16:28:07 GMT
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Server: nginx
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: Vary: Origin
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Content-Type-Options: nosniff
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Frame-Options: SAMEORIGIN
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Request-Id: 01FC8ZWPGR514NY7ZZK7TWWHW9
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: X-Runtime: 0.138946
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: {
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0:  "message": "404 Group Not Found"
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: }
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: -----------------------------------------------------
2021-08-04T16:28:07.207Z [DEBUG] provider.terraform-provider-gitlab_v3.7.0: 2021/08/04 16:28:07 [DEBUG] gitlab group 52 not found so removing from state

I'm wondering if there is some syncing involved which needs completion? Or if that shouldn't happen and is indeed a bug?

Steps to reproduce

There are some using the terraform provider in the issue linked above.

However, you could probably try and create groups and getting it without a delay.

Example Project

see https://github.com/gitlabhq/terraform-provider-gitlab/issues/692

What is the current bug behavior?

Unable to GET group right after creating it

What is the expected correct behavior?

That after getting a valid 201 response from the create endpoint the group is immediately queryable.

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes