terraform-provider-docker/internal/provider/resource_docker_registry_image.go
Manuel Vogel ad3e56da2b
feat: migrate to terraform-sdk v2 (#102)
* chore: runs v2 upgrade cmd
* chore: moves all files into the internal provider dir
* feat: migrates main and provider
* fix: migrates tests to provider factories
* fix: replace import state passthrough ctx func
* chore: bump tf-sdk to v2.4.4
* fix: acc test by adding stop grace period
* fix: move to validate diag functions
* test: switch from ctx TODO to Background
* feat: add state upgrade for restart_policy and auth

Co-authored-by: Shunsuke Suzuki <suzuki-shunsuke@users.noreply.github.com>
2021-03-18 08:30:54 +01:00

281 lines
6.4 KiB
Go

package provider
import (
"os"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceDockerRegistryImage() *schema.Resource {
return &schema.Resource{
CreateContext: resourceDockerRegistryImageCreate,
ReadContext: resourceDockerRegistryImageRead,
DeleteContext: resourceDockerRegistryImageDelete,
UpdateContext: resourceDockerRegistryImageUpdate,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"keep_remotely": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"build": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"suppress_output": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"remote_context": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"no_cache": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"remove": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"force_remove": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"pull_parent": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"isolation": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"cpu_set_cpus": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"cpu_set_mems": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"cpu_shares": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"cpu_quota": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"cpu_period": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"memory": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"memory_swap": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"cgroup_parent": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"network_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"shm_size": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"dockerfile": {
Type: schema.TypeString,
Optional: true,
Default: "Dockerfile",
ForceNew: true,
},
"ulimit": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"hard": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"soft": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
},
},
},
"build_args": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"auth_config": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"host_name": {
Type: schema.TypeString,
Required: true,
},
"user_name": {
Type: schema.TypeString,
Optional: true,
},
"password": {
Type: schema.TypeString,
Optional: true,
},
"auth": {
Type: schema.TypeString,
Optional: true,
},
"email": {
Type: schema.TypeString,
Optional: true,
},
"server_address": {
Type: schema.TypeString,
Optional: true,
},
"identity_token": {
Type: schema.TypeString,
Optional: true,
},
"registry_token": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"context": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: func(val interface{}) string {
// the context hash is stored to identify changes in the context files
dockerContextTarPath, _ := buildDockerImageContextTar(val.(string))
defer os.Remove(dockerContextTarPath)
contextTarHash, _ := getDockerImageContextTarHash(dockerContextTarPath)
return val.(string) + ":" + contextTarHash
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"squash": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"cache_from": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"security_opt": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"extra_hosts": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"target": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"session_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"platform": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"build_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
"sha256_digest": {
Type: schema.TypeString,
Computed: true,
},
},
}
}