terraform: fix

This commit is contained in:
Cadey Ratio 2017-12-02 18:00:32 -08:00
parent bbfefefe3c
commit ce8c3c8a56
2 changed files with 16 additions and 3 deletions

View File

@ -31,6 +31,7 @@ func provider() terraform.ResourceProvider {
"host": &schema.Schema{ "host": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: false, Optional: false,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ROUTE_HOST", nil), DefaultFunc: schema.EnvDefaultFunc("ROUTE_HOST", nil),
}, },
"verify_tls": &schema.Schema{ "verify_tls": &schema.Schema{

View File

@ -13,15 +13,16 @@ func routeResource() *schema.Resource {
Create: resourceRouteCreate, Create: resourceRouteCreate,
Read: resourceRouteRead, Read: resourceRouteRead,
Delete: resourceRouteDelete, Delete: resourceRouteDelete,
Exists: resourceRouteExists,
Importer: &schema.ResourceImporter{ Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough, State: schema.ImportStatePassthrough,
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"domain": { "host": {
Type: schema.TypeString, Type: schema.TypeString,
Required: false, Required: true,
ForceNew: true, ForceNew: true,
}, },
}, },
@ -32,7 +33,7 @@ func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error {
cli := meta.(proto.RoutesClient) cli := meta.(proto.RoutesClient)
rt, err := cli.Put(context.Background(), &proto.Route{ rt, err := cli.Put(context.Background(), &proto.Route{
Host: d.Get("domain").(string), Host: d.Get("host").(string),
}) })
if err != nil { if err != nil {
@ -62,6 +63,17 @@ func resourceRouteDelete(d *schema.ResourceData, meta interface{}) error {
return nil return nil
} }
func resourceRouteExists(d *schema.ResourceData, meta interface{}) (bool, error) {
cli := meta.(proto.RoutesClient)
_, err := cli.Get(context.Background(), &proto.GetRouteRequest{Id: d.Id()})
if err != nil {
return false, err
}
return true, nil
}
func resourceRouteRead(d *schema.ResourceData, meta interface{}) error { func resourceRouteRead(d *schema.ResourceData, meta interface{}) error {
cli := meta.(proto.RoutesClient) cli := meta.(proto.RoutesClient)