Skip to content

Commit

Permalink
fix: changing vendor for a stack is no longer allowed (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMacies authored Oct 23, 2024
1 parent 1eeddc6 commit bdff95d
Showing 1 changed file with 167 additions and 57 deletions.
224 changes: 167 additions & 57 deletions spacelift/resource_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'"]
Expand All @@ -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")),
Expand Down Expand Up @@ -1132,38 +1129,84 @@ 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")),
Attribute("cloudformation.#", Equals("0")),
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")),
Expand All @@ -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")),
Expand Down Expand Up @@ -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")),
),
},
})
Expand Down

0 comments on commit bdff95d

Please sign in to comment.