diff --git a/spacelift/resource_stack_test.go b/spacelift/resource_stack_test.go index 1839f143..a51e0c18 100644 --- a/spacelift/resource_stack_test.go +++ b/spacelift/resource_stack_test.go @@ -1063,12 +1063,12 @@ func TestStackResourceSpace(t *testing.T) { }) }) - t.Run("with GitHub and vendor-specific configuration", func(t *testing.T) { + t.Run("with GitHub and Pulumi", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - config := func(vendorConfig string) string { - return fmt.Sprintf(` - resource "spacelift_stack" "test" { + testSteps(t, []resource.TestStep{ + { + Config: fmt.Sprintf(`resource "spacelift_stack" "test" { administrative = true after_apply = ["ls -la", "rm -rf /"] after_destroy = ["echo 'after_destroy'"] @@ -1088,14 +1088,11 @@ func TestStackResourceSpace(t *testing.T) { project_root = "root" repository = "demo" runner_image = "custom_image:runner" - %s - } - `, randomID, vendorConfig) - } - - testSteps(t, []resource.TestStep{ - { - Config: config(``), + pulumi { + login_url = "s3://bucket" + stack_name = "mainpl" + } + }`, randomID), Check: Resource( resourceName, Attribute("id", StartsWith("provider-test-stack")), @@ -1132,21 +1129,6 @@ func TestStackResourceSpace(t *testing.T) { Attribute("project_root", Equals("root")), Attribute("repository", Equals("demo")), Attribute("runner_image", Equals("custom_image:runner")), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config(`pulumi { - login_url = "s3://bucket" - stack_name = "mainpl" - }`), - Check: Resource( - resourceName, - Attribute("id", StartsWith("provider-test-stack")), Attribute("pulumi.0.login_url", Equals("s3://bucket")), Attribute("pulumi.0.stack_name", Equals("mainpl")), Attribute("ansible.#", Equals("0")), @@ -1154,16 +1136,77 @@ func TestStackResourceSpace(t *testing.T) { Attribute("kubernetes.#", Equals("0")), ), }, + }) + }) + + t.Run("with GitHub and Cloudformation", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + testSteps(t, []resource.TestStep{ { - Config: config(`cloudformation { + Config: fmt.Sprintf(`resource "spacelift_stack" "test" { + administrative = true + after_apply = ["ls -la", "rm -rf /"] + after_destroy = ["echo 'after_destroy'"] + after_init = ["terraform fmt -check", "tflint"] + after_perform = ["echo 'after_perform'"] + after_plan = ["echo 'after_plan'"] + autodeploy = true + autoretry = false + before_apply = ["ls -la", "rm -rf /"] + before_destroy = ["echo 'before_destroy'"] + before_init = ["terraform fmt -check", "tflint"] + before_perform = ["echo 'before_perform'"] + before_plan = ["echo 'before_plan'"] + branch = "master" + labels = ["one", "two"] + name = "Provider test stack %s" + project_root = "root" + repository = "demo" + runner_image = "custom_image:runner" + cloudformation { entry_template_file = "main.yaml" region = "eu-central-1" template_bucket = "s3://bucket" stack_name = "maincf" - }`), + } + }`, randomID), Check: Resource( resourceName, Attribute("id", StartsWith("provider-test-stack")), + Attribute("administrative", Equals("true")), + Attribute("after_apply.#", Equals("2")), + Attribute("after_apply.0", Equals("ls -la")), + Attribute("after_apply.1", Equals("rm -rf /")), + Attribute("after_destroy.#", Equals("1")), + Attribute("after_destroy.0", Equals("echo 'after_destroy'")), + Attribute("after_init.#", Equals("2")), + Attribute("after_init.0", Equals("terraform fmt -check")), + Attribute("after_init.1", Equals("tflint")), + Attribute("after_perform.#", Equals("1")), + Attribute("after_perform.0", Equals("echo 'after_perform'")), + Attribute("after_plan.#", Equals("1")), + Attribute("after_plan.0", Equals("echo 'after_plan'")), + Attribute("autodeploy", Equals("true")), + Attribute("autoretry", Equals("false")), + Attribute("before_apply.#", Equals("2")), + Attribute("before_apply.0", Equals("ls -la")), + Attribute("before_apply.1", Equals("rm -rf /")), + Attribute("before_destroy.#", Equals("1")), + Attribute("before_destroy.0", Equals("echo 'before_destroy'")), + Attribute("before_init.#", Equals("2")), + Attribute("before_init.0", Equals("terraform fmt -check")), + Attribute("before_init.1", Equals("tflint")), + Attribute("before_perform.#", Equals("1")), + Attribute("before_perform.0", Equals("echo 'before_perform'")), + Attribute("before_plan.#", Equals("1")), + Attribute("before_plan.0", Equals("echo 'before_plan'")), + Attribute("branch", Equals("master")), + SetEquals("labels", "one", "two"), + Attribute("name", StartsWith("Provider test stack")), + Attribute("project_root", Equals("root")), + Attribute("repository", Equals("demo")), + Attribute("runner_image", Equals("custom_image:runner")), Attribute("cloudformation.0.entry_template_file", Equals("main.yaml")), Attribute("cloudformation.0.region", Equals("eu-central-1")), Attribute("cloudformation.0.template_bucket", Equals("s3://bucket")), @@ -1173,45 +1216,112 @@ func TestStackResourceSpace(t *testing.T) { Attribute("kubernetes.#", Equals("0")), ), }, + }) + }) + + t.Run("with GitHub and Kubernetes", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + testSteps(t, []resource.TestStep{ { - Config: config(`kubernetes {}`), - Check: Resource( - resourceName, - Attribute("id", StartsWith("provider-test-stack")), - Attribute("kubernetes.0.namespace", Equals("")), - Attribute("ansible.#", Equals("0")), - Attribute("pulumi.#", Equals("0")), - Attribute("cloudformation.#", Equals("0")), - ), - }, - { - Config: config(`kubernetes { + Config: fmt.Sprintf(`resource "spacelift_stack" "test" { + administrative = true + after_apply = ["ls -la", "rm -rf /"] + after_destroy = ["echo 'after_destroy'"] + after_init = ["terraform fmt -check", "tflint"] + after_perform = ["echo 'after_perform'"] + after_plan = ["echo 'after_plan'"] + autodeploy = true + autoretry = false + before_apply = ["ls -la", "rm -rf /"] + before_destroy = ["echo 'before_destroy'"] + before_init = ["terraform fmt -check", "tflint"] + before_perform = ["echo 'before_perform'"] + before_plan = ["echo 'before_plan'"] + branch = "master" + labels = ["one", "two"] + name = "Provider test stack %s" + project_root = "root" + repository = "demo" + runner_image = "custom_image:runner" + kubernetes { namespace = "myapp-prod" - }`), + } + }`, randomID), Check: Resource( resourceName, Attribute("id", StartsWith("provider-test-stack")), + Attribute("administrative", Equals("true")), + Attribute("after_apply.#", Equals("2")), + Attribute("after_apply.0", Equals("ls -la")), + Attribute("after_apply.1", Equals("rm -rf /")), + Attribute("after_destroy.#", Equals("1")), + Attribute("after_destroy.0", Equals("echo 'after_destroy'")), + Attribute("after_init.#", Equals("2")), + Attribute("after_init.0", Equals("terraform fmt -check")), + Attribute("after_init.1", Equals("tflint")), + Attribute("after_perform.#", Equals("1")), + Attribute("after_perform.0", Equals("echo 'after_perform'")), + Attribute("after_plan.#", Equals("1")), + Attribute("after_plan.0", Equals("echo 'after_plan'")), + Attribute("autodeploy", Equals("true")), + Attribute("autoretry", Equals("false")), + Attribute("before_apply.#", Equals("2")), + Attribute("before_apply.0", Equals("ls -la")), + Attribute("before_apply.1", Equals("rm -rf /")), + Attribute("before_destroy.#", Equals("1")), + Attribute("before_destroy.0", Equals("echo 'before_destroy'")), + Attribute("before_init.#", Equals("2")), + Attribute("before_init.0", Equals("terraform fmt -check")), + Attribute("before_init.1", Equals("tflint")), + Attribute("before_perform.#", Equals("1")), + Attribute("before_perform.0", Equals("echo 'before_perform'")), + Attribute("before_plan.#", Equals("1")), + Attribute("before_plan.0", Equals("echo 'before_plan'")), + Attribute("branch", Equals("master")), + SetEquals("labels", "one", "two"), + Attribute("name", StartsWith("Provider test stack")), + Attribute("project_root", Equals("root")), + Attribute("repository", Equals("demo")), + Attribute("runner_image", Equals("custom_image:runner")), Attribute("kubernetes.0.namespace", Equals("myapp-prod")), Attribute("ansible.#", Equals("0")), Attribute("pulumi.#", Equals("0")), Attribute("cloudformation.#", Equals("0")), ), }, + }) + }) + + t.Run("with GitHub and Ansible", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + + testSteps(t, []resource.TestStep{ { - Config: config(`ansible { + Config: fmt.Sprintf(`resource "spacelift_stack" "test" { + administrative = true + after_apply = ["ls -la", "rm -rf /"] + after_destroy = ["echo 'after_destroy'"] + after_init = ["terraform fmt -check", "tflint"] + after_perform = ["echo 'after_perform'"] + after_plan = ["echo 'after_plan'"] + autodeploy = true + autoretry = false + before_apply = ["ls -la", "rm -rf /"] + before_destroy = ["echo 'before_destroy'"] + before_init = ["terraform fmt -check", "tflint"] + before_perform = ["echo 'before_perform'"] + before_plan = ["echo 'before_plan'"] + branch = "master" + labels = ["one", "two"] + name = "Provider test stack %s" + project_root = "root" + repository = "demo" + runner_image = "custom_image:runner" + ansible { playbook = "main.yml" - }`), - Check: Resource( - resourceName, - Attribute("id", StartsWith("provider-test-stack")), - Attribute("ansible.0.playbook", Equals("main.yml")), - Attribute("cloudformation.#", Equals("0")), - Attribute("kubernetes.#", Equals("0")), - Attribute("pulumi.#", Equals("0")), - ), - }, - { - Config: config(``), + } + }`, randomID), Check: Resource( resourceName, Attribute("id", StartsWith("provider-test-stack")), @@ -1248,10 +1358,10 @@ func TestStackResourceSpace(t *testing.T) { Attribute("project_root", Equals("root")), Attribute("repository", Equals("demo")), Attribute("runner_image", Equals("custom_image:runner")), - Attribute("ansible.#", Equals("0")), + Attribute("ansible.0.playbook", Equals("main.yml")), Attribute("cloudformation.#", Equals("0")), - Attribute("pulumi.#", Equals("0")), Attribute("kubernetes.#", Equals("0")), + Attribute("pulumi.#", Equals("0")), ), }, })