terraform/builtin/providers/google/resource_pubsub_topic.go

68 lines
1.3 KiB
Go

package google
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/pubsub/v1"
)
func resourcePubsubTopic() *schema.Resource {
return &schema.Resource{
Create: resourcePubsubTopicCreate,
Read: resourcePubsubTopicRead,
Delete: resourcePubsubTopicDelete,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}
func resourcePubsubTopicCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
name := fmt.Sprintf("projects/%s/topics/%s", config.Project, d.Get("name").(string))
topic := &pubsub.Topic{}
call := config.clientPubsub.Projects.Topics.Create(name, topic)
res, err := call.Do()
if err != nil {
return err
}
d.SetId(res.Name)
return nil
}
func resourcePubsubTopicRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
name := d.Id()
call := config.clientPubsub.Projects.Topics.Get(name)
_, err := call.Do()
if err != nil {
return err
}
return nil
}
func resourcePubsubTopicDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
name := d.Id()
call := config.clientPubsub.Projects.Topics.Delete(name)
_, err := call.Do()
if err != nil {
return err
}
return nil
}