diff --git a/cmd/terraform-provider-route/main.go b/cmd/terraform-provider-route/main.go index 88534f1..635cd84 100644 --- a/cmd/terraform-provider-route/main.go +++ b/cmd/terraform-provider-route/main.go @@ -31,6 +31,7 @@ func provider() terraform.ResourceProvider { "host": &schema.Schema{ Type: schema.TypeString, Optional: false, + Required: true, DefaultFunc: schema.EnvDefaultFunc("ROUTE_HOST", nil), }, "verify_tls": &schema.Schema{ diff --git a/cmd/terraform-provider-route/route.go b/cmd/terraform-provider-route/route.go index 10eb74a..6a0def2 100644 --- a/cmd/terraform-provider-route/route.go +++ b/cmd/terraform-provider-route/route.go @@ -13,15 +13,16 @@ func routeResource() *schema.Resource { Create: resourceRouteCreate, Read: resourceRouteRead, Delete: resourceRouteDelete, + Exists: resourceRouteExists, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ - "domain": { + "host": { Type: schema.TypeString, - Required: false, + Required: true, ForceNew: true, }, }, @@ -32,7 +33,7 @@ func resourceRouteCreate(d *schema.ResourceData, meta interface{}) error { cli := meta.(proto.RoutesClient) rt, err := cli.Put(context.Background(), &proto.Route{ - Host: d.Get("domain").(string), + Host: d.Get("host").(string), }) if err != nil { @@ -62,6 +63,17 @@ func resourceRouteDelete(d *schema.ResourceData, meta interface{}) error { 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 { cli := meta.(proto.RoutesClient)