From 2d5d9b41d867540facc90dad6f37c6782e642220 Mon Sep 17 00:00:00 2001 From: Manuel Vogel Date: Fri, 14 May 2021 09:16:00 +0200 Subject: [PATCH] docs: add plugin resource generation --- docs/resources/plugin.md | 42 +++++++++++++++---- examples/resources/docker_plugin/import.sh | 2 + examples/resources/docker_plugin/resource.tf | 16 ++++++++ internal/provider/resource_docker_plugin.go | 43 ++++++++++++-------- 4 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 examples/resources/docker_plugin/import.sh create mode 100644 examples/resources/docker_plugin/resource.tf diff --git a/docs/resources/plugin.md b/docs/resources/plugin.md index 7c7fc571..2269b949 100644 --- a/docs/resources/plugin.md +++ b/docs/resources/plugin.md @@ -3,14 +3,33 @@ page_title: "docker_plugin Resource - terraform-provider-docker" subcategory: "" description: |- - + Manages the lifecycle of a Docker plugin. --- # docker_plugin (Resource) +Manages the lifecycle of a Docker plugin. +## Example Usage +```terraform +resource "docker_plugin" "sample-volume-plugin" { + name = "docker.io/tiborvass/sample-volume-plugin:latest" +} +resource "docker_plugin" "sample-volume-plugin" { + name = "tiborvass/sample-volume-plugin" + alias = "sample-volume-plugin" + enabled = false + grant_all_permissions = true + force_destroy = true + enable_timeout = 60 + force_disable = true + env = [ + "DEBUG=1" + ] +} +``` ## Schema @@ -23,12 +42,12 @@ description: |- - **alias** (String) Docker Plugin alias - **enable_timeout** (Number) HTTP client timeout to enable the plugin -- **enabled** (Boolean) -- **env** (Set of String) -- **force_destroy** (Boolean) -- **force_disable** (Boolean) If true, then the plugin is disabled forcibly when the plugin is disabled +- **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` +- **force_destroy** (Boolean) If true, then the plugin is destroyed forcibly +- **force_disable** (Boolean) If true, then the plugin is disabled forcibly - **grant_all_permissions** (Boolean) If true, grant all permissions necessary to run the plugin -- **grant_permissions** (Block Set) (see [below for nested schema](#nestedblock--grant_permissions)) +- **grant_permissions** (Block Set) Grant specific permissions only (see [below for nested schema](#nestedblock--grant_permissions)) - **id** (String) The ID of this resource. ### Read-Only @@ -40,7 +59,14 @@ description: |- Required: -- **name** (String) -- **value** (Set of String) +- **name** (String) The name of the permission +- **value** (Set of String) The value of the permission +## Import +Import is supported using the following syntax: + +```shell +#!/bin/bash +terraform import docker_plugin.sample-volume-plugin "$(docker plugin inspect -f "{{.ID}}" tiborvass/sample-volume-plugin:latest)" +``` diff --git a/examples/resources/docker_plugin/import.sh b/examples/resources/docker_plugin/import.sh new file mode 100644 index 00000000..742575e7 --- /dev/null +++ b/examples/resources/docker_plugin/import.sh @@ -0,0 +1,2 @@ +#!/bin/bash +terraform import docker_plugin.sample-volume-plugin "$(docker plugin inspect -f "{{.ID}}" tiborvass/sample-volume-plugin:latest)" \ No newline at end of file diff --git a/examples/resources/docker_plugin/resource.tf b/examples/resources/docker_plugin/resource.tf new file mode 100644 index 00000000..f0e6f461 --- /dev/null +++ b/examples/resources/docker_plugin/resource.tf @@ -0,0 +1,16 @@ +resource "docker_plugin" "sample-volume-plugin" { + name = "docker.io/tiborvass/sample-volume-plugin:latest" +} + +resource "docker_plugin" "sample-volume-plugin" { + name = "tiborvass/sample-volume-plugin" + alias = "sample-volume-plugin" + enabled = false + grant_all_permissions = true + force_destroy = true + enable_timeout = 60 + force_disable = true + env = [ + "DEBUG=1" + ] +} diff --git a/internal/provider/resource_docker_plugin.go b/internal/provider/resource_docker_plugin.go index 09fbbde2..0aefe061 100644 --- a/internal/provider/resource_docker_plugin.go +++ b/internal/provider/resource_docker_plugin.go @@ -6,6 +6,8 @@ import ( func resourceDockerPlugin() *schema.Resource { return &schema.Resource{ + Description: "Manages the lifecycle of a Docker plugin.", + Create: resourceDockerPluginCreate, Read: resourceDockerPluginRead, Update: resourceDockerPluginUpdate, @@ -13,29 +15,31 @@ func resourceDockerPlugin() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, + Description: "Docker Plugin name", Required: true, ForceNew: true, - Description: "Docker Plugin name", DiffSuppressFunc: diffSuppressFuncPluginName, ValidateFunc: validateFuncPluginName, }, "alias": { Type: schema.TypeString, + Description: "Docker Plugin alias", Computed: true, Optional: true, ForceNew: true, - Description: "Docker Plugin alias", DiffSuppressFunc: func(k, oldV, newV string, d *schema.ResourceData) bool { return complementTag(oldV) == complementTag(newV) }, }, "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: true, + Type: schema.TypeBool, + Description: "If `true` the plugin is enabled", + Optional: true, + Default: true, }, "grant_all_permissions": { Type: schema.TypeBool, @@ -45,18 +49,21 @@ func resourceDockerPlugin() *schema.Resource { }, "grant_permissions": { Type: schema.TypeSet, + Description: "Grant specific permissions only", Optional: true, ConflictsWith: []string{"grant_all_permissions"}, Set: dockerPluginGrantPermissionsSetFunc, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Description: "The name of the permission", + Required: true, }, "value": { - Type: schema.TypeSet, - Required: true, + Type: schema.TypeSet, + Description: "The value of the permission", + Required: true, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -65,10 +72,11 @@ func resourceDockerPlugin() *schema.Resource { }, }, "env": { - Type: schema.TypeSet, - Optional: true, - 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`", + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, }, "plugin_reference": { Type: schema.TypeString, @@ -77,18 +85,19 @@ func resourceDockerPlugin() *schema.Resource { }, "force_destroy": { - Type: schema.TypeBool, - Optional: true, + Type: schema.TypeBool, + Description: "If true, then the plugin is destroyed forcibly", + Optional: true, }, "enable_timeout": { Type: schema.TypeInt, - Optional: true, Description: "HTTP client timeout to enable the plugin", + Optional: true, }, "force_disable": { Type: schema.TypeBool, + Description: "If true, then the plugin is disabled forcibly", Optional: true, - Description: "If true, then the plugin is disabled forcibly when the plugin is disabled", }, }, }