2018-05-16 12:00:04 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
|
|
import (
|
2020-12-02 06:06:39 -05:00
|
|
|
"context"
|
2018-05-16 12:00:04 -04:00
|
|
|
"fmt"
|
|
|
|
|
"regexp"
|
2019-05-26 05:42:53 -04:00
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2018-05-16 12:00:04 -04:00
|
|
|
"testing"
|
2019-05-26 05:42:53 -04:00
|
|
|
"time"
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2018-07-03 11:30:53 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2019-10-09 14:25:38 -04:00
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
2018-05-16 12:00:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
// ----------- UNIT TESTS -----------
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
|
|
func TestDockerSecretFromRegistryAuth_basic(t *testing.T) {
|
2018-07-03 11:30:53 -04:00
|
|
|
authConfigs := make(map[string]types.AuthConfig)
|
|
|
|
|
authConfigs["https://repo.my-company.com:8787"] = types.AuthConfig{
|
2018-05-16 12:00:04 -04:00
|
|
|
Username: "myuser",
|
|
|
|
|
Password: "mypass",
|
|
|
|
|
Email: "",
|
|
|
|
|
ServerAddress: "repo.my-company.com:8787",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foundAuthConfig := fromRegistryAuth("repo.my-company.com:8787/my_image", authConfigs)
|
|
|
|
|
checkAttribute(t, "Username", foundAuthConfig.Username, "myuser")
|
|
|
|
|
checkAttribute(t, "Password", foundAuthConfig.Password, "mypass")
|
|
|
|
|
checkAttribute(t, "Email", foundAuthConfig.Email, "")
|
|
|
|
|
checkAttribute(t, "ServerAddress", foundAuthConfig.ServerAddress, "repo.my-company.com:8787")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDockerSecretFromRegistryAuth_multiple(t *testing.T) {
|
2018-07-03 11:30:53 -04:00
|
|
|
authConfigs := make(map[string]types.AuthConfig)
|
|
|
|
|
authConfigs["https://repo.my-company.com:8787"] = types.AuthConfig{
|
2018-05-16 12:00:04 -04:00
|
|
|
Username: "myuser",
|
|
|
|
|
Password: "mypass",
|
|
|
|
|
Email: "",
|
|
|
|
|
ServerAddress: "repo.my-company.com:8787",
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
authConfigs["https://nexus.my-fancy-company.com"] = types.AuthConfig{
|
2018-05-16 12:00:04 -04:00
|
|
|
Username: "myuser33",
|
|
|
|
|
Password: "mypass123",
|
|
|
|
|
Email: "test@example.com",
|
|
|
|
|
ServerAddress: "nexus.my-fancy-company.com",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foundAuthConfig := fromRegistryAuth("nexus.my-fancy-company.com/the_image", authConfigs)
|
|
|
|
|
checkAttribute(t, "Username", foundAuthConfig.Username, "myuser33")
|
|
|
|
|
checkAttribute(t, "Password", foundAuthConfig.Password, "mypass123")
|
|
|
|
|
checkAttribute(t, "Email", foundAuthConfig.Email, "test@example.com")
|
|
|
|
|
checkAttribute(t, "ServerAddress", foundAuthConfig.ServerAddress, "nexus.my-fancy-company.com")
|
|
|
|
|
|
|
|
|
|
foundAuthConfig = fromRegistryAuth("alpine:3.1", authConfigs)
|
|
|
|
|
checkAttribute(t, "Username", foundAuthConfig.Username, "")
|
|
|
|
|
checkAttribute(t, "Password", foundAuthConfig.Password, "")
|
|
|
|
|
checkAttribute(t, "Email", foundAuthConfig.Email, "")
|
|
|
|
|
checkAttribute(t, "ServerAddress", foundAuthConfig.ServerAddress, "")
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 05:04:51 -05:00
|
|
|
func checkAttribute(t *testing.T, name, actual, expected string) {
|
2018-05-16 12:00:04 -04:00
|
|
|
if actual != expected {
|
|
|
|
|
t.Fatalf("bad authconfig attribute for '%q'\nExpected: %s\n Got: %s", name, expected, actual)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestDockerImageNameSuppress(t *testing.T) {
|
|
|
|
|
suppressFunc := suppressIfSHAwasAdded()
|
|
|
|
|
old := ""
|
|
|
|
|
new := "alpine3.1"
|
|
|
|
|
suppress := suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:v1@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if !suppress {
|
|
|
|
|
t.Fatalf("Expected suppress for \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:latest@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if !suppress {
|
|
|
|
|
t.Fatalf("Expected suppress for \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:latest"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:latest@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:latest@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:v2@sha256:ed8e15d68bb13e3a04abddc295f87d2a8b7d849d5ff91f00dbdd66dc10fd8aac"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for image tag update from \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:v1@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:v2@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for image tag update from \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:latest@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:latest@sha256:c9d1055182f0607632b7d859d2f220126fb1c0d10aedc4451817840b30c1af86"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for image digest update from \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service:v3@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service:latest@sha256:c9d1055182f0607632b7d859d2f220126fb1c0d10aedc4451817840b30c1af86"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for image tag but no digest update from \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
old = "127.0.0.1:15000/tftest-service@sha256:74d04f400723d9770187ee284255d1eb556f3d51700792fb2bfd6ab13da50981"
|
|
|
|
|
new = "127.0.0.1:15000/tftest-service@sha256:c9d1055182f0607632b7d859d2f220126fb1c0d10aedc4451817840b30c1af86"
|
|
|
|
|
suppress = suppressFunc("k", old, new, nil)
|
|
|
|
|
if suppress {
|
|
|
|
|
t.Fatalf("Expected no suppress for image tag but no digest update from \n\told '%s' \n\tnew '%s'", old, new)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
// ----------------------------------------
|
|
|
|
|
// ----------- ACCEPTANCE TESTS -----------
|
|
|
|
|
// ----------------------------------------
|
|
|
|
|
// Fire and Forget
|
|
|
|
|
var serviceIDRegex = regexp.MustCompile(`[A-Za-z0-9_\+\.-]+`)
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_minimalSpec(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_service.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_fullSpec(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_volume" "test_volume" {
|
|
|
|
|
name = "tftest-volume"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "docker_config" "service_config" {
|
|
|
|
|
name = "tftest-full-myconfig"
|
|
|
|
|
data = "ewogICJwcmVmaXgiOiAiMTIzIgp9"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_secret" "service_secret" {
|
|
|
|
|
name = "tftest-mysecret"
|
|
|
|
|
data = "ewogICJrZXkiOiAiUVdFUlRZIgp9"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "docker_network" "test_network" {
|
|
|
|
|
name = "tftest-network"
|
|
|
|
|
driver = "overlay"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "docker_service" "foo" {
|
2019-05-26 05:42:53 -04:00
|
|
|
name = "tftest-service-basic"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "servicelabel"
|
|
|
|
|
value = "true"
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "foo"
|
|
|
|
|
value = "bar"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
command = ["ls"]
|
|
|
|
|
args = ["-las"]
|
|
|
|
|
hostname = "my-fancy-service"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
env = {
|
2018-05-16 12:00:04 -04:00
|
|
|
MYFOO = "BAR"
|
2019-10-06 06:11:11 -04:00
|
|
|
URI = "/api-call?param1=value1"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
dir = "/root"
|
|
|
|
|
user = "root"
|
|
|
|
|
groups = ["docker", "foogroup"]
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
privileges {
|
|
|
|
|
se_linux_context {
|
|
|
|
|
disable = true
|
|
|
|
|
user = "user-label"
|
|
|
|
|
role = "role-label"
|
|
|
|
|
type = "type-label"
|
|
|
|
|
level = "level-label"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
read_only = true
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
mounts {
|
|
|
|
|
target = "/mount/test"
|
|
|
|
|
source = "${docker_volume.test_volume.name}"
|
|
|
|
|
type = "volume"
|
|
|
|
|
read_only = true
|
|
|
|
|
|
|
|
|
|
volume_options {
|
|
|
|
|
no_copy = true
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "foo"
|
|
|
|
|
value = "bar"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2019-06-10 18:24:55 -04:00
|
|
|
driver_name = "random-driver"
|
|
|
|
|
driver_options = {
|
|
|
|
|
op1 = "val1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
stop_signal = "SIGTERM"
|
|
|
|
|
stop_grace_period = "10s"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
healthcheck {
|
2019-05-26 05:42:53 -04:00
|
|
|
test = ["CMD", "curl", "-f", "localhost:8080/health"]
|
2018-05-16 12:00:04 -04:00
|
|
|
interval = "5s"
|
|
|
|
|
timeout = "2s"
|
|
|
|
|
retries = 4
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
hosts {
|
|
|
|
|
host = "testhost"
|
|
|
|
|
ip = "10.0.1.0"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
dns_config {
|
|
|
|
|
nameservers = ["8.8.8.8"]
|
|
|
|
|
search = ["example.org"]
|
|
|
|
|
options = ["timeout:3"]
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
secrets {
|
|
|
|
|
secret_id = "${docker_secret.service_secret.id}"
|
|
|
|
|
secret_name = "${docker_secret.service_secret.name}"
|
2019-12-18 13:04:01 -05:00
|
|
|
file_name = "/secrets.json"
|
|
|
|
|
file_uid = "0"
|
|
|
|
|
file_gid = "0"
|
|
|
|
|
file_mode = 0777
|
2019-06-10 18:24:55 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
configs {
|
|
|
|
|
config_id = "${docker_config.service_config.id}"
|
|
|
|
|
config_name = "${docker_config.service_config.name}"
|
|
|
|
|
file_name = "/configs.json"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resources {
|
|
|
|
|
limits {
|
|
|
|
|
nano_cpus = 1000000
|
|
|
|
|
memory_bytes = 536870912
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
restart_policy = {
|
2018-05-16 12:00:04 -04:00
|
|
|
condition = "on-failure"
|
|
|
|
|
delay = "3s"
|
|
|
|
|
max_attempts = 4
|
|
|
|
|
window = "10s"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
placement {
|
|
|
|
|
constraints = [
|
|
|
|
|
"node.role==manager",
|
|
|
|
|
]
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
prefs = [
|
|
|
|
|
"spread=node.role.manager",
|
|
|
|
|
]
|
2019-05-26 05:42:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
platforms {
|
|
|
|
|
architecture = "amd64"
|
|
|
|
|
os = "linux"
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
force_update = 0
|
|
|
|
|
runtime = "container"
|
|
|
|
|
networks = ["${docker_network.test_network.id}"]
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
log_driver {
|
|
|
|
|
name = "json-file"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
options = {
|
2018-05-16 12:00:04 -04:00
|
|
|
max-size = "10m"
|
|
|
|
|
max-file = "3"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
update_config {
|
|
|
|
|
parallelism = 2
|
|
|
|
|
delay = "10s"
|
|
|
|
|
failure_action = "pause"
|
|
|
|
|
monitor = "5s"
|
|
|
|
|
max_failure_ratio = "0.1"
|
|
|
|
|
order = "start-first"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
rollback_config {
|
|
|
|
|
parallelism = 2
|
|
|
|
|
delay = "5ms"
|
|
|
|
|
failure_action = "pause"
|
|
|
|
|
monitor = "10h"
|
|
|
|
|
max_failure_ratio = "0.9"
|
|
|
|
|
order = "stop-first"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
endpoint_spec {
|
|
|
|
|
mode = "vip"
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
ports {
|
|
|
|
|
name = "random"
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
published_port = "8080"
|
|
|
|
|
publish_mode = "ingress"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-11-14 08:06:50 -05:00
|
|
|
testCheckLabelMap("docker_service.foo", "labels", map[string]string{"servicelabel": "true"}),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1.*`)),
|
2019-11-14 08:06:50 -05:00
|
|
|
testCheckLabelMap("docker_service.foo", "task_spec.0.container_spec.0.labels", map[string]string{"foo": "bar"}),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.command.0", "ls"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.args.0", "-las"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hostname", "my-fancy-service"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.MYFOO", "BAR"),
|
2019-10-06 06:11:11 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.URI", "/api-call?param1=value1"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dir", "/root"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.user", "root"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.0", "docker"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.1", "foogroup"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.0.se_linux_context.0.disable", "true"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.0.se_linux_context.0.user", "user-label"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.0.se_linux_context.0.role", "role-label"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.0.se_linux_context.0.type", "type-label"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.0.se_linux_context.0.level", "level-label"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.read_only", "true"),
|
2019-11-15 00:08:45 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.target", "/mount/test"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.source", "tftest-volume"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.type", "volume"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.read_only", "true"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.volume_options.0.no_copy", "true"),
|
|
|
|
|
testCheckLabelMap("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.volume_options.0.labels", map[string]string{"foo": "bar"}),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.volume_options.0.driver_name", "random-driver"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.2817186635.volume_options.0.driver_options.op1", "val1"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.stop_signal", "SIGTERM"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.stop_grace_period", "10s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.0", "CMD"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.1", "curl"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.2", "-f"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.3", "localhost:8080/health"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.interval", "5s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.timeout", "2s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.retries", "4"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.1878413705.host", "testhost"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.1878413705.ip", "10.0.1.0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.0.nameservers.0", "8.8.8.8"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.0.search.0", "example.org"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.0.options.0", "timeout:3"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.configs.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.secrets.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.resources.0.limits.0.nano_cpus", "1000000"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.resources.0.limits.0.memory_bytes", "536870912"),
|
2018-07-03 11:30:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.restart_policy.condition", "on-failure"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.restart_policy.delay", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.restart_policy.max_attempts", "4"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.restart_policy.window", "10s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.placement.0.constraints.4248571116", "node.role==manager"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.placement.0.prefs.1751004438", "spread=node.role.manager"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.force_update", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.networks.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.name", "json-file"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-file", "3"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-size", "10m"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.parallelism", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.delay", "10s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.failure_action", "pause"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.max_failure_ratio", "0.1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.monitor", "5s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.order", "start-first"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.parallelism", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.delay", "5ms"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.failure_action", "pause"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.monitor", "10h"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.max_failure_ratio", "0.9"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "rollback_config.0.order", "stop-first"),
|
2018-05-18 06:14:02 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.mode", "vip"),
|
2019-12-27 10:48:21 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.name", "random"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.protocol", "tcp"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.published_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.publish_mode", "ingress"),
|
2018-05-16 12:00:04 -04:00
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_service.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_partialReplicationConfig(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "1"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {
|
|
|
|
|
replicated {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "1"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "2"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_service.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_globalReplicationMode(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {
|
|
|
|
|
global = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.global", "true"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_service.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_ConflictingGlobalAndReplicated(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
|
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
global = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
ExpectError: regexp.MustCompile(`.*conflicts with.*`),
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_ConflictingGlobalModeAndConverge(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mode {
|
|
|
|
|
global = true
|
|
|
|
|
}
|
|
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "10s"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
ExpectError: regexp.MustCompile(`.*conflicts with.*`),
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
// Converging tests
|
|
|
|
|
func TestAccDockerService_privateImageConverge(t *testing.T) {
|
|
|
|
|
registry := "127.0.0.1:15000"
|
2019-05-31 09:08:32 -04:00
|
|
|
image := "127.0.0.1:15000/tftest-service:v1"
|
2019-05-26 05:42:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2019-05-26 05:42:53 -04:00
|
|
|
Config: fmt.Sprintf(`
|
|
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "%s"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-11-23 08:42:05 -05:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-foo"
|
2019-05-26 05:42:53 -04:00
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "%s"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "3m"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`, registry, image),
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2019-11-23 08:42:05 -05:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-foo"),
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
2019-05-26 05:42:53 -04:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
CheckDestroy: checkAndRemoveImages,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAccDockerService_updateMultiplePropertiesConverge(t *testing.T) {
|
2019-08-08 14:14:51 -04:00
|
|
|
t.Skip("Skipping this test because it is flaky only on travis")
|
2019-05-26 05:42:53 -04:00
|
|
|
// Step 1
|
|
|
|
|
configData := "ewogICJwcmVmaXgiOiAiMTIzIgp9"
|
|
|
|
|
secretData := "ewogICJrZXkiOiAiUVdFUlRZIgp9"
|
|
|
|
|
image := "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
mounts := `
|
2019-06-10 18:24:55 -04:00
|
|
|
mounts {
|
|
|
|
|
source = "${docker_volume.foo.name}"
|
|
|
|
|
target = "/mount/test"
|
|
|
|
|
type = "volume"
|
|
|
|
|
read_only = true
|
|
|
|
|
volume_options {
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "env"
|
|
|
|
|
value = "dev"
|
|
|
|
|
}
|
|
|
|
|
labels {
|
|
|
|
|
label = "terraform"
|
|
|
|
|
value = "true"
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-10 18:24:55 -04:00
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
hosts := `
|
2019-06-10 18:24:55 -04:00
|
|
|
hosts {
|
|
|
|
|
host = "testhost"
|
|
|
|
|
ip = "10.0.1.0"
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
logging := `
|
|
|
|
|
name = "json-file"
|
|
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
options = {
|
2019-05-26 05:42:53 -04:00
|
|
|
max-size = "10m"
|
|
|
|
|
max-file = "3"
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
healthcheckInterval := "1s"
|
|
|
|
|
healthcheckTimeout := "500ms"
|
|
|
|
|
replicas := 2
|
|
|
|
|
portsSpec := `
|
2019-06-10 18:24:55 -04:00
|
|
|
ports {
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
published_port = "8081"
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// Step 2
|
|
|
|
|
configData2 := "ewogICJwcmVmaXgiOiAiNTY3Igp9" // UPDATED to prefix: 567
|
|
|
|
|
secretData2 := "ewogICJrZXkiOiAiUVdFUlRZIgp9" // UPDATED to YXCVB
|
|
|
|
|
image2 := "127.0.0.1:15000/tftest-service:v2"
|
|
|
|
|
healthcheckInterval2 := "2s"
|
|
|
|
|
mounts2 := `
|
2019-06-10 18:24:55 -04:00
|
|
|
mounts {
|
|
|
|
|
source = "${docker_volume.foo.name}"
|
|
|
|
|
target = "/mount/test"
|
|
|
|
|
type = "volume"
|
|
|
|
|
read_only = true
|
|
|
|
|
volume_options {
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "env"
|
|
|
|
|
value = "dev"
|
|
|
|
|
}
|
|
|
|
|
labels {
|
|
|
|
|
label = "terraform"
|
|
|
|
|
value = "true"
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
2019-06-10 18:24:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mounts {
|
|
|
|
|
source = "${docker_volume.foo2.name}"
|
|
|
|
|
target = "/mount/test2"
|
|
|
|
|
type = "volume"
|
|
|
|
|
read_only = true
|
|
|
|
|
volume_options {
|
2019-11-14 08:06:50 -05:00
|
|
|
labels {
|
|
|
|
|
label = "env"
|
|
|
|
|
value = "dev"
|
|
|
|
|
}
|
|
|
|
|
labels {
|
|
|
|
|
label = "terraform"
|
|
|
|
|
value = "true"
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-06-10 18:24:55 -04:00
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
hosts2 := `
|
2019-06-10 18:24:55 -04:00
|
|
|
hosts {
|
|
|
|
|
host = "testhost2"
|
|
|
|
|
ip = "10.0.2.2"
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
logging2 := `
|
|
|
|
|
name = "json-file"
|
|
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
options = {
|
2019-05-26 05:42:53 -04:00
|
|
|
max-size = "15m"
|
|
|
|
|
max-file = "5"
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
healthcheckTimeout2 := "800ms"
|
|
|
|
|
replicas2 := 6
|
|
|
|
|
portsSpec2 := `
|
2019-06-10 18:24:55 -04:00
|
|
|
ports {
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
published_port = "8081"
|
|
|
|
|
}
|
|
|
|
|
ports {
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
published_port = "8082"
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
|
|
|
|
|
|
|
|
|
// Step 3
|
|
|
|
|
configData3 := configData2
|
|
|
|
|
secretData3 := secretData2
|
|
|
|
|
image3 := image2
|
|
|
|
|
mounts3 := mounts2
|
|
|
|
|
hosts3 := hosts2
|
|
|
|
|
logging3 := logging2
|
|
|
|
|
healthcheckInterval3 := healthcheckInterval2
|
|
|
|
|
healthcheckTimeout3 := healthcheckTimeout2
|
|
|
|
|
replicas3 := 3 // only decrease
|
|
|
|
|
portsSpec3 := portsSpec2
|
2019-06-10 18:24:55 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
|
{
|
|
|
|
|
Config: fmt.Sprintf(updateMultiplePropertiesConfigConverge, configData, secretData, image, mounts, hosts, healthcheckInterval, healthcheckTimeout, logging, replicas, portsSpec),
|
2018-05-16 12:00:04 -04:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-fnf-service-up-crihiadr"),
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1@sha256.*`)),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", strconv.Itoa(replicas)),
|
2019-05-31 09:08:32 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.parallelism", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.delay", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.failure_action", "continue"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.monitor", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.max_failure_ratio", "0.5"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.order", "start-first"),
|
2018-05-18 06:14:02 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.#", "1"),
|
2019-12-27 10:48:21 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.published_port", "8081"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.configs.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.secrets.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dir", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.%", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.#", "0"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.0", "CMD"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.1", "curl"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.2", "-f"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.3", "localhost:8080/health"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.interval", healthcheckInterval),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.timeout", healthcheckTimeout),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.retries", "2"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hostname", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.1878413705.host", "testhost"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.1878413705.ip", "10.0.1.0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.isolation", "default"),
|
2019-11-14 08:06:50 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.labels.#", "0"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.#", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.stop_grace_period", "10s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.user", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.name", "json-file"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.%", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-file", "3"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-size", "10m"),
|
2018-05-16 12:00:04 -04:00
|
|
|
),
|
|
|
|
|
},
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2019-05-26 05:42:53 -04:00
|
|
|
Config: fmt.Sprintf(updateMultiplePropertiesConfigConverge, configData2, secretData2, image2, mounts2, hosts2, healthcheckInterval2, healthcheckTimeout2, logging2, replicas2, portsSpec2),
|
2018-05-16 12:00:04 -04:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-fnf-service-up-crihiadr"),
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v2.*`)),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", strconv.Itoa(replicas2)),
|
2019-05-31 09:08:32 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.parallelism", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.delay", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.failure_action", "continue"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.monitor", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.max_failure_ratio", "0.5"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.order", "start-first"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.#", "2"),
|
2019-12-27 10:48:21 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.published_port", "8081"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.1.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.1.published_port", "8082"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.configs.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.secrets.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dir", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.%", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.#", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.0", "CMD"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.1", "curl"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.2", "-f"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.3", "localhost:8080/health"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.interval", healthcheckInterval2),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.timeout", healthcheckTimeout2),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.retries", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hostname", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.575059346.host", "testhost2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.575059346.ip", "10.0.2.2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.isolation", "default"),
|
2019-11-14 08:06:50 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.labels.#", "0"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.#", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.#", "0"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.stop_grace_period", "10s"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.user", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.name", "json-file"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.%", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-file", "5"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-size", "15m"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
Config: fmt.Sprintf(updateMultiplePropertiesConfigConverge, configData3, secretData3, image3, mounts3, hosts3, healthcheckInterval3, healthcheckTimeout3, logging3, replicas3, portsSpec3),
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-fnf-service-up-crihiadr"),
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v2.*`)),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", strconv.Itoa(replicas3)),
|
2019-05-31 09:08:32 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.parallelism", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.delay", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.failure_action", "continue"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.monitor", "3s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.max_failure_ratio", "0.5"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "update_config.0.order", "start-first"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.#", "2"),
|
2019-12-27 10:48:21 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.0.published_port", "8081"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.1.target_port", "8080"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "endpoint_spec.0.ports.1.published_port", "8082"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.configs.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.secrets.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dir", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dns_config.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.%", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.#", "0"),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.0", "CMD"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.1", "curl"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.2", "-f"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.test.3", "localhost:8080/health"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.interval", healthcheckInterval3),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.timeout", healthcheckTimeout3),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.healthcheck.0.retries", "2"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hostname", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.575059346.host", "testhost2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hosts.575059346.ip", "10.0.2.2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.isolation", "default"),
|
2019-11-14 08:06:50 -05:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.labels.#", "0"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.mounts.#", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.privileges.#", "0"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.stop_grace_period", "10s"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.user", ""),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.#", "1"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.name", "json-file"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.%", "2"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-file", "5"),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.log_driver.0.options.max-size", "15m"),
|
2018-05-16 12:00:04 -04:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_nonExistingPrivateImageConverge(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
|
|
|
|
resource "docker_service" "foo" {
|
2019-05-26 05:42:53 -04:00
|
|
|
name = "tftest-service-privateimagedoesnotexist"
|
2018-05-16 12:00:04 -04:00
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2019-05-26 05:42:53 -04:00
|
|
|
image = "127.0.0.1:15000/idonoexist:latest"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "20s"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
2019-05-26 05:42:53 -04:00
|
|
|
ExpectError: regexp.MustCompile(`.*did not converge after.*`),
|
2018-05-16 12:00:04 -04:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
isServiceRemoved("tftest-service-privateimagedoesnotexist"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
func TestAccDockerService_nonExistingPublicImageConverge(t *testing.T) {
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
|
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-publicimagedoesnotexist"
|
|
|
|
|
task_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
container_spec {
|
2018-05-16 12:00:04 -04:00
|
|
|
image = "stovogel/blablabla:part5"
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
|
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "10s"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
ExpectError: regexp.MustCompile(`.*did not converge after.*`),
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
isServiceRemoved("tftest-service-publicimagedoesnotexist"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
func TestAccDockerService_convergeAndStopGracefully(t *testing.T) {
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
Config: `
|
2019-05-26 05:42:53 -04:00
|
|
|
provider "docker" {
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
name = "tftest-service-basic-converge"
|
|
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
stop_grace_period = "10s"
|
|
|
|
|
healthcheck {
|
2019-05-26 05:42:53 -04:00
|
|
|
test = ["CMD", "curl", "-f", "localhost:8080/health"]
|
2018-05-16 12:00:04 -04:00
|
|
|
interval = "5s"
|
|
|
|
|
timeout = "2s"
|
|
|
|
|
start_period = "0s"
|
|
|
|
|
retries = 4
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endpoint_spec {
|
|
|
|
|
ports {
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "3m"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-basic-converge"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "2"),
|
2019-12-27 10:48:21 -05:00
|
|
|
testValueHigherEqualThan("docker_service.foo", "endpoint_spec.0.ports.0.target_port", 8080),
|
|
|
|
|
testValueHigherEqualThan("docker_service.foo", "endpoint_spec.0.ports.0.published_port", 30000),
|
2018-05-16 12:00:04 -04:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-05-26 05:42:53 -04:00
|
|
|
CheckDestroy: checkAndRemoveImages,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
func TestAccDockerService_updateFailsAndRollbackConverge(t *testing.T) {
|
2019-05-26 05:42:53 -04:00
|
|
|
image := "127.0.0.1:15000/tftest-service:v1"
|
|
|
|
|
imageFail := "127.0.0.1:15000/tftest-service:v3"
|
|
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2019-05-26 05:42:53 -04:00
|
|
|
Config: fmt.Sprintf(updateFailsAndRollbackConvergeConfig, image),
|
2018-05-16 12:00:04 -04:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-updateFailsAndRollbackConverge"),
|
2019-05-26 05:42:53 -04:00
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1.*`)),
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "2"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2019-05-26 05:42:53 -04:00
|
|
|
Config: fmt.Sprintf(updateFailsAndRollbackConvergeConfig, imageFail),
|
|
|
|
|
ExpectError: regexp.MustCompile(`.*rollback completed.*`),
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "id", serviceIDRegex),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "name", "tftest-service-updateFailsAndRollbackConverge"),
|
|
|
|
|
resource.TestMatchResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.image", regexp.MustCompile(`127.0.0.1:15000/tftest-service:v1.*`)),
|
|
|
|
|
resource.TestCheckResourceAttr("docker_service.foo", "mode.0.replicated.0.replicas", "2"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
CheckDestroy: checkAndRemoveImages,
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
const updateMultiplePropertiesConfigConverge = `
|
|
|
|
|
provider "docker" {
|
|
|
|
|
alias = "private"
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_volume" "foo" {
|
|
|
|
|
name = "tftest-volume"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_volume" "foo2" {
|
|
|
|
|
name = "tftest-volume2"
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2018-07-03 11:30:53 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_config" "service_config" {
|
|
|
|
|
name = "tftest-myconfig-${uuid()}"
|
|
|
|
|
data = "%s"
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
lifecycle {
|
|
|
|
|
ignore_changes = ["name"]
|
|
|
|
|
create_before_destroy = true
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_secret" "service_secret" {
|
|
|
|
|
name = "tftest-tftest-mysecret-${replace(timestamp(),":", ".")}"
|
|
|
|
|
data = "%s"
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
lifecycle {
|
|
|
|
|
ignore_changes = ["name"]
|
|
|
|
|
create_before_destroy = true
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
provider = "docker.private"
|
|
|
|
|
name = "tftest-fnf-service-up-crihiadr"
|
|
|
|
|
|
|
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "%s"
|
|
|
|
|
|
2019-06-10 18:24:55 -04:00
|
|
|
%s
|
|
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
|
|
configs {
|
|
|
|
|
config_id = "${docker_config.service_config.id}"
|
|
|
|
|
config_name = "${docker_config.service_config.name}"
|
|
|
|
|
file_name = "/configs.json"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
secrets {
|
|
|
|
|
secret_id = "${docker_secret.service_secret.id}"
|
|
|
|
|
secret_name = "${docker_secret.service_secret.name}"
|
|
|
|
|
file_name = "/secrets.json"
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
|
|
|
|
|
healthcheck {
|
|
|
|
|
test = ["CMD", "curl", "-f", "localhost:8080/health"]
|
|
|
|
|
interval = "%s"
|
|
|
|
|
timeout = "%s"
|
|
|
|
|
start_period = "1s"
|
|
|
|
|
retries = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stop_grace_period = "10s"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
log_driver {
|
|
|
|
|
%s
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = %d
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
update_config {
|
2019-05-31 09:08:32 -04:00
|
|
|
parallelism = 2
|
|
|
|
|
delay = "3s"
|
|
|
|
|
failure_action = "continue"
|
|
|
|
|
monitor = "3s"
|
|
|
|
|
max_failure_ratio = "0.5"
|
2019-05-26 05:42:53 -04:00
|
|
|
order = "start-first"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
endpoint_spec {
|
2019-06-10 18:24:55 -04:00
|
|
|
%s
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
2019-05-31 09:08:32 -04:00
|
|
|
timeout = "2m"
|
2019-05-26 05:42:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
const updateFailsAndRollbackConvergeConfig = `
|
|
|
|
|
provider "docker" {
|
|
|
|
|
alias = "private"
|
|
|
|
|
registry_auth {
|
|
|
|
|
address = "127.0.0.1:15000"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
resource "docker_service" "foo" {
|
|
|
|
|
provider = "docker.private"
|
|
|
|
|
name = "tftest-service-updateFailsAndRollbackConverge"
|
|
|
|
|
task_spec {
|
|
|
|
|
container_spec {
|
|
|
|
|
image = "%s"
|
|
|
|
|
|
|
|
|
|
healthcheck {
|
|
|
|
|
test = ["CMD", "curl", "-f", "localhost:8080/health"]
|
|
|
|
|
interval = "5s"
|
|
|
|
|
timeout = "2s"
|
|
|
|
|
start_period = "0s"
|
|
|
|
|
retries = 4
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
mode {
|
|
|
|
|
replicated {
|
|
|
|
|
replicas = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
update_config {
|
|
|
|
|
parallelism = 1
|
|
|
|
|
delay = "5s"
|
|
|
|
|
failure_action = "rollback"
|
|
|
|
|
monitor = "10s"
|
|
|
|
|
max_failure_ratio = "0.0"
|
|
|
|
|
order = "stop-first"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
rollback_config {
|
|
|
|
|
parallelism = 1
|
|
|
|
|
delay = "1s"
|
|
|
|
|
failure_action = "pause"
|
|
|
|
|
monitor = "4s"
|
|
|
|
|
max_failure_ratio = "0.0"
|
|
|
|
|
order = "stop-first"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
endpoint_spec {
|
|
|
|
|
mode = "vip"
|
|
|
|
|
ports {
|
|
|
|
|
name = "random"
|
|
|
|
|
protocol = "tcp"
|
|
|
|
|
target_port = "8080"
|
|
|
|
|
published_port = "8080"
|
|
|
|
|
publish_mode = "ingress"
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2019-05-26 05:42:53 -04:00
|
|
|
converge_config {
|
|
|
|
|
delay = "7s"
|
|
|
|
|
timeout = "3m"
|
|
|
|
|
}
|
2018-05-16 12:00:04 -04:00
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
`
|
2018-05-16 12:00:04 -04:00
|
|
|
|
|
|
|
|
// Helpers
|
2019-05-26 05:42:53 -04:00
|
|
|
// isServiceRemoved checks if a service was removed successfully
|
2018-05-16 12:00:04 -04:00
|
|
|
func isServiceRemoved(serviceName string) resource.TestCheckFunc {
|
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
|
2018-07-03 11:30:53 -04:00
|
|
|
filters := filters.NewArgs()
|
|
|
|
|
filters.Add("name", serviceName)
|
|
|
|
|
services, err := client.ServiceList(context.Background(), types.ServiceListOptions{
|
|
|
|
|
Filters: filters,
|
2018-05-16 12:00:04 -04:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Error listing service for name %s: %v", serviceName, err)
|
|
|
|
|
}
|
|
|
|
|
length := len(services)
|
|
|
|
|
if length != 0 {
|
|
|
|
|
return fmt.Errorf("Service should be removed but is running: %s", serviceName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-26 05:42:53 -04:00
|
|
|
|
|
|
|
|
// checkAndRemoveImages checks and removes all private images with
|
|
|
|
|
// the given pattern. This ensures that the image are not kept on the swarm nodes
|
|
|
|
|
// and the tests are independent of each other
|
|
|
|
|
func checkAndRemoveImages(s *terraform.State) error {
|
|
|
|
|
retrySleepSeconds := 3
|
|
|
|
|
maxRetryDeleteCount := 6
|
|
|
|
|
imagePattern := "127.0.0.1:15000/tftest-service*"
|
|
|
|
|
|
|
|
|
|
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
|
|
|
|
|
|
|
|
|
|
filters := filters.NewArgs()
|
|
|
|
|
filters.Add("reference", imagePattern)
|
|
|
|
|
images, err := client.ImageList(context.Background(), types.ImageListOptions{
|
|
|
|
|
Filters: filters,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retryDeleteCount := 0
|
|
|
|
|
for i := 0; i < len(images); {
|
|
|
|
|
image := images[i]
|
|
|
|
|
_, err := client.ImageRemove(context.Background(), image.ID, types.ImageRemoveOptions{
|
|
|
|
|
Force: true,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
if strings.Contains(err.Error(), "image is being used by running container") {
|
|
|
|
|
if retryDeleteCount == maxRetryDeleteCount {
|
|
|
|
|
return fmt.Errorf("could not delete image '%s' after %d retries", image.ID, maxRetryDeleteCount)
|
|
|
|
|
}
|
|
|
|
|
<-time.After(time.Duration(retrySleepSeconds) * time.Second)
|
|
|
|
|
retryDeleteCount++
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
i++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imagesAfterDelete, err := client.ImageList(context.Background(), types.ImageListOptions{
|
|
|
|
|
Filters: filters,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(imagesAfterDelete) != 0 {
|
|
|
|
|
return fmt.Errorf("Expected images of patter '%s' to be deleted, but there is/are still %d", imagePattern, len(imagesAfterDelete))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|