Skip to content

Commit 2890a9e

Browse files
authored
chore: Add deprecation for docker_service.networks_advanced.name (#837)
1 parent 8bacb0d commit 2890a9e

File tree

9 files changed

+43
-20
lines changed

9 files changed

+43
-20
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
The documentation for the provider is available on the [Terraform Registry](https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs).
2424

25-
Do you want to migrate from `v2.x` to `v3.x`? Please read the [migration guide](docs/v2_v3_migration.md)
25+
Migration guides:
26+
* Do you want to migrate from `v3.x` to `v4.x`? Please read the [V3 - V4 migration guide](docs/v3_v4_migration.md)
27+
* Do you want to migrate from `v2.x` to `v3.x`? Please read the [V2 - V3 migration guide](docs/v2_v3_migration.md)
2628

2729
## Example usage
2830

docs/resources/network.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ resource "docker_network" "private_network" {
2828
### Optional
2929

3030
- `attachable` (Boolean) Enable manual container attachment to the network.
31-
- `check_duplicate` (Boolean, Deprecated) Requests daemon to check for networks with same name.
3231
- `driver` (String) The driver of the Docker network. Possible values are `bridge`, `host`, `overlay`, `macvlan`. See [network docs](https://docs.docker.com/network/#network-drivers) for more details.
3332
- `ingress` (Boolean) Create swarm routing-mesh network. Defaults to `false`.
3433
- `internal` (Boolean) Whether the network is internal.

docs/resources/service.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,12 @@ Optional:
558558
<a id="nestedblock--task_spec--networks_advanced"></a>
559559
### Nested Schema for `task_spec.networks_advanced`
560560

561-
Required:
562-
563-
- `name` (String) The name/id of the network.
564-
565561
Optional:
566562

567563
- `aliases` (Set of String) The network aliases of the container in the specific network.
568564
- `driver_opts` (Set of String) An array of driver options for the network, e.g. `opts1=value`
565+
- `id` (String) The id of the docker network to use. Please use `docker_network.id`. Using the name attribute of the docker network will lead to constant replacements.
566+
- `name` (String, Deprecated) Deprecated attribute. The name/id of the docker network. Conflicts with `id` attribute.
569567

570568

571569
<a id="nestedblock--task_spec--placement"></a>

docs/v3_v4_migration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# V3 to V4 Migration Guide
2+
3+
4+
## `docker_network`
5+
6+
Removed attributes:
7+
8+
* `check_duplicate`
9+
10+
## `docker_service`
11+
12+
New attribute:
13+
14+
* `networks_advanced.id`
15+
16+
Deprecated attribute:
17+
18+
* `networks_advanced.name`: Replaced by `id` attribute to make it clear that the `docker_network.id` needs to be used to prevent constant recreation of the service

internal/provider/resource_docker_network.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ func resourceDockerNetwork() *schema.Resource {
3737
Elem: labelSchema,
3838
},
3939

40-
"check_duplicate": {
41-
Type: schema.TypeBool,
42-
Description: "Requests daemon to check for networks with same name.",
43-
Optional: true,
44-
ForceNew: true,
45-
Deprecated: "This option is deprecated and will be removed in a future version. The Docker daemon will always check for duplicate networks.",
46-
},
47-
4840
"driver": {
4941
Type: schema.TypeString,
5042
Description: "The driver of the Docker network. Possible values are `bridge`, `host`, `overlay`, `macvlan`. See [network docs](https://docs.docker.com/network/#network-drivers) for more details.",

internal/provider/resource_docker_network_funcs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func resourceDockerNetworkCreate(ctx context.Context, d *schema.ResourceData, me
7878
}
7979

8080
d.SetId(retNetwork.ID)
81-
// d.Set("check_duplicate") TODO mavogel
8281
return resourceDockerNetworkRead(ctx, d, meta)
8382
}
8483

internal/provider/resource_docker_service.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,16 @@ func resourceDockerService() *schema.Resource {
700700
Schema: map[string]*schema.Schema{
701701
"name": {
702702
Type: schema.TypeString,
703-
Description: "The name/id of the network.",
704-
Required: true,
703+
Description: "Deprecated attribute. The name/id of the docker network. Conflicts with `id` attribute.",
704+
ForceNew: true,
705+
Optional: true,
706+
Deprecated: "Use the id attribute.",
707+
},
708+
"id": {
709+
Type: schema.TypeString,
710+
Description: "The id of the docker network to use. Please use `docker_network.id`. Using the name attribute of the docker network will lead to constant replacements.",
705711
ForceNew: true,
712+
Optional: true,
706713
},
707714
"aliases": {
708715
Type: schema.TypeSet,

internal/provider/resource_docker_service_structures.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67
"strconv"
@@ -515,7 +516,7 @@ func flattenTaskNetworksAdvanced(in []swarm.NetworkAttachmentConfig) *schema.Set
515516
out := make([]interface{}, len(in))
516517
for i, v := range in {
517518
m := make(map[string]interface{})
518-
m["name"] = v.Target
519+
m["id"] = v.Target
519520
m["driver_opts"] = stringSliceToSchemaSet(mapTypeMapValsToStringSlice(mapStringStringToMapStringInterface(v.DriverOpts)))
520521
if len(v.Aliases) > 0 {
521522
m["aliases"] = stringSliceToSchemaSet(v.Aliases)
@@ -1112,7 +1113,14 @@ func createServiceAdvancedNetworks(v interface{}) ([]swarm.NetworkAttachmentConf
11121113
if len(v.(*schema.Set).List()) > 0 {
11131114
for _, rawNetwork := range v.(*schema.Set).List() {
11141115
rawNetwork := rawNetwork.(map[string]interface{})
1115-
networkID := rawNetwork["name"].(string)
1116+
networkID := ""
1117+
if id, ok := rawNetwork["id"]; ok && id.(string) != "" {
1118+
networkID = id.(string)
1119+
} else if name, ok := rawNetwork["name"]; ok && name.(string) != "" {
1120+
networkID = name.(string)
1121+
} else {
1122+
return networks, fmt.Errorf("network 'name' or 'id' must be specified")
1123+
}
11161124
networkAliases := stringSetToStringSlice(rawNetwork["aliases"].(*schema.Set))
11171125
network := swarm.NetworkAttachmentConfig{
11181126
Target: networkID,

testdata/resources/docker_service/testAccDockerServiceFullSpec.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ resource "docker_service" "foo" {
177177
runtime = "container"
178178

179179
networks_advanced {
180-
name = docker_network.test_network.id
180+
id = docker_network.test_network.id
181181
aliases = ["tftest-foobar"]
182182
driver_opts = [
183183
"foo=bar"

0 commit comments

Comments
 (0)