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{
Type: schema.TypeString,
Optional: false,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("ROUTE_HOST", nil),
},
"verify_tls": &schema.Schema{

View File

@ -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)