Skip to content

Commit

Permalink
Merge pull request #2038 from hashicorp/b-template-rel-path
Browse files Browse the repository at this point in the history
provider/template: store relative path in state
  • Loading branch information
phinze committed May 21, 2015
2 parents 46fa67e + 06eb388 commit 3e79ca4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions builtin/providers/template/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config/lang"
Expand All @@ -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,
Expand Down

0 comments on commit 3e79ca4

Please sign in to comment.