From 06eb388c3f124a1e6a64f57f3758fca1df661782 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 21 May 2015 15:01:28 -0500 Subject: [PATCH] provider/template: store relative path in state This makes template_file usage in modules portable. --- builtin/providers/template/resource.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/builtin/providers/template/resource.go b/builtin/providers/template/resource.go index d1a8176be..8eb3ce9eb 100644 --- a/builtin/providers/template/resource.go +++ b/builtin/providers/template/resource.go @@ -5,6 +5,8 @@ import ( "encoding/hex" "fmt" "io/ioutil" + "os" + "path/filepath" "github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config/lang" @@ -26,6 +28,18 @@ func resource() *schema.Resource { Required: true, Description: "file to read template from", ForceNew: true, + // Make a "best effort" attempt to relativize the file path. + StateFunc: func(v interface{}) string { + pwd, err := os.Getwd() + if err != nil { + return v.(string) + } + rel, err := filepath.Rel(pwd, v.(string)) + if err != nil { + return v.(string) + } + return rel + }, }, "vars": &schema.Schema{ Type: schema.TypeMap,