mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #2038 from hashicorp/b-template-rel-path
provider/template: store relative path in state
This commit is contained in:
commit
3e79ca4408
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user