mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-13 10:01:08 -04:00
* "external" provider for gluing in external logic This provider will become a bit of glue to help people interface external programs with Terraform without writing a full Terraform provider. It will be nowhere near as capable as a first-class provider, but is intended as a light-touch way to integrate some pre-existing or custom system into Terraform. * Unit test for the "resourceProvider" utility function This small function determines the dependable name of a provider for a given resource name and optional provider alias. It's simple but it's a key part of how resource nodes get connected to provider nodes so worth specifying the intended behavior in the form of a test. * Allow a provider to export a resource with the provider's name If a provider only implements one resource of each type (managed vs. data) then it can be reasonable for the resource names to exactly match the provider name, if the provider name is descriptive enough for the purpose of the each resource to be obvious. * provider/external: data source A data source that executes a child process, expecting it to support a particular gateway protocol, and exports its result. This can be used as a straightforward way to retrieve data from sources that Terraform doesn't natively support.. * website: documentation for the "external" provider
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
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)
|
|
}
|