diff --git a/kustomize/resource_kustomization.go b/kustomize/resource_kustomization.go index 54980b5..5bd3411 100644 --- a/kustomize/resource_kustomization.go +++ b/kustomize/resource_kustomization.go @@ -320,7 +320,7 @@ func kustomizationResourceUpdate(d *schema.ResourceData, m interface{}) error { return logError(err) } - if !d.HasChange("manifest") { + if !d.HasChange("manifest") && !d.HasChange("wait") { return logError(kmm.fmtErr( errors.New("update called without diff"), )) diff --git a/kustomize/resource_kustomization_test.go b/kustomize/resource_kustomization_test.go index 9b30802..f851856 100644 --- a/kustomize/resource_kustomization_test.go +++ b/kustomize/resource_kustomization_test.go @@ -523,6 +523,64 @@ resource "kustomization_resource" "dep1" { ` } +func TestAccResourceKustomization_add_wait(t *testing.T) { + now := time.Now() + resource.Test(t, resource.TestCase{ + //PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + // + // + // Applying initial config with a svc and deployment in a namespace with no wait + { + Config: testAccResourceKustomizationConfig_wait_off("test_kustomizations/wait-change/initial"), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 5*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), + ), + }, + // + // + // Applying exactly the same configuration, but with wait turned on + { + Config: testAccResourceKustomizationConfig_wait_on("test_kustomizations/wait-change/initial"), + Check: resource.ComposeAggregateTestCheckFunc( + assertDurationIsShorterThan(now, 1*time.Minute), + testAccCheckManifestNestedString("kustomization_resource.dep1", "test", "spec", "selector", "matchLabels", "app"), + testAccCheckDeploymentReady("kustomization_resource.dep1", "test-wait-change", "test"), + ), + }, + }, + }) +} + +func testAccResourceKustomizationConfig_wait_off(path string) string { + return testAccDataSourceKustomizationConfig_basic(path) + ` +resource "kustomization_resource" "ns" { + manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"] +} +resource "kustomization_resource" "dep1" { + manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"] +} +` +} + +func testAccResourceKustomizationConfig_wait_on(path string) string { + return testAccDataSourceKustomizationConfig_basic(path) + ` +resource "kustomization_resource" "ns" { + manifest = data.kustomization_build.test.manifests["_/Namespace/_/test-wait-change"] +} +resource "kustomization_resource" "dep1" { + manifest = data.kustomization_build.test.manifests["apps/Deployment/test-wait-change/test"] + wait = true + timeouts { + create = "1m" + update = "1m" + } +} +` +} + func TestAccResourceKustomization_wait_failure(t *testing.T) { now := time.Now() diff --git a/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml new file mode 100644 index 0000000..004c561 --- /dev/null +++ b/kustomize/test_kustomizations/wait-change/initial/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: test-wait-change + +resources: +- namespace.yaml +- ../../_example_app diff --git a/kustomize/test_kustomizations/wait-change/initial/namespace.yaml b/kustomize/test_kustomizations/wait-change/initial/namespace.yaml new file mode 100644 index 0000000..12fb165 --- /dev/null +++ b/kustomize/test_kustomizations/wait-change/initial/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: test-wait-change