2015-02-17 11:28:33 -05:00
package docker
import (
2019-03-05 09:55:17 -05:00
"log"
2019-10-09 14:25:38 -04:00
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
2015-02-17 11:28:33 -05:00
)
func resourceDockerContainer ( ) * schema . Resource {
return & schema . Resource {
2019-03-05 09:55:17 -05:00
Create : resourceDockerContainerCreate ,
Read : resourceDockerContainerRead ,
Update : resourceDockerContainerUpdate ,
Delete : resourceDockerContainerDelete ,
MigrateState : resourceDockerContainerMigrateState ,
2019-11-14 17:10:48 -05:00
SchemaVersion : 2 ,
2019-11-23 08:42:05 -05:00
Importer : & schema . ResourceImporter {
State : schema . ImportStatePassthrough ,
} ,
2019-11-14 17:10:48 -05:00
StateUpgraders : [ ] schema . StateUpgrader {
{
Version : 1 ,
Type : resourceDockerContainerV1 ( ) . CoreConfigSchema ( ) . ImpliedType ( ) ,
Upgrade : func ( rawState map [ string ] interface { } , meta interface { } ) ( map [ string ] interface { } , error ) {
2019-11-14 17:44:58 -05:00
//TODO do the ohter V0-to-V1 migration, unless we're okay
//with breaking for users who straggled on their docker
//provider version
2019-11-14 17:10:48 -05:00
2019-11-14 17:44:58 -05:00
return migrateContainerLabels ( rawState ) , nil
2019-11-14 17:10:48 -05:00
} ,
} ,
} ,
2015-02-17 11:28:33 -05:00
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"name" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"rm" : {
2018-10-25 02:01:38 -04:00
Type : schema . TypeBool ,
Default : false ,
Optional : true ,
} ,
2019-10-25 06:14:09 -04:00
"read_only" : {
Type : schema . TypeBool ,
Default : false ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"start" : {
2018-10-08 14:14:01 -04:00
Type : schema . TypeBool ,
Default : true ,
Optional : true ,
} ,
2019-03-01 16:02:17 -05:00
"attach" : {
2018-10-28 13:41:10 -04:00
Type : schema . TypeBool ,
Default : false ,
Optional : true ,
} ,
2019-03-01 16:02:17 -05:00
"logs" : {
2018-10-28 13:41:10 -04:00
Type : schema . TypeBool ,
Default : false ,
Optional : true ,
} ,
2015-02-17 11:28:33 -05:00
// Indicates whether the container must be running.
//
// An assumption is made that configured containers
// should be running; if not, they should not be in
// the configuration. Therefore a stopped container
// should be started. Set to false to have the
// provider leave the container alone.
//
// Actively-debugged containers are likely to be
// stopped and started manually, and Docker has
// some provisions for restarting containers that
// stop. The utility here comes from the fact that
// this will delete and re-create the container
// following the principle that the containers
// should be pristine when started.
2019-03-01 16:02:17 -05:00
"must_run" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeBool ,
Default : true ,
Optional : true ,
} ,
2019-03-01 16:02:17 -05:00
"exit_code" : {
2018-10-25 02:01:38 -04:00
Type : schema . TypeInt ,
Computed : true ,
} ,
2019-03-01 16:02:17 -05:00
"container_logs" : {
2018-10-28 13:41:10 -04:00
Type : schema . TypeString ,
Computed : true ,
} ,
2015-02-17 11:28:33 -05:00
// ForceNew is not true for image because we need to
// sane this against Docker image IDs, as each image
// can have multiple names/tags attached do it.
2019-03-01 16:02:17 -05:00
"image" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
2019-05-26 05:42:53 -04:00
// DiffSuppressFunc: suppressIfSHAwasAdded(), // TODO mvogel
2015-02-17 11:28:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"hostname" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2015-02-17 11:28:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"domainname" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"command" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeList ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2015-02-17 11:28:33 -05:00
Elem : & schema . Schema { Type : schema . TypeString } ,
} ,
2019-03-01 16:02:17 -05:00
"entrypoint" : {
2015-10-26 17:24:48 -04:00
Type : schema . TypeList ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2015-10-26 17:24:48 -04:00
Elem : & schema . Schema { Type : schema . TypeString } ,
} ,
2019-03-01 16:02:17 -05:00
"user" : {
2016-04-04 22:43:59 -04:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
} ,
2019-03-01 16:02:17 -05:00
"dns" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
2016-02-07 18:51:26 -05:00
Set : schema . HashString ,
2015-02-17 11:28:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"dns_opts" : {
2016-06-29 08:38:46 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
2019-03-01 16:02:17 -05:00
"dns_search" : {
2016-06-29 08:38:46 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
2019-03-01 16:02:17 -05:00
"publish_all_ports" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeBool ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"restart" : {
2018-01-29 06:01:46 -05:00
Type : schema . TypeString ,
Optional : true ,
Default : "no" ,
ValidateFunc : validateStringMatchesPattern ( ` ^(no|on-failure|always|unless-stopped)$ ` ) ,
2015-10-27 12:08:57 -04:00
} ,
2019-03-01 16:02:17 -05:00
"max_retry_count" : {
2015-10-27 12:08:57 -04:00
Type : schema . TypeInt ,
Optional : true ,
} ,
2020-02-01 10:15:36 -05:00
"working_dir" : {
2019-09-23 13:41:20 -04:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
2020-11-29 08:38:33 -05:00
DiffSuppressFunc : func ( k , oldV , newV string , d * schema . ResourceData ) bool {
// treat "" as a no-op, which is Docker's default behavior
if newV == "" {
newV = oldV
}
return oldV == newV
} ,
2019-09-23 13:41:20 -04:00
} ,
2020-10-11 09:25:20 -04:00
"remove_volumes" : {
Type : schema . TypeBool ,
Optional : true ,
Default : true ,
} ,
2019-03-01 16:02:17 -05:00
"capabilities" : {
2017-03-07 11:48:20 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
MaxItems : 1 ,
2020-02-01 10:15:36 -05:00
// TODO implement DiffSuppressFunc
2017-03-07 11:48:20 -05:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"add" : {
2017-03-07 11:48:20 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
2019-03-01 16:02:17 -05:00
"drop" : {
2017-03-07 11:48:20 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
} ,
} ,
} ,
2020-11-15 12:19:19 -05:00
"security_opts" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Computed : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Description : "List of string values to customize labels for MLS systems, such as SELinux. See https://docs.docker.com/engine/reference/run/#security-configuration" ,
Set : schema . HashString ,
} ,
2019-05-26 05:59:29 -04:00
"mounts" : {
Type : schema . TypeSet ,
Description : "Specification for mounts to be added to containers created as part of the service" ,
Optional : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"target" : {
Type : schema . TypeString ,
Description : "Container path" ,
Required : true ,
} ,
"source" : {
Type : schema . TypeString ,
Description : "Mount source (e.g. a volume name, a host path)" ,
Optional : true ,
} ,
"type" : {
Type : schema . TypeString ,
Description : "The mount type" ,
Required : true ,
ValidateFunc : validateStringMatchesPattern ( ` ^(bind|volume|tmpfs)$ ` ) ,
} ,
"read_only" : {
Type : schema . TypeBool ,
Description : "Whether the mount should be read-only" ,
Optional : true ,
} ,
"bind_options" : {
Type : schema . TypeList ,
Description : "Optional configuration for the bind type" ,
Optional : true ,
MaxItems : 1 ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"propagation" : {
Type : schema . TypeString ,
Description : "A propagation mode with the value" ,
Optional : true ,
ValidateFunc : validateStringMatchesPattern ( ` ^(private|rprivate|shared|rshared|slave|rslave)$ ` ) ,
} ,
} ,
} ,
} ,
"volume_options" : {
Type : schema . TypeList ,
Description : "Optional configuration for the volume type" ,
Optional : true ,
MaxItems : 1 ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"no_copy" : {
Type : schema . TypeBool ,
Description : "Populate volume with data from the target" ,
Optional : true ,
} ,
"labels" : {
2019-11-10 15:15:42 -05:00
Type : schema . TypeSet ,
2019-05-26 05:59:29 -04:00
Description : "User-defined key/value metadata" ,
Optional : true ,
2019-11-10 15:15:42 -05:00
Elem : labelSchema ,
2019-05-26 05:59:29 -04:00
} ,
"driver_name" : {
Type : schema . TypeString ,
Description : "Name of the driver to use to create the volume." ,
Optional : true ,
} ,
"driver_options" : {
Type : schema . TypeMap ,
Description : "key/value map of driver specific options" ,
Optional : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
} ,
} ,
} ,
} ,
"tmpfs_options" : {
Type : schema . TypeList ,
Description : "Optional configuration for the tmpfs type" ,
Optional : true ,
2020-02-01 10:15:36 -05:00
ForceNew : true ,
2019-05-26 05:59:29 -04:00
MaxItems : 1 ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"size_bytes" : {
Type : schema . TypeInt ,
Description : "The size for the tmpfs mount in bytes" ,
Optional : true ,
} ,
"mode" : {
Type : schema . TypeInt ,
Description : "The permission mode for the tmpfs mount in an integer" ,
Optional : true ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
2019-03-01 16:02:17 -05:00
"volumes" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
2015-12-03 05:51:59 -05:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"from_container" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"container_path" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"host_path" : {
2017-05-15 06:09:50 -04:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
ValidateFunc : validateDockerContainerPath ,
2016-01-15 16:59:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"volume_name" : {
2016-01-15 16:59:33 -05:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
2015-12-03 05:51:59 -05:00
} ,
2019-03-01 16:02:17 -05:00
"read_only" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeBool ,
Optional : true ,
ForceNew : true ,
} ,
} ,
} ,
2015-02-17 11:28:33 -05:00
} ,
2019-05-26 05:59:29 -04:00
"tmpfs" : {
Type : schema . TypeMap ,
Optional : true ,
} ,
2019-03-01 16:02:17 -05:00
"ports" : {
2018-10-16 12:49:57 -04:00
Type : schema . TypeList ,
2015-02-17 11:28:33 -05:00
Optional : true ,
ForceNew : true ,
2015-12-03 05:51:59 -05:00
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"internal" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeInt ,
Required : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"external" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeInt ,
Optional : true ,
2018-10-16 12:49:57 -04:00
Computed : true ,
2015-12-03 05:51:59 -05:00
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"ip" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeString ,
2018-10-09 16:32:26 -04:00
Default : "0.0.0.0" ,
2015-12-03 05:51:59 -05:00
Optional : true ,
ForceNew : true ,
2019-03-07 04:15:42 -05:00
StateFunc : func ( val interface { } ) string {
// Empty IP assignments default to 0.0.0.0
if val . ( string ) == "" {
return "0.0.0.0"
}
return val . ( string )
} ,
2015-12-03 05:51:59 -05:00
} ,
2019-03-01 16:02:17 -05:00
"protocol" : {
2015-12-03 05:51:59 -05:00
Type : schema . TypeString ,
Default : "tcp" ,
Optional : true ,
ForceNew : true ,
} ,
} ,
} ,
2019-03-05 09:55:17 -05:00
DiffSuppressFunc : suppressIfPortsDidNotChangeForMigrationV0ToV1 ( ) ,
2015-02-17 11:28:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"host" : {
2015-10-09 09:05:43 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"ip" : {
2015-10-09 09:05:43 -04:00
Type : schema . TypeString ,
2016-10-27 05:54:05 -04:00
Required : true ,
2015-10-09 09:05:43 -04:00
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"host" : {
2015-10-09 09:05:43 -04:00
Type : schema . TypeString ,
2016-10-27 05:54:05 -04:00
Required : true ,
2015-10-09 09:05:43 -04:00
ForceNew : true ,
2018-04-20 05:35:49 -04:00
} ,
} ,
} ,
} ,
2019-03-01 16:02:17 -05:00
"ulimit" : {
2018-04-20 05:35:49 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"name" : {
2018-04-20 05:35:49 -04:00
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"soft" : {
2018-04-20 05:35:49 -04:00
Type : schema . TypeInt ,
Required : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"hard" : {
2018-04-20 05:35:49 -04:00
Type : schema . TypeInt ,
Required : true ,
ForceNew : true ,
2015-10-09 09:05:43 -04:00
} ,
} ,
} ,
2015-02-17 11:28:33 -05:00
} ,
2019-03-01 16:02:17 -05:00
"env" : {
2015-02-17 11:28:33 -05:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2015-02-17 11:28:33 -05:00
Elem : & schema . Schema { Type : schema . TypeString } ,
2016-02-07 18:51:26 -05:00
Set : schema . HashString ,
2015-02-17 11:28:33 -05:00
} ,
2015-04-16 15:42:21 -04:00
2019-03-01 16:02:17 -05:00
"links" : {
2018-04-02 02:19:45 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
Deprecated : "The --link flag is a legacy feature of Docker. It may eventually be removed." ,
2015-04-16 15:42:21 -04:00
} ,
2015-04-16 09:21:14 -04:00
2019-03-01 16:02:17 -05:00
"ip_address" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeString ,
Computed : true ,
Deprecated : "Use ip_adresses_data instead. This field exposes the data of the container's first network." ,
2015-04-20 15:18:46 -04:00
} ,
2019-03-01 16:02:17 -05:00
"ip_prefix_length" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeInt ,
Computed : true ,
Deprecated : "Use ip_prefix_length from ip_adresses_data instead. This field exposes the data of the container's first network." ,
2015-04-20 15:18:46 -04:00
} ,
2019-03-01 16:02:17 -05:00
"gateway" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeString ,
Computed : true ,
Deprecated : "Use gateway from ip_adresses_data instead. This field exposes the data of the container's first network." ,
2015-04-20 15:18:46 -04:00
} ,
2019-03-01 16:02:17 -05:00
"bridge" : {
2015-04-20 15:18:46 -04:00
Type : schema . TypeString ,
Computed : true ,
} ,
2015-06-04 06:57:38 -04:00
2019-03-01 16:02:17 -05:00
"network_data" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeList ,
Computed : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"network_name" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeString ,
Computed : true ,
} ,
2019-03-01 16:02:17 -05:00
"ip_address" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeString ,
Computed : true ,
} ,
2019-03-01 16:02:17 -05:00
"ip_prefix_length" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeInt ,
Computed : true ,
} ,
2019-03-01 16:02:17 -05:00
"gateway" : {
2018-10-25 01:21:48 -04:00
Type : schema . TypeString ,
Computed : true ,
} ,
2020-05-01 22:29:59 -04:00
"global_ipv6_address" : {
Type : schema . TypeString ,
Computed : true ,
} ,
"global_ipv6_prefix_length" : {
Type : schema . TypeInt ,
Computed : true ,
} ,
"ipv6_gateway" : {
Type : schema . TypeString ,
Computed : true ,
} ,
2018-10-25 01:21:48 -04:00
} ,
} ,
} ,
2019-03-01 16:02:17 -05:00
"privileged" : {
2015-06-04 06:57:38 -04:00
Type : schema . TypeBool ,
Optional : true ,
ForceNew : true ,
} ,
2015-10-27 19:53:49 -04:00
2019-03-01 16:02:17 -05:00
"devices" : {
2018-04-20 05:14:44 -04:00
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
2019-03-01 16:02:17 -05:00
"host_path" : {
2018-04-20 05:14:44 -04:00
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"container_path" : {
2018-04-20 05:14:44 -04:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
2019-03-01 16:02:17 -05:00
"permissions" : {
2018-04-20 05:14:44 -04:00
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
} ,
} ,
} ,
2019-03-01 16:02:17 -05:00
"destroy_grace_seconds" : {
2016-07-11 11:03:02 -04:00
Type : schema . TypeInt ,
Optional : true ,
} ,
2019-03-01 16:02:17 -05:00
"labels" : {
2019-11-10 15:15:42 -05:00
Type : schema . TypeSet ,
2015-11-03 15:20:58 -05:00
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2019-11-10 15:15:42 -05:00
Elem : labelSchema ,
2015-11-03 15:20:58 -05:00
} ,
2019-03-01 16:02:17 -05:00
"memory" : {
2018-01-29 06:01:46 -05:00
Type : schema . TypeInt ,
Optional : true ,
ValidateFunc : validateIntegerGeqThan ( 0 ) ,
2015-10-27 19:53:49 -04:00
} ,
2019-03-01 16:02:17 -05:00
"memory_swap" : {
2018-01-29 06:01:46 -05:00
Type : schema . TypeInt ,
Optional : true ,
2019-11-14 17:10:48 -05:00
ValidateFunc : validateIntegerGeqThan ( - 1 ) ,
} ,
"shm_size" : {
Type : schema . TypeInt ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2019-11-14 17:10:48 -05:00
ValidateFunc : validateIntegerGeqThan ( 0 ) ,
} ,
"cpu_shares" : {
Type : schema . TypeInt ,
Optional : true ,
ValidateFunc : validateIntegerGeqThan ( 0 ) ,
} ,
"cpu_set" : {
Type : schema . TypeString ,
Optional : true ,
ValidateFunc : validateStringMatchesPattern ( ` ^\d+([,-]\d+)*$ ` ) ,
} ,
"log_driver" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
Default : "json-file" ,
} ,
"log_opts" : {
Type : schema . TypeMap ,
Optional : true ,
ForceNew : true ,
} ,
"network_alias" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
Description : "Set an alias for the container in all specified networks" ,
Deprecated : "Use networks_advanced instead. Will be removed in v2.0.0" ,
} ,
"network_mode" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
DiffSuppressFunc : func ( k , oldV , newV string , d * schema . ResourceData ) bool {
// treat "" as "default", which is Docker's default value
if oldV == "" {
oldV = "default"
}
if newV == "" {
newV = "default"
}
return oldV == newV
} ,
2019-11-14 17:10:48 -05:00
} ,
"networks" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
Deprecated : "Use networks_advanced instead. Will be removed in v2.0.0" ,
} ,
"networks_advanced" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"name" : {
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
} ,
"aliases" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
"ipv4_address" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
"ipv6_address" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
} ,
} ,
} ,
"pid_mode" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
"userns_mode" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
"upload" : {
Type : schema . TypeSet ,
Optional : true ,
ForceNew : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"content" : {
Type : schema . TypeString ,
Optional : true ,
// This is intentional. The container is mutated once, and never updated later.
// New configuration forces a new deployment, even with the same binaries.
ForceNew : true ,
} ,
"content_base64" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
ValidateFunc : validateStringIsBase64Encoded ( ) ,
} ,
"file" : {
Type : schema . TypeString ,
Required : true ,
ForceNew : true ,
} ,
"executable" : {
Type : schema . TypeBool ,
Optional : true ,
ForceNew : true ,
Default : false ,
} ,
2020-02-03 15:44:46 -05:00
"source" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
"source_hash" : {
Type : schema . TypeString ,
Optional : true ,
ForceNew : true ,
} ,
2019-11-14 17:10:48 -05:00
} ,
} ,
} ,
"healthcheck" : {
Type : schema . TypeList ,
Description : "A test to perform to check that the container is healthy" ,
MaxItems : 1 ,
Optional : true ,
Elem : & schema . Resource {
Schema : map [ string ] * schema . Schema {
"test" : {
Type : schema . TypeList ,
Description : "The test to perform as list" ,
Required : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
} ,
"interval" : {
Type : schema . TypeString ,
Description : "Time between running the check (ms|s|m|h)" ,
Optional : true ,
Default : "0s" ,
ValidateFunc : validateDurationGeq0 ( ) ,
} ,
"timeout" : {
Type : schema . TypeString ,
Description : "Maximum time to allow one check to run (ms|s|m|h)" ,
Optional : true ,
Default : "0s" ,
ValidateFunc : validateDurationGeq0 ( ) ,
} ,
"start_period" : {
Type : schema . TypeString ,
Description : "Start period for the container to initialize before counting retries towards unstable (ms|s|m|h)" ,
Optional : true ,
Default : "0s" ,
ValidateFunc : validateDurationGeq0 ( ) ,
} ,
"retries" : {
Type : schema . TypeInt ,
Description : "Consecutive failures needed to report unhealthy" ,
Optional : true ,
Default : 0 ,
ValidateFunc : validateIntegerGeqThan ( 0 ) ,
} ,
} ,
} ,
} ,
"sysctls" : {
Type : schema . TypeMap ,
Optional : true ,
ForceNew : true ,
} ,
"ipc_mode" : {
Type : schema . TypeString ,
Description : "IPC sharing mode for the container" ,
Optional : true ,
ForceNew : true ,
2020-02-01 10:15:36 -05:00
Computed : true ,
2019-11-14 17:10:48 -05:00
} ,
"group_add" : {
Type : schema . TypeSet ,
Description : "Additional groups for the container user" ,
2019-10-06 05:13:24 -04:00
Optional : true ,
ForceNew : true ,
Elem : & schema . Schema { Type : schema . TypeString } ,
Set : schema . HashString ,
} ,
2020-11-11 10:14:49 -05:00
"init" : {
Type : schema . TypeBool ,
Optional : true ,
Computed : true ,
} ,
2015-02-17 11:28:33 -05:00
} ,
}
}
2019-03-05 09:55:17 -05:00
func suppressIfPortsDidNotChangeForMigrationV0ToV1 ( ) schema . SchemaDiffSuppressFunc {
return func ( k , old , new string , d * schema . ResourceData ) bool {
2019-08-01 18:16:50 -04:00
if k == "ports.#" && old != new {
log . Printf ( "[DEBUG] suppress diff ports: old and new don't have the same length" )
return false
}
2019-03-05 09:55:17 -05:00
portsOldRaw , portsNewRaw := d . GetChange ( "ports" )
portsOld := portsOldRaw . ( [ ] interface { } )
portsNew := portsNewRaw . ( [ ] interface { } )
if len ( portsOld ) != len ( portsNew ) {
log . Printf ( "[DEBUG] suppress diff ports: old and new don't have the same length" )
return false
}
log . Printf ( "[DEBUG] suppress diff ports: old and new have same length" )
for _ , portOld := range portsOld {
portOldMapped := portOld . ( map [ string ] interface { } )
oldInternalPort := portOldMapped [ "internal" ]
portFound := false
for _ , portNew := range portsNew {
portNewMapped := portNew . ( map [ string ] interface { } )
newInternalPort := portNewMapped [ "internal" ]
// port is still there in new
if newInternalPort == oldInternalPort {
log . Printf ( "[DEBUG] suppress diff ports: comparing port '%v'" , oldInternalPort )
2020-08-02 12:27:43 -04:00
if portNewMapped [ "protocol" ] != portOldMapped [ "protocol" ] {
if containsPortWithProtocol ( portsNew , portOldMapped [ "internal" ] , portOldMapped [ "protocol" ] ) {
log . Printf ( "[DEBUG] suppress diff ports: found another port in new list with the same protocol for '%v" , oldInternalPort )
continue
}
log . Printf ( "[DEBUG] suppress diff ports: 'protocol' changed for '%v'" , oldInternalPort )
return false
}
2019-03-05 09:55:17 -05:00
if portNewMapped [ "external" ] != portOldMapped [ "external" ] {
log . Printf ( "[DEBUG] suppress diff ports: 'external' changed for '%v'" , oldInternalPort )
return false
}
if portNewMapped [ "ip" ] != portOldMapped [ "ip" ] {
log . Printf ( "[DEBUG] suppress diff ports: 'ip' changed for '%v'" , oldInternalPort )
return false
}
2020-08-02 12:27:43 -04:00
portFound = true
break
2019-03-05 09:55:17 -05:00
}
}
// port was deleted or exchanges in new
if ! portFound {
log . Printf ( "[DEBUG] suppress diff ports: port was deleted '%v'" , oldInternalPort )
return false
}
}
return true
}
}
2020-08-02 12:27:43 -04:00
func containsPortWithProtocol ( ports [ ] interface { } , searchInternalPort , searchProtocol interface { } ) bool {
for _ , port := range ports {
portMapped := port . ( map [ string ] interface { } )
internalPort := portMapped [ "internal" ]
protocol := portMapped [ "protocol" ]
if internalPort == searchInternalPort && protocol == searchProtocol {
return true
}
}
return false
}