github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/concepts/plugins/base.mdx (about) 1 --- 2 layout: docs 3 page_title: Base Plugin 4 description: Learn about how to author a Nomad plugin. 5 --- 6 7 # Base Plugin 8 9 The base plugin is a special plugin type implemented by all plugins. It allows 10 for common plugin operations such as defining a configuration schema and 11 version information. 12 13 ## Plugin API 14 15 #### `PluginInfo() (*PluginInfoResponse, error)` 16 17 A `PluginInfoResponse` contains meta data about the plugin. 18 19 ```go 20 PluginInfoResponse{ 21 // Type is the plugin type which is implemented 22 Type: PluginTypeDriver, 23 // Plugin API versions supported by the plugin 24 PluginApiVersions: []string{drivers.ApiVersion010}, 25 // Version of the plugin 26 PluginVersion: "0.1.0", 27 // Name of the plugin 28 Name: "foodriver", 29 } 30 ``` 31 32 #### `ConfigSchema() (*hclspec.Spec, error)` 33 34 The `ConfigSchema` function allows a plugin to tell Nomad the schema for its 35 configuration. This configuration is given in a [plugin block][pluginblock] of 36 the client configuration. The schema is defined with the [hclspec][hclspec] 37 package. 38 39 #### `SetConfig(config *Config) error` 40 41 The `SetConfig` function is called when starting the plugin for the first 42 time. The `Config` given has two different configuration fields. The first 43 `PluginConfig`, is an encoded configuration from the `plugin` block of the 44 client config. The second, `AgentConfig`, is the Nomad agent's configuration 45 which is given to all plugins. 46 47 ## HCL Specifications 48 49 `*hclspec.Spec` is a struct that defines the schema to validate an HCL entity 50 against. The full documentation of the different hcl attribute types can be 51 found on the [hclspec godoc][hclspec]. 52 53 For a basic example, lets look at the driver configuration for the raw_exec 54 driver: 55 56 ```hcl 57 job "example" { 58 ... 59 driver = "raw_exec" 60 config { 61 command = "/bin/sleep" 62 args = ["100"] 63 } 64 } 65 ``` 66 67 The `config` block is what is validated against the `hclspec.Spec`. It has two 68 keys, command which takes a string attribute and args which takes an array 69 attribute. The corresponding `*hclspec.Spec` would be: 70 71 ```go 72 spec := hclspec.NewObject(map[string]*hclspec.Spec{ 73 "command": hclspec.NewAttr("command", "string", true), 74 "args": hclspec.NewAttr("args", "list(string)", false), 75 }) 76 ``` 77 78 [hclspec]: https://godoc.org/github.com/hashicorp/nomad/plugins/shared/hclspec 79 [pluginblock]: /docs/configuration/plugin