2021-03-18 03:30:54 -04:00
|
|
|
package provider
|
2018-05-16 12:00:04 -04:00
|
|
|
|
|
|
|
|
import (
|
2020-12-02 06:06:39 -05:00
|
|
|
"context"
|
2018-05-16 12:00:04 -04:00
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2021-03-18 03:30:54 -04:00
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
2018-05-16 12:00:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAccDockerConfig_basic(t *testing.T) {
|
2021-03-18 03:30:54 -04:00
|
|
|
ctx := context.Background()
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
2021-03-18 03:30:54 -04:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
ProviderFactories: providerFactories,
|
|
|
|
|
CheckDestroy: func(state *terraform.State) error {
|
|
|
|
|
return testCheckDockerConfigDestroy(ctx, state)
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
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=="),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_config.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-12-02 06:06:39 -05:00
|
|
|
|
2018-05-16 12:00:04 -04:00
|
|
|
func TestAccDockerConfig_basicUpdatable(t *testing.T) {
|
2021-03-18 03:30:54 -04:00
|
|
|
ctx := context.Background()
|
2018-05-16 12:00:04 -04:00
|
|
|
resource.Test(t, resource.TestCase{
|
2021-03-18 03:30:54 -04:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
ProviderFactories: providerFactories,
|
|
|
|
|
CheckDestroy: func(state *terraform.State) error {
|
|
|
|
|
return testCheckDockerConfigDestroy(ctx, state)
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
Steps: []resource.TestStep{
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
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=="),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-03-01 16:02:17 -05:00
|
|
|
{
|
2018-05-16 12:00:04 -04:00
|
|
|
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"),
|
|
|
|
|
),
|
|
|
|
|
},
|
2019-11-23 08:42:05 -05:00
|
|
|
{
|
|
|
|
|
ResourceName: "docker_config.foo",
|
|
|
|
|
ImportState: true,
|
|
|
|
|
ImportStateVerify: true,
|
|
|
|
|
},
|
2018-05-16 12:00:04 -04:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
// Helpers
|
|
|
|
|
/////////////
|
2021-03-18 03:30:54 -04:00
|
|
|
func testCheckDockerConfigDestroy(ctx context.Context, s *terraform.State) error {
|
2018-05-16 12:00:04 -04:00
|
|
|
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
|
if rs.Type != "configs" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id := rs.Primary.Attributes["id"]
|
2021-03-18 03:30:54 -04:00
|
|
|
_, _, err := client.ConfigInspectWithRaw(ctx, id)
|
2018-05-16 12:00:04 -04:00
|
|
|
|
2018-07-03 11:30:53 -04:00
|
|
|
if err == nil {
|
2018-05-16 12:00:04 -04:00
|
|
|
return fmt.Errorf("Config with id '%s' still exists", id)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|