package main import ( "context" "log" proto "git.xeserv.us/xena/route/proto" "github.com/hashicorp/terraform/helper/schema" ) func routeResource() *schema.Resource { return &schema.Resource{ Create: resourceRouteCreate, Read: resourceRouteRead, Delete: resourceRouteDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ "domain": { Type: schema.TypeString, Required: false, }, }, } } func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error { cli := meta.(*proto.RoutesClient) rt, err := rc.Put(context.Background(), &proto.Route{ Host: d.Get("domain").(string), }) if err != nil { return err } log.Printf("[INFO] created route for domain %s with ID %s", rt.Domain, r.Id) return nil } func resourceRouteDelete(d *schema.ResourceData, meta interface{}) error { cli := meta.(*proto.RoutesClient) rt, err := cli.Get(context.Background(), &proto.GetRouteRequest{Id: d.Id()}) if err != nil { return err } err = cli.Delete(context.Background(), rt) if err != nil { return err } log.Printf("[INFO] deleted route for domain %s with ID %s", rt.Domain, r.Id) return nil } func resourceRouteRead(d *schema.ResourceData, meta interface{}) error { cli := meta.(*proto.RoutesClient) rt, err := cli.Get(context.Background(), &proto.GetRouteRequest{Id: d.Id()}) if err != nil { return err } d.SetId(r.Id) d.Set("host", rt.Host) d.Set("creator", rt.Creator) return nil }