forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (42 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
// This is a minimal implementation of the external data source protocol
// intended only for use in the provider acceptance tests.
//
// In practice it's likely not much harder to just write a real Terraform
// plugin if you're going to be writing your data source in Go anyway;
// this example is just in Go because we want to avoid introducing
// additional language runtimes into the test environment.
func main() {
queryBytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
var query map[string]string
err = json.Unmarshal(queryBytes, &query)
if err != nil {
panic(err)
}
if query["fail"] != "" {
fmt.Fprintf(os.Stderr, "I was asked to fail\n")
os.Exit(1)
}
var result = map[string]string{
"result": "yes",
"query_value": query["value"],
}
if len(os.Args) >= 2 {
result["argument"] = os.Args[1]
}
resultBytes, err := json.Marshal(result)
if err != nil {
panic(err)
}
os.Stdout.Write(resultBytes)
os.Exit(0)
}