Error invalid instance URLs

Error invalid instance URLs: resource “google_compute_instance_group” “t-compute-instance-group”

Goal : Create a compute instance and add it to an unmanaged instance group in GCP using terraform.

Issue : A compute instance and an unmanaged instance group are being created successfully, but the instance is not being added to the group and giving: Error invalid instance URLs: resource “google_compute_instance_group” "t-compute-instance-group"

Able to add the instance to the group manually after running the terraform configuration though.

Service account key has Project Editor permission assigned.

Code: https://github.com/sagar-aj7/terraform_unmanaged_inst_group

Same question on stack overflow: https://stackoverflow.com/questions/65313133/error-invalid-instance-urls-resource-google-compute-instance-group-t-compute