2021-03-18 03:30:54 -04:00
package provider
2020-03-24 10:34:14 -04:00
import (
"os"
2021-03-18 03:30:54 -04:00
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2020-03-24 10:34:14 -04:00
)
func resourceDockerRegistryImage ( ) * schema . Resource {
return & schema . Resource {
2021-05-21 08:30:56 -04:00
Description : "Manages the lifecycle of docker image/tag in a registry." ,
2021-03-18 03:30:54 -04:00
CreateContext : resourceDockerRegistryImageCreate ,
ReadContext : resourceDockerRegistryImageRead ,
DeleteContext : resourceDockerRegistryImageDelete ,
UpdateContext : resourceDockerRegistryImageUpdate ,
2020-03-24 10:34:14 -04:00
Schema : map [ string ] * schema . Schema {
"name" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The name of the Docker image." ,
Required : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
"keep_remotely" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "If true, then the Docker image won't be deleted on destroy operation. If this is false, it will delete the image from the docker registry on destroy operation. Defaults to `false`" ,
Default : false ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2021-05-31 03:11:49 -04:00
"insecure_skip_verify" : {
Type : schema . TypeBool ,
Description : "If `true`, the verification of TLS certificates of the server/registry is disabled. Defaults to `false`" ,
Optional : true ,
Default : false ,
} ,
2020-12-02 06:06:39 -05:00
"build" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "Definition for building the image" ,
Optional : true ,
MaxItems : 1 ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2020-12-02 06:06:39 -05:00
"suppress_output" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "Suppress the build output and print image ID on success" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"remote_context" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "A Git repository URI or HTTP/HTTPS context URI" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"no_cache" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "Do not use the cache when building the image" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"remove" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "Remove intermediate containers after a successful build (default behavior)" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"force_remove" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "Always remove intermediate containers" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"pull_parent" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "Attempt to pull the image even if an older image exists locally" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"isolation" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Isolation represents the isolation technology of a container. The supported values are " ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cpu_set_cpus" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "CPUs in which to allow execution (e.g., `0-3`, `0`, `1`)" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cpu_set_mems" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "MEMs in which to allow execution (`0-3`, `0`, `1`)" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cpu_shares" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "CPU shares (relative weight)" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cpu_quota" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "Microseconds of CPU time that the container can get in a CPU period" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cpu_period" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "The length of a CPU period in microseconds" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"memory" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "Set memory limit for build" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"memory_swap" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "Total memory (memory + swap), -1 to enable unlimited swap" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cgroup_parent" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Optional parent cgroup for the container" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"network_mode" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Set the networking mode for the RUN instructions during build" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"shm_size" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "Size of /dev/shm in bytes. The size must be greater than 0" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"dockerfile" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Dockerfile file. Defaults to `Dockerfile`" ,
Default : "Dockerfile" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"ulimit" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "Configuration for ulimits" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2020-12-02 06:06:39 -05:00
"name" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "type of ulimit, e.g. `nofile`" ,
Required : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"hard" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "soft limit" ,
Required : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"soft" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeInt ,
Description : "hard limit" ,
Required : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
} ,
} ,
} ,
2020-12-02 06:06:39 -05:00
"build_args" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeMap ,
Description : "Pairs for build-time variables in the form TODO" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Schema {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The argument" ,
2020-03-24 10:34:14 -04:00
} ,
} ,
2020-12-02 06:06:39 -05:00
"auth_config" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "The configuration for the autentication" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2020-12-02 06:06:39 -05:00
"host_name" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "hostname of the registry" ,
Required : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"user_name" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the registry user name" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"password" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the registry password" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"auth" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the auth token" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"email" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the user emal" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"server_address" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the server address" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"identity_token" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the identity token" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"registry_token" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "the registry token" ,
Optional : true ,
2020-03-24 10:34:14 -04:00
} ,
} ,
} ,
} ,
2020-12-02 06:06:39 -05:00
"context" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
2021-07-09 03:04:43 -04:00
Description : "The absolute path to the context folder. You can use the helper function '${path.cwd}/context-dir'." ,
2021-05-21 08:30:56 -04:00
Required : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
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
} ,
} ,
2020-12-02 06:06:39 -05:00
"labels" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeMap ,
Description : "User-defined key/value metadata" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Schema {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The key/value pair" ,
2020-03-24 10:34:14 -04:00
} ,
} ,
2020-12-02 06:06:39 -05:00
"squash" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeBool ,
Description : "If true the new layers are squashed into a new image with a single new layer" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"cache_from" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "Images to consider as cache sources" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Schema {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The image" ,
2020-03-24 10:34:14 -04:00
} ,
} ,
2020-12-02 06:06:39 -05:00
"security_opt" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "The security options" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Schema {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The option" ,
2020-03-24 10:34:14 -04:00
} ,
} ,
2020-12-02 06:06:39 -05:00
"extra_hosts" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeList ,
Description : "A list of hostnames/IP mappings to add to the container’ s /etc/hosts file. Specified in the form [\"hostname:IP\"]" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
Elem : & schema . Schema {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "" ,
2020-03-24 10:34:14 -04:00
} ,
} ,
2020-12-02 06:06:39 -05:00
"target" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Set the target build stage to build" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"session_id" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Set an ID for the build session" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"platform" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Set platform if server is multi-platform capable" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"version" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "Version of the unerlying builder to use" ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
2020-12-02 06:06:39 -05:00
"build_id" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "BuildID is an optional identifier that can be passed together with the build request. The " ,
Optional : true ,
ForceNew : true ,
2020-03-24 10:34:14 -04:00
} ,
} ,
} ,
} ,
"sha256_digest" : {
2021-05-21 08:30:56 -04:00
Type : schema . TypeString ,
Description : "The sha256 digest of the image." ,
Computed : true ,
2020-03-24 10:34:14 -04:00
} ,
} ,
}
}