https://pulumi.com logo
#google-cloud
Title
# google-cloud
a

astonishing-lifeguard-39886

01/11/2021, 3:19 PM
Hey everyone, I’m struggling with setting up (using Go) a service in cloud run in conjunction with a pub sub subscription. What I want to accomplish: 1. Setup / Create a new Cloud Run Service 2. New Cloud Run Service has an URL being generated (in my case, I don’t use domain mapping) 3. Setup / Create a Pub Sub Subscription, hand over the URL as the push endpoint the thing is: I can not find an “URL” Property within cloudrun.Service type 1)
Copy code
service, _ := cloudrun.NewService(s.ctx, "my-srv",
		&cloudrun.ServiceArgs{
			// Location from config
			Location: pulumi.String(s.region),
			// ProjectId from pulumi
			Project: pulumi.StringPtr(gcpConf.GetProject(s.ctx)),
			Template: &cloudrun.ServiceTemplateArgs{
				Spec: &cloudrun.ServiceTemplateSpecArgs{
					// e-mail of service account to run container in
					ServiceAccountName: s.serviceAccount.Email,
					Containers: &cloudrun.ServiceTemplateSpecContainerArray{
						&cloudrun.ServiceTemplateSpecContainerArgs{
							Image: "<my-image>",
						},
					},
				},
			}})
3)
Copy code
pubsub.NewSubscription(s.ctx, "my-subscription", &pubsub.SubscriptionArgs{
		Project: pulumi.StringPtr(gcpConf.GetProject(s.ctx)),
		Topic: "<my-topic>",
		Name: pulumi.String("my-subscription"),
		PushConfig: &pubsub.SubscriptionPushConfigArgs {
			PushEndpoint: // what does here?
		}
	
	})
PushConfig: &pubsub.SubscriptionPushConfigArgs { PushEndpoint: // what does here? } Thx in advance
c

creamy-engine-1851

01/11/2021, 3:33 PM
I've had the same problem, fortunately Cloud run has an URL pattern that you can use.
Copy code
https://<serviceName>-<projectHash>-<region>.<http://run.app|run.app>
projectHash is generated by the Platform, and you need to deploy a cloud run app to figure out what it is. region is a little bit odd, us-central1 is uc.a and europe-west1 is ew.a for instance
a

astonishing-lifeguard-39886

01/11/2021, 3:51 PM
mh. Well, in theory the information is there.
Copy code
service.Statuses
is an array of ServiceStatusInput. ServiceStatusInput contains an URL property - which is an StringPtrOutput But
Copy code
PushConfig: &pubsub.SubscriptionPushConfigArgs {
			PushEndpoint: service.Statuses.Index(<http://pulumi.Int|pulumi.Int>(0)).Url(),
		},
will not compile as
PushEndpoint
accepted StringInputs only
c

creamy-engine-1851

01/11/2021, 4:02 PM
Try something like this, haven't compiled it but maybe works:
Copy code
PushConfig: &pubsub.SubscriptionPushConfigArgs {
			PushEndpoint: service.Statuses.Index(<http://pulumi.Int|pulumi.Int>(0)).Url().ApplyString(func(v interface{}) (result string, err error) {
				result, ok := v.(string)
				if !ok {
					return result, errors.New("could not convert to string")
				}
				return result, nil
			}),
		},
a

astonishing-lifeguard-39886

01/11/2021, 4:59 PM
works @creamy-engine-1851 with a minor adaption for the type. indeed it is *string
Copy code
service.Statuses.Index(<http://pulumi.Int|pulumi.Int>(0)).Url().ApplyString(func(v interface{}) (result string, err error) {
		rawUrl, ok := v.(*string)
		if !ok {
			return *rawUrl, errors.New("could not convert to string")
		}
		return *rawUrl, nil
	})
✔️ 1