From 00ee4507f9c67a7bc67322d48087b4c606ee6796 Mon Sep 17 00:00:00 2001 From: Manuel Vogel Date: Fri, 14 May 2021 08:48:05 +0200 Subject: [PATCH] docs: add plugin data source generation --- docs/data-sources/plugin.md | 20 +++++++++----- .../data-sources/docker_plugin/data-source.tf | 3 +++ .../provider/data_source_docker_plugin.go | 27 +++++++++++-------- 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 examples/data-sources/docker_plugin/data-source.tf diff --git a/docs/data-sources/plugin.md b/docs/data-sources/plugin.md index c13a8dfc..a66c260c 100644 --- a/docs/data-sources/plugin.md +++ b/docs/data-sources/plugin.md @@ -3,29 +3,35 @@ page_title: "docker_plugin Data Source - terraform-provider-docker" subcategory: "" description: |- - + Reads the local Docker plugin. The plugin must be installed locally. --- # docker_plugin (Data Source) +Reads the local Docker plugin. The plugin must be installed locally. +## Example Usage - +```terraform +data "docker_plugin" "sample-volume-plugin" { + alias = "sample-volume-plugin:latest" +} +``` ## Schema ### Optional -- **alias** (String) Docker Plugin alias +- **alias** (String) The alias of the Docker plugin. If the tag is omitted, `:latest` is complemented to the attribute value. - **id** (String) The ID of this resource. -- **name** (String) +- **name** (String) The plugin name. If the tag is omitted, `:latest` is complemented to the attribute value. ### Read-Only -- **enabled** (Boolean) -- **env** (Set of String) +- **enabled** (Boolean) If `true` the plugin is enabled +- **env** (Set of String) The environment variables in the from of `KEY=VALUE`, e.g. `DEBUG=0` - **grant_all_permissions** (Boolean) If true, grant all permissions necessary to run the plugin -- **plugin_reference** (String) Docker Plugin Reference +- **plugin_reference** (String) The Docker Plugin Reference diff --git a/examples/data-sources/docker_plugin/data-source.tf b/examples/data-sources/docker_plugin/data-source.tf new file mode 100644 index 00000000..791235af --- /dev/null +++ b/examples/data-sources/docker_plugin/data-source.tf @@ -0,0 +1,3 @@ +data "docker_plugin" "sample-volume-plugin" { + alias = "sample-volume-plugin:latest" +} \ No newline at end of file diff --git a/internal/provider/data_source_docker_plugin.go b/internal/provider/data_source_docker_plugin.go index f74dd474..5d3f3763 100644 --- a/internal/provider/data_source_docker_plugin.go +++ b/internal/provider/data_source_docker_plugin.go @@ -10,6 +10,8 @@ import ( func dataSourceDockerPlugin() *schema.Resource { return &schema.Resource{ + Description: "Reads the local Docker plugin. The plugin must be installed locally.", + Read: dataSourceDockerPluginRead, Schema: map[string]*schema.Schema{ @@ -18,38 +20,41 @@ func dataSourceDockerPlugin() *schema.Resource { Optional: true, }, "name": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Description: "The plugin name. If the tag is omitted, `:latest` is complemented to the attribute value.", + Optional: true, }, "alias": { Type: schema.TypeString, + Description: "The alias of the Docker plugin. If the tag is omitted, `:latest` is complemented to the attribute value.", Optional: true, - Description: "Docker Plugin alias", }, "plugin_reference": { Type: schema.TypeString, - Description: "Docker Plugin Reference", + Description: "The Docker Plugin Reference", Computed: true, }, "enabled": { - Type: schema.TypeBool, - Computed: true, + Type: schema.TypeBool, + Description: "If `true` the plugin is enabled", + Computed: true, }, "grant_all_permissions": { Type: schema.TypeBool, - Computed: true, Description: "If true, grant all permissions necessary to run the plugin", + Computed: true, }, "env": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeSet, + Description: "The environment variables in the from of `KEY=VALUE`, e.g. `DEBUG=0`", + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, }, }, } } -var errDataSourceKeyIsMissing = errors.New("One of id or alias must be assigned") +var errDataSourceKeyIsMissing = errors.New("one of id or alias must be assigned") func getDataSourcePluginKey(d *schema.ResourceData) (string, error) { id, idOK := d.GetOk("id")