Skip to content

Commit 06eb388

Browse files
committed
provider/template: store relative path in state
This makes template_file usage in modules portable.
1 parent e5f5e1a commit 06eb388

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

builtin/providers/template/resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/hex"
66
"fmt"
77
"io/ioutil"
8+
"os"
9+
"path/filepath"
810

911
"github.com/hashicorp/terraform/config"
1012
"github.com/hashicorp/terraform/config/lang"
@@ -26,6 +28,18 @@ func resource() *schema.Resource {
2628
Required: true,
2729
Description: "file to read template from",
2830
ForceNew: true,
31+
// Make a "best effort" attempt to relativize the file path.
32+
StateFunc: func(v interface{}) string {
33+
pwd, err := os.Getwd()
34+
if err != nil {
35+
return v.(string)
36+
}
37+
rel, err := filepath.Rel(pwd, v.(string))
38+
if err != nil {
39+
return v.(string)
40+
}
41+
return rel
42+
},
2943
},
3044
"vars": &schema.Schema{
3145
Type: schema.TypeMap,

0 commit comments

Comments
 (0)