Open antoinedeschenes opened 8 months ago
Hi @antoinedeschenes I can see that you are declaring you project here in the resource google_pubsub_subscription_iam_member
:
resource "google_pubsub_subscription_iam_member" "default" {
subscription = "your-subscription-name"
**project = "your-project"**
role = "roles/pubsub.subscriber"
member = "serviceAccount:your-sa@your-project.iam.gserviceaccount.com"
}
But at the same time, you are importing it here but never using or reference it:
import {
id = "projects/your-project/subscriptions/your-subscription-name roles/pubsub.subscriber serviceAccount:your-sa@your-project.iam.gserviceaccount.com"
to = google_pubsub_subscription_iam_member.default
}
If you want to use your imported project on the "google_pubsub_subscription_iam_member" "default"
you just need to reference it:
resource "google_pubsub_subscription_iam_member" "default" {
**project = google_pubsub_subscription_iam_member.default.project**
subscription = "your-subscription-name"
role = "roles/pubsub.subscriber"
member = "allUsers"
}
@ggtisc why are you referring google_pubsub_subscription_iam_member.default
to itself?
resource "google_pubsub_subscription_iam_member" "default" {
**project = google_pubsub_subscription_iam_member.default.project**
the import block is equivalent to running:
terraform import google_pubsub_subscription_iam_member.default "projects/your-project/subscriptions/your-subscription-name roles/pubsub.subscriber serviceAccount:your-sa@your-project.iam.gserviceaccount.com"
manually
Confirmed the issue, and agreed that the import ID parsing looks incorrect.
I've been able to work around this by setting GOOGLE_PROJECT=garbage
(literally). The value you supply in the environment variable doesn't seem to have any bearing except that it silences the error. But I have to do this on both the import
, and on subsequent terraform plan
runs, as well, so it is less than ideal.
I run into the same # forces replacement
issue, too. That can then be worked around by editing the state, manually, though obviously, one must be careful here. In the state file, you will find that,
"project": null,
Tweak that to the project ID, and plan
should be happy / converge on no changes.
After I resolved the issue with "project": null
in the state file, and plan
was happy again, it was no longer necessary to supply a garbage value for GOOGLE_PROJECT
(i.e., that environment variable can just be unset, which is what it is normally for me).
Community Note
Terraform Version
Affected Resource(s)
google_pubsub_subscription_iam_*
Terraform Configuration
Debug Output
No response
Expected Behavior
Actual Behavior
Without
CLOUDSDK_CORE_PROJECT
environment variableWith
CLOUDSDK_CORE_PROJECT
set, the import ID isn't parsed properly, and the project is set in the subscription name instead:Steps to reproduce
terraform plan
Important Factoids
No response
References
Import id parsing seems to look for the subscription name only, without parsing the project and subscription properly in the path.
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription_iam#import
b/331832959