github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/google/resource_pubsub_topic.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "google.golang.org/api/pubsub/v1" 6 "github.com/hashicorp/terraform/helper/schema" 7 ) 8 9 func resourcePubsubTopic() *schema.Resource { 10 return &schema.Resource{ 11 Create: resourcePubsubTopicCreate, 12 Read: resourcePubsubTopicRead, 13 Delete: resourcePubsubTopicDelete, 14 15 Schema: map[string]*schema.Schema{ 16 "name": &schema.Schema{ 17 Type: schema.TypeString, 18 Required: true, 19 ForceNew: true, 20 }, 21 22 }, 23 } 24 } 25 26 func resourcePubsubTopicCreate(d *schema.ResourceData, meta interface{}) error { 27 config := meta.(*Config) 28 29 name := fmt.Sprintf("projects/%s/topics/%s", config.Project, d.Get("name").(string)) 30 topic := &pubsub.Topic{} 31 32 call := config.clientPubsub.Projects.Topics.Create(name, topic) 33 res, err := call.Do() 34 if err != nil { 35 return err 36 } 37 38 d.SetId(res.Name) 39 40 return nil 41 } 42 43 func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error { 44 config := meta.(*Config) 45 46 name := d.Id() 47 call := config.clientPubsub.Projects.Topics.Get(name) 48 _, err := call.Do() 49 if err != nil { 50 return err 51 } 52 53 return nil 54 } 55 56 57 func resourcePubsubTopicDelete(d *schema.ResourceData, meta interface{}) error { 58 config := meta.(*Config) 59 60 name := d.Id() 61 call := config.clientPubsub.Projects.Topics.Delete(name) 62 _, err := call.Do() 63 if err != nil { 64 return err 65 } 66 67 return nil 68 }