diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/terraform/plugin/serve.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/plugin/serve.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/plugin/serve.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/plugin/serve.go b/vendor/github.com/hashicorp/terraform/plugin/serve.go new file mode 100644 index 0000000..2028a61 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/plugin/serve.go | |||
@@ -0,0 +1,54 @@ | |||
1 | package plugin | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/go-plugin" | ||
5 | "github.com/hashicorp/terraform/terraform" | ||
6 | ) | ||
7 | |||
8 | // The constants below are the names of the plugins that can be dispensed | ||
9 | // from the plugin server. | ||
10 | const ( | ||
11 | ProviderPluginName = "provider" | ||
12 | ProvisionerPluginName = "provisioner" | ||
13 | ) | ||
14 | |||
15 | // Handshake is the HandshakeConfig used to configure clients and servers. | ||
16 | var Handshake = plugin.HandshakeConfig{ | ||
17 | // The ProtocolVersion is the version that must match between TF core | ||
18 | // and TF plugins. This should be bumped whenever a change happens in | ||
19 | // one or the other that makes it so that they can't safely communicate. | ||
20 | // This could be adding a new interface value, it could be how | ||
21 | // helper/schema computes diffs, etc. | ||
22 | ProtocolVersion: 4, | ||
23 | |||
24 | // The magic cookie values should NEVER be changed. | ||
25 | MagicCookieKey: "TF_PLUGIN_MAGIC_COOKIE", | ||
26 | MagicCookieValue: "d602bf8f470bc67ca7faa0386276bbdd4330efaf76d1a219cb4d6991ca9872b2", | ||
27 | } | ||
28 | |||
29 | type ProviderFunc func() terraform.ResourceProvider | ||
30 | type ProvisionerFunc func() terraform.ResourceProvisioner | ||
31 | |||
32 | // ServeOpts are the configurations to serve a plugin. | ||
33 | type ServeOpts struct { | ||
34 | ProviderFunc ProviderFunc | ||
35 | ProvisionerFunc ProvisionerFunc | ||
36 | } | ||
37 | |||
38 | // Serve serves a plugin. This function never returns and should be the final | ||
39 | // function called in the main function of the plugin. | ||
40 | func Serve(opts *ServeOpts) { | ||
41 | plugin.Serve(&plugin.ServeConfig{ | ||
42 | HandshakeConfig: Handshake, | ||
43 | Plugins: pluginMap(opts), | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | // pluginMap returns the map[string]plugin.Plugin to use for configuring a plugin | ||
48 | // server or client. | ||
49 | func pluginMap(opts *ServeOpts) map[string]plugin.Plugin { | ||
50 | return map[string]plugin.Plugin{ | ||
51 | "provider": &ResourceProviderPlugin{F: opts.ProviderFunc}, | ||
52 | "provisioner": &ResourceProvisionerPlugin{F: opts.ProvisionerFunc}, | ||
53 | } | ||
54 | } | ||