mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-22 07:39:35 -05:00
Adds docker swarm features to the provider for the Docker Engine 17.09.1 and API Version 1.32. The spec is close to the API. By default, the swarm services are fire and forget. A converging config implements the features of the docker cli to ensure a service and all its replicas are up and running. Furthermore, service can have configs, secrets, networks, mounts and be added to a network.
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package docker
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccDockerConfig_basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckDockerConfigDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: `
|
|
resource "docker_config" "foo" {
|
|
name = "foo-config"
|
|
data = "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="
|
|
}
|
|
`,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("docker_config.foo", "name", "foo-config"),
|
|
resource.TestCheckResourceAttr("docker_config.foo", "data", "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
func TestAccDockerConfig_basicUpdatable(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testCheckDockerConfigDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: `
|
|
resource "docker_config" "foo" {
|
|
name = "tftest-myconfig-${replace(timestamp(),":", ".")}"
|
|
data = "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="
|
|
|
|
lifecycle {
|
|
ignore_changes = ["name"]
|
|
create_before_destroy = true
|
|
}
|
|
}
|
|
`,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("docker_config.foo", "data", "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
Config: `
|
|
resource "docker_config" "foo" {
|
|
name = "tftest-myconfig2-${replace(timestamp(),":", ".")}"
|
|
data = "U3VuIDI1IE1hciAyMDE4IDE0OjQ2OjE5IENFU1QK"
|
|
|
|
lifecycle {
|
|
ignore_changes = ["name"]
|
|
create_before_destroy = true
|
|
}
|
|
}
|
|
`,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
resource.TestCheckResourceAttr("docker_config.foo", "data", "U3VuIDI1IE1hciAyMDE4IDE0OjQ2OjE5IENFU1QK"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
/////////////
|
|
// Helpers
|
|
/////////////
|
|
func testCheckDockerConfigDestroy(s *terraform.State) error {
|
|
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "configs" {
|
|
continue
|
|
}
|
|
|
|
id := rs.Primary.Attributes["id"]
|
|
config, err := client.InspectConfig(id)
|
|
|
|
if err == nil || config != nil {
|
|
return fmt.Errorf("Config with id '%s' still exists", id)
|
|
}
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|