mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-18 23:06:10 -05:00
Some checks failed
Acc Tests / acc-test (TestAccDockerConfig, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerConfig, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerNetwork, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerNetwork, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerPlugin, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerPlugin, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerSecret, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerSecret, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerTag, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerTag, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerVolume, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (TestAccDockerVolume, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerContainer, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerContainer, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerImage, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerImage, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerRegistryImage, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerRegistryImage, 1.8.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerService, 0.15.x) (push) Has been cancelled
Acc Tests / acc-test (true, TestAccDockerService, 1.8.x) (push) Has been cancelled
Compile Binaries / compile-fast (push) Has been cancelled
Compile Binaries / compile (push) Has been cancelled
golangci-lint / lint (push) Has been cancelled
Unit Tests / unit-test (push) Has been cancelled
Website Checks / markdown-link-check (push) Has been cancelled
Docs and Website Lint / website-generation (push) Has been cancelled
Docs and Website Lint / website-lint-spellcheck-tffmt (push) Has been cancelled
Docs and Website Lint / markdown-lint (push) Has been cancelled
91 lines
2.5 KiB
Go
91 lines
2.5 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
)
|
|
|
|
func dataSourceDockerPlugin() *schema.Resource {
|
|
return &schema.Resource{
|
|
Description: "Reads the local Docker plugin. The plugin must be installed locally.",
|
|
|
|
ReadContext: dataSourceDockerPluginRead,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"id": {
|
|
Type: schema.TypeString,
|
|
Description: "The ID of the plugin, which has precedence over the `alias` of both are given",
|
|
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,
|
|
},
|
|
"name": {
|
|
Type: schema.TypeString,
|
|
Description: "The plugin name. If the tag is omitted, `:latest` is complemented to the attribute value.",
|
|
Computed: true,
|
|
},
|
|
"plugin_reference": {
|
|
Type: schema.TypeString,
|
|
Description: "The Docker Plugin Reference",
|
|
Computed: true,
|
|
},
|
|
"enabled": {
|
|
Type: schema.TypeBool,
|
|
Description: "If `true` the plugin is enabled",
|
|
Computed: true,
|
|
},
|
|
"grant_all_permissions": {
|
|
Type: schema.TypeBool,
|
|
Description: "If true, grant all permissions necessary to run the plugin",
|
|
Computed: true,
|
|
},
|
|
"env": {
|
|
Type: schema.TypeSet,
|
|
Description: "The environment variables in the form 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")
|
|
|
|
func getDataSourcePluginKey(d *schema.ResourceData) (string, error) {
|
|
id, idOK := d.GetOk("id")
|
|
alias, aliasOK := d.GetOk("alias")
|
|
if idOK {
|
|
if aliasOK {
|
|
return "", errDataSourceKeyIsMissing
|
|
}
|
|
return id.(string), nil
|
|
}
|
|
if aliasOK {
|
|
return alias.(string), nil
|
|
}
|
|
return "", errDataSourceKeyIsMissing
|
|
}
|
|
|
|
func dataSourceDockerPluginRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
|
|
key, err := getDataSourcePluginKey(d)
|
|
if err != nil {
|
|
return diag.FromErr(err)
|
|
}
|
|
client, err := meta.(*ProviderConfig).MakeClient(ctx, d)
|
|
if err != nil {
|
|
return diag.Errorf("failed to create Docker client: %v", err)
|
|
}
|
|
plugin, _, err := client.PluginInspectWithRaw(ctx, key)
|
|
if err != nil {
|
|
return diag.Errorf("inspect a Docker plugin "+key+": %w", err)
|
|
}
|
|
|
|
setDockerPlugin(d, plugin)
|
|
return nil
|
|
}
|