func (b *PubSubBroker) Provision(ctx context.Context, provisionContext *varcontext.VarContext) (models.ServiceInstanceDetails, error) {
	defaultLabels := provisionContext.GetStringMapString("labels")
	topicName := provisionContext.GetString("topic_name")
	subscriptionName := provisionContext.GetString("subscription_name")
	endpoint := ""
	if provisionContext.GetBool("is_push") {
		endpoint = provisionContext.GetString("endpoint")
	}
	subscriptionConfig := googlepubsub.SubscriptionConfig{
		PushConfig: googlepubsub.PushConfig{
			Endpoint: endpoint,
		},
		AckDeadline: time.Duration(provisionContext.GetInt("ack_deadline")) * time.Second,
		Labels:      defaultLabels,
	}
	if err := provisionContext.Error(); err != nil {
		return models.ServiceInstanceDetails{}, err
	}
	if topicName == "" {
		return models.ServiceInstanceDetails{}, errors.New("topic_name must not be blank")
	}
	pubsubClient, err := b.createClient(ctx)
	if err != nil {
		return models.ServiceInstanceDetails{}, err
	}
	topic, err := pubsubClient.CreateTopic(ctx, topicName)
	if err != nil {
		return models.ServiceInstanceDetails{}, fmt.Errorf("Error creating new Pub/Sub topic: %s", err)
	}
	if _, err := topic.Update(ctx, googlepubsub.TopicConfigToUpdate{Labels: defaultLabels}); err != nil {
		return models.ServiceInstanceDetails{}, fmt.Errorf("Error setting labels on new Pub/Sub topic: %s", err)
	}
	if subscriptionName != "" {
		subscriptionConfig.Topic = topic
		if _, err := pubsubClient.CreateSubscription(ctx, subscriptionName, subscriptionConfig); err != nil {
			return models.ServiceInstanceDetails{}, fmt.Errorf("Error creating subscription: %s", err)
		}
	}
	ii := InstanceInformation{
		TopicName:        topicName,
		SubscriptionName: subscriptionName,
	}
	id := models.ServiceInstanceDetails{
		Name:     topicName,
		Url:      "",
		Location: "",
	}
	if err := id.SetOtherDetails(ii); err != nil {
		return models.ServiceInstanceDetails{}, err
	}
	return id, err
}
Provision creates a new Pub/Sub topic from the settings in the user-provided details and service plan.
If a subscription name is supplied, the function will also create a subscription for the topic.
package pubsub
import (
	"errors"
	googlepubsub "cloud.google.com/go/pubsub"
	"github.com/GoogleCloudPlatform/gcp-service-broker/db_service/models"
	"github.com/GoogleCloudPlatform/gcp-service-broker/pkg/varcontext"
	"github.com/GoogleCloudPlatform/gcp-service-broker/utils"
	"github.com/pivotal-cf/brokerapi"
	"golang.org/x/net/context"
	"fmt"
	"time"
	"github.com/GoogleCloudPlatform/gcp-service-broker/pkg/providers/builtin/base"
	"google.golang.org/api/option"
)
type PubSubBroker struct {
	base.BrokerBase
}
type InstanceInformation struct {
	TopicName string `json:"topic_name"`
	SubscriptionName string `json:"subscription_name"`
}