To change the target Google Cloud Platform (GCP) project for publishing messages from a registry to a different GCP project, follow these steps:
Identify your original project (e.g., skysharma-gcp
), your target project you want to publish (e.g., skysharma-gcp-2
), your Pub/Sub topic (e.g., root
), and subscription (e.g., root-sub
).
Give your original service account permissions in the target project as per Cloud Pub/Sub Documentation.
Update the subscription policy:
Retrieve the current policy (change yours accordingly):
gcloud pubsub subscriptions get-iam-policy projects/skysharma-gcp-2/subscriptions/root-sub --format json > ~/Temp/subscription_policy.json |
Edit subscription_policy.json
to add your service account with the role roles/pubsub.editor
. This gives the original service account access to this subscription in the new project. The updated subscription_policy.json
would look like this:
{ "etag": "BwUjMhCsNvY=", "bindings": [ { "role": "roles/pubsub.admin", "members": [ "user:user-1@gmail.com" ] }, { "role": "roles/pubsub.editor", "members": [ "serviceAccount:skysharma-gcp-svc-acct@skysharma-gcp.iam.gserviceaccount.com" } ] } |
Apply the updated policy (change yours accordingly):
gcloud pubsub subscriptions set-iam-policy projects/skysharma-gcp-2/subscriptions/root-sub ~/Temp/subscription_policy.json |
Update the topic policy:
Retrieve the current policy (change yours accordingly):
gcloud pubsub topics get-iam-policy projects/skysharma-gcp-2/topics/root --format json > ~/Temp/topic_policy.json |
Edit topic_policy.json
similar to the subscription policy step to add the bindings item to allow the current service account access to this topic. The updated topic_policy.json
would look like this:
{ "etag": "BwUjMhCsNvY=", "bindings": [ { "role": "roles/pubsub.editor", "members": [ "user:user-1@gmail.com", "serviceAccount:skysharma-gcp-svc-acct@skysharma-gcp.iam.gserviceaccount.com" ] } ] } |
Apply the updated policy (change yours accordingly):
gcloud pubsub topics set-iam-policy projects/skysharma-gcp-2/topics/root ~/Temp/topic_policy.json |
Have the API keys for your registry ready.
Use the curl
command to send a POST request to the changePubSubProject
endpoint. This API changes the target project for your Pub/Sub topics.
curl 'https://us-central1.clearblade.com/api/v/1/code/{SystemKey}/changePubSubProject' \ -X POST \ -d '{"project": "skysharma-gcp-2"}' \ -H 'ClearBlade-UserToken: {Token}' |
Replace {SystemKey}
and {Token}
with your specific values.
If your URL is different (e.g., europe-west1.clearblade.com
), adjust accordingly.
Send a test MQTT message from your device into the registry. Verify the message appears in the target project’s Pub/Sub subscription.
The capability to change the target project is available as a new API endpoint using your registry API key.
Currently, this process has no UI; it's only available via API.
To validate, send a test message and check if it appears in the target project.