Skip to content

Commit 497aaee

Browse files
authored
Feature: Multiple enhancements (#854)
* feat: Implement labels for docker config Based on #543 from @jani123 * feat: Implements timeouts for docker_container Thanks to PR #777 from @Strafo * chore: Fix spelling mistakes Thanks to #588 from @vszabo2
1 parent aaf6c38 commit 497aaee

21 files changed

+124
-43
lines changed

GNUmakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ chlog-%:
113113
@echo "Review the changes made by this script then execute the following:"
114114

115115

116-
replace-occurences-%:
117-
@echo "Replace occurences of old version strings..."
116+
replace-occurrences-%:
117+
@echo "Replace occurrences of old version strings..."
118118
sed -i "s/$(shell (svu --tag.prefix='' current))/$*/g" README.md docs/index.md examples/provider/provider-tf13.tf
119119

120120
release-%:
@@ -130,15 +130,15 @@ release-%:
130130

131131
patch:
132132
@${MAKE} chlog-$(shell (svu patch))
133-
@${MAKE} replace-occurences-$(shell (svu --tag.prefix='' patch))
133+
@${MAKE} replace-occurrences-$(shell (svu --tag.prefix='' patch))
134134
@${MAKE} release-$(shell (svu patch))
135135

136136
minor:
137137
@${MAKE} chlog-$(shell (svu minor))
138-
@${MAKE} replace-occurences-$(shell (svu --tag.prefix='' minor))
138+
@${MAKE} replace-occurrences-$(shell (svu --tag.prefix='' minor))
139139
@${MAKE} release-$(shell (svu minor))
140140

141141
major:
142142
@${MAKE} chlog-$(shell (svu major))
143-
@${MAKE} replace-occurences-$(shell (svu --tag.prefix='' major))
143+
@${MAKE} replace-occurrences-$(shell (svu --tag.prefix='' major))
144144
@${MAKE} release-$(shell (svu major))

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ provider "docker" {
5757
}
5858
```
5959

60-
When using a remote host, the daemon configuration on the remote host can apply default configuration to your resources when running `terraform apply`, for example by appling log options to containers. When running `terraform plan` the next time, it will show up as a diff. In such cases it is recommended to use the `ignore_changes` lifecycle meta-argument to ignore the changing attribute (See [this issue](https://github.com/kreuzwerker/terraform-provider-docker/issues/473) for more information).
60+
When using a remote host, the daemon configuration on the remote host can apply default configuration to your resources when running `terraform apply`, for example by applying log options to containers. When running `terraform plan` the next time, it will show up as a diff. In such cases it is recommended to use the `ignore_changes` lifecycle meta-argument to ignore the changing attribute (See [this issue](https://github.com/kreuzwerker/terraform-provider-docker/issues/473) for more information).
6161

6262
## Disabling Docker Daemon Checking
6363

@@ -110,7 +110,7 @@ When passing in a config file either the corresponding `auth` string of the repo
110110
used to retrieve the authentication credentials.
111111

112112
-> **Note**
113-
`config_file` has predence over all other options. You can theoretically specify values for every attribute but the credentials obtained through the `config_file` will override the manually set `username`/`password`
113+
`config_file` has precedence over all other options. You can theoretically specify values for every attribute but the credentials obtained through the `config_file` will override the manually set `username`/`password`
114114

115115
You can still use the environment variables `DOCKER_REGISTRY_USER` and `DOCKER_REGISTRY_PASS`.
116116

docs/resources/config.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,22 @@ resource "docker_service" "service" {
9595
- `data` (String) Base64-url-safe-encoded config data
9696
- `name` (String) User-defined name of the config
9797

98+
### Optional
99+
100+
- `labels` (Block Set) User-defined key/value metadata (see [below for nested schema](#nestedblock--labels))
101+
98102
### Read-Only
99103

100104
- `id` (String) The ID of this resource.
101105

106+
<a id="nestedblock--labels"></a>
107+
### Nested Schema for `labels`
108+
109+
Required:
110+
111+
- `label` (String) Name of the label
112+
- `value` (String) Value of the label
113+
102114
## Import
103115

104116
Import is supported using the following syntax by providing the `id`:

docs/resources/container.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "docker_image" "ubuntu" {
3636
### Optional
3737

3838
- `attach` (Boolean) If `true` attach to the container after its creation and waits the end of its execution. Defaults to `false`.
39-
- `capabilities` (Block Set, Max: 1) Add or drop certrain linux capabilities. (see [below for nested schema](#nestedblock--capabilities))
39+
- `capabilities` (Block Set, Max: 1) Add or drop certain linux capabilities. (see [below for nested schema](#nestedblock--capabilities))
4040
- `cgroup_parent` (String) Optional parent cgroup for the container
4141
- `cgroupns_mode` (String) Cgroup namespace mode to use for the container. Possible values are: `private`, `host`.
4242
- `command` (List of String) The command to use to start the container. For example, to run `/usr/bin/myprogram -f baz.conf` set the command to be `["/usr/bin/myprogram","-f","baz.conf"]`.
@@ -90,11 +90,12 @@ resource "docker_image" "ubuntu" {
9090
- `stop_timeout` (Number) Timeout (in seconds) to stop a container.
9191
- `storage_opts` (Map of String) Key/value pairs for the storage driver options, e.g. `size`: `120G`
9292
- `sysctls` (Map of String) A map of kernel parameters (sysctls) to set in the container.
93+
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
9394
- `tmpfs` (Map of String) A map of container directories which should be replaced by `tmpfs mounts`, and their corresponding mount options.
9495
- `tty` (Boolean) If `true`, allocate a pseudo-tty (`docker run -t`). Defaults to `false`.
9596
- `ulimit` (Block Set) Ulimit options to add. (see [below for nested schema](#nestedblock--ulimit))
9697
- `upload` (Block Set) Specifies files to upload to the container before starting it. Only one of `content` or `content_base64` can be set and at least one of them has to be set. (see [below for nested schema](#nestedblock--upload))
97-
- `user` (String) User used for run the first process. Format is `user` or `user:group` which user and group can be passed literraly or by name.
98+
- `user` (String) User used for run the first process. Format is `user` or `user:group` which user and group can be passed literally or by name.
9899
- `userns_mode` (String) Sets the usernamespace mode for the container when usernamespace remapping option is enabled.
99100
- `volumes` (Block Set) Spec for mounting volumes in the container. (see [below for nested schema](#nestedblock--volumes))
100101
- `wait` (Boolean) If `true`, then the Docker container is waited for being healthy state after creation. This requires your container to have a healthcheck, otherwise this provider will error. If `false`, then the container health state is not checked. Defaults to `false`.
@@ -249,6 +250,16 @@ Optional:
249250
- `protocol` (String) Protocol that can be used over this port. Defaults to `tcp`.
250251

251252

253+
<a id="nestedblock--timeouts"></a>
254+
### Nested Schema for `timeouts`
255+
256+
Optional:
257+
258+
- `create` (String)
259+
- `delete` (String)
260+
- `update` (String)
261+
262+
252263
<a id="nestedblock--ulimit"></a>
253264
### Nested Schema for `ulimit`
254265

docs/resources/service.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ Optional:
599599

600600
Optional:
601601

602-
- `memory_bytes` (Number) The amounf of memory in bytes the container allocates
602+
- `memory_bytes` (Number) The amount of memory in bytes the container allocates
603603
- `nano_cpus` (Number) CPU shares in units of `1/1e9` (or `10^-9`) of the CPU. Should be at least `1000000`
604604

605605

@@ -609,7 +609,7 @@ Optional:
609609
Optional:
610610

611611
- `generic_resources` (Block List, Max: 1) User-defined resources can be either Integer resources (e.g, `SSD=3`) or String resources (e.g, GPU=UUID1) (see [below for nested schema](#nestedblock--task_spec--resources--reservation--generic_resources))
612-
- `memory_bytes` (Number) The amounf of memory in bytes the container allocates
612+
- `memory_bytes` (Number) The amount of memory in bytes the container allocates
613613
- `nano_cpus` (Number) CPU shares in units of 1/1e9 (or 10^-9) of the CPU. Should be at least `1000000`
614614

615615
<a id="nestedblock--task_spec--resources--reservation--generic_resources"></a>
@@ -675,7 +675,7 @@ Required:
675675
Optional:
676676

677677
- `name` (String) A random name for the port
678-
- `protocol` (String) Rrepresents the protocol of a port: `tcp`, `udp` or `sctp`. Defaults to `tcp`.
678+
- `protocol` (String) Represents the protocol of a port: `tcp`, `udp` or `sctp`. Defaults to `tcp`.
679679
- `publish_mode` (String) Represents the mode in which the port is to be published: 'ingress' or 'host'. Defaults to `ingress`.
680680
- `published_port` (Number) The port on the swarm hosts
681681

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func providerSetToRegistryAuth(authList *schema.Set) (*AuthConfigs, error) {
357357
log.Println("[DEBUG] Parsing file for registry auths:", filePath)
358358

359359
// We manually expand the path and do not use the 'pathexpand' interpolation function
360-
// because in the default of this varable we refer to '~/.docker/config.json'
360+
// because in the default of this variable we refer to '~/.docker/config.json'
361361
if strings.HasPrefix(filePath, "~/") {
362362
usr, err := user.Current()
363363
if err != nil {

internal/provider/resource_docker_config.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ func resourceDockerConfig() *schema.Resource {
3838
ForceNew: true,
3939
ValidateDiagFunc: validateStringIsBase64Encoded(),
4040
},
41+
"labels": {
42+
Type: schema.TypeSet,
43+
Description: "User-defined key/value metadata",
44+
Optional: true,
45+
ForceNew: true,
46+
Elem: labelSchema,
47+
},
4148
},
4249
}
4350
}
@@ -56,6 +63,9 @@ func resourceDockerConfigCreate(ctx context.Context, d *schema.ResourceData, met
5663
Data: data,
5764
}
5865

66+
if v, ok := d.GetOk("labels"); ok {
67+
configSpec.Labels = labelSetToMap(v.(*schema.Set))
68+
}
5969
config, err := client.ConfigCreate(ctx, configSpec)
6070
if err != nil {
6171
return diag.FromErr(err)
@@ -81,8 +91,9 @@ func resourceDockerConfigRead(ctx context.Context, d *schema.ResourceData, meta
8191
log.Printf("[DEBUG] Docker config inspect from readFunc: %s", jsonObj)
8292

8393
d.SetId(config.ID)
84-
d.Set("name", config.Spec.Name) //nolint:errcheck
85-
d.Set("data", base64.StdEncoding.EncodeToString(config.Spec.Data)) //nolint:errcheck
94+
d.Set("name", config.Spec.Name)
95+
d.Set("data", base64.StdEncoding.EncodeToString(config.Spec.Data))
96+
d.Set("labels", mapToLabelSet(config.Spec.Labels))
8697
return nil
8798
}
8899

internal/provider/resource_docker_config_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,41 @@ func TestAccDockerConfig_basicUpdatable(t *testing.T) {
111111
})
112112
}
113113

114+
func TestAccDockerConfig_labels(t *testing.T) {
115+
ctx := context.Background()
116+
resource.Test(t, resource.TestCase{
117+
PreCheck: func() { testAccPreCheck(t) },
118+
ProviderFactories: providerFactories,
119+
CheckDestroy: func(state *terraform.State) error {
120+
return testCheckDockerConfigDestroy(ctx, state)
121+
},
122+
Steps: []resource.TestStep{
123+
{
124+
Config: `
125+
resource "docker_config" "foo" {
126+
name = "foo-config"
127+
data = "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="
128+
labels {
129+
label = "test1"
130+
value = "foo"
131+
}
132+
labels {
133+
label = "test2"
134+
value = "bar"
135+
}
136+
}
137+
`,
138+
Check: testCheckLabelMap("docker_config.foo", "labels",
139+
map[string]string{
140+
"test1": "foo",
141+
"test2": "bar",
142+
},
143+
),
144+
},
145+
},
146+
})
147+
}
148+
114149
// ///////////
115150
// Helpers
116151
// ///////////

internal/provider/resource_docker_container.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ package provider
33
import (
44
"context"
55
"log"
6+
"time"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
)
910

11+
const (
12+
dockerContainerCreateDefaultTimeout = 20 * time.Minute
13+
dockerContainerUpdateDefaultTimeout = 20 * time.Minute
14+
dockerContainerDeleteDefaultTimeout = 20 * time.Minute
15+
)
16+
1017
func resourceDockerContainer() *schema.Resource {
1118
return &schema.Resource{
1219
Description: "Manages the lifecycle of a Docker container.",
@@ -20,12 +27,17 @@ func resourceDockerContainer() *schema.Resource {
2027
Importer: &schema.ResourceImporter{
2128
StateContext: schema.ImportStatePassthroughContext,
2229
},
30+
Timeouts: &schema.ResourceTimeout{
31+
Create: schema.DefaultTimeout(dockerContainerCreateDefaultTimeout),
32+
Update: schema.DefaultTimeout(dockerContainerUpdateDefaultTimeout),
33+
Delete: schema.DefaultTimeout(dockerContainerDeleteDefaultTimeout),
34+
},
2335
StateUpgraders: []schema.StateUpgrader{
2436
{
2537
Version: 1,
2638
Type: resourceDockerContainerV1().CoreConfigSchema().ImpliedType(),
2739
Upgrade: func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
28-
// TODO do the ohter V0-to-V1 migration, unless we're okay
40+
// TODO do the other V0-to-V1 migration, unless we're okay
2941
// with breaking for users who straggled on their docker
3042
// provider version
3143

@@ -168,7 +180,7 @@ func resourceDockerContainer() *schema.Resource {
168180

169181
"user": {
170182
Type: schema.TypeString,
171-
Description: "User used for run the first process. Format is `user` or `user:group` which user and group can be passed literraly or by name.",
183+
Description: "User used for run the first process. Format is `user` or `user:group` which user and group can be passed literally or by name.",
172184
Optional: true,
173185
ForceNew: true,
174186
Elem: &schema.Schema{Type: schema.TypeString},
@@ -249,7 +261,7 @@ func resourceDockerContainer() *schema.Resource {
249261
},
250262
"capabilities": {
251263
Type: schema.TypeSet,
252-
Description: "Add or drop certrain linux capabilities.",
264+
Description: "Add or drop certain linux capabilities.",
253265
Optional: true,
254266
ForceNew: true,
255267
MaxItems: 1,

internal/provider/resource_docker_container_funcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData,
976976
if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") {
977977
return diag.Errorf("Error waiting for container removal '%s': %s", d.Id(), err)
978978
}
979-
log.Printf("[INFO] Waiting for Container '%s' errord: '%s'", d.Id(), err.Error())
979+
log.Printf("[INFO] Waiting for Container '%s' error: '%s'", d.Id(), err.Error())
980980
}
981981

982982
d.SetId("")

0 commit comments

Comments
 (0)