Skip to content

Commit e776d14

Browse files
committed
fix: changing vendor for a stack is no longer allowed
1 parent 1eeddc6 commit e776d14

File tree

1 file changed

+167
-57
lines changed

1 file changed

+167
-57
lines changed

spacelift/resource_stack_test.go

Lines changed: 167 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,12 @@ func TestStackResourceSpace(t *testing.T) {
10631063
})
10641064
})
10651065

1066-
t.Run("with GitHub and vendor-specific configuration", func(t *testing.T) {
1066+
t.Run("with GitHub and Pulumi", func(t *testing.T) {
10671067
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
10681068

1069-
config := func(vendorConfig string) string {
1070-
return fmt.Sprintf(`
1071-
resource "spacelift_stack" "test" {
1069+
testSteps(t, []resource.TestStep{
1070+
{
1071+
Config: fmt.Sprintf(`resource "spacelift_stack" "test" {
10721072
administrative = true
10731073
after_apply = ["ls -la", "rm -rf /"]
10741074
after_destroy = ["echo 'after_destroy'"]
@@ -1088,14 +1088,11 @@ func TestStackResourceSpace(t *testing.T) {
10881088
project_root = "root"
10891089
repository = "demo"
10901090
runner_image = "custom_image:runner"
1091-
%s
1092-
}
1093-
`, randomID, vendorConfig)
1094-
}
1095-
1096-
testSteps(t, []resource.TestStep{
1097-
{
1098-
Config: config(``),
1091+
pulumi {
1092+
login_url = "s3://bucket"
1093+
stack_name = "mainpl"
1094+
}
1095+
}`, randomID),
10991096
Check: Resource(
11001097
resourceName,
11011098
Attribute("id", StartsWith("provider-test-stack")),
@@ -1132,38 +1129,84 @@ func TestStackResourceSpace(t *testing.T) {
11321129
Attribute("project_root", Equals("root")),
11331130
Attribute("repository", Equals("demo")),
11341131
Attribute("runner_image", Equals("custom_image:runner")),
1135-
),
1136-
},
1137-
{
1138-
ResourceName: resourceName,
1139-
ImportState: true,
1140-
ImportStateVerify: true,
1141-
},
1142-
{
1143-
Config: config(`pulumi {
1144-
login_url = "s3://bucket"
1145-
stack_name = "mainpl"
1146-
}`),
1147-
Check: Resource(
1148-
resourceName,
1149-
Attribute("id", StartsWith("provider-test-stack")),
11501132
Attribute("pulumi.0.login_url", Equals("s3://bucket")),
11511133
Attribute("pulumi.0.stack_name", Equals("mainpl")),
11521134
Attribute("ansible.#", Equals("0")),
11531135
Attribute("cloudformation.#", Equals("0")),
11541136
Attribute("kubernetes.#", Equals("0")),
11551137
),
11561138
},
1139+
})
1140+
})
1141+
1142+
t.Run("with GitHub and Cloudformation", func(t *testing.T) {
1143+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1144+
1145+
testSteps(t, []resource.TestStep{
11571146
{
1158-
Config: config(`cloudformation {
1147+
Config: fmt.Sprintf(`resource "spacelift_stack" "test" {
1148+
administrative = true
1149+
after_apply = ["ls -la", "rm -rf /"]
1150+
after_destroy = ["echo 'after_destroy'"]
1151+
after_init = ["terraform fmt -check", "tflint"]
1152+
after_perform = ["echo 'after_perform'"]
1153+
after_plan = ["echo 'after_plan'"]
1154+
autodeploy = true
1155+
autoretry = false
1156+
before_apply = ["ls -la", "rm -rf /"]
1157+
before_destroy = ["echo 'before_destroy'"]
1158+
before_init = ["terraform fmt -check", "tflint"]
1159+
before_perform = ["echo 'before_perform'"]
1160+
before_plan = ["echo 'before_plan'"]
1161+
branch = "master"
1162+
labels = ["one", "two"]
1163+
name = "Provider test stack %s"
1164+
project_root = "root"
1165+
repository = "demo"
1166+
runner_image = "custom_image:runner"
1167+
cloudformation {
11591168
entry_template_file = "main.yaml"
11601169
region = "eu-central-1"
11611170
template_bucket = "s3://bucket"
11621171
stack_name = "maincf"
1163-
}`),
1172+
}
1173+
}`, randomID),
11641174
Check: Resource(
11651175
resourceName,
11661176
Attribute("id", StartsWith("provider-test-stack")),
1177+
Attribute("administrative", Equals("true")),
1178+
Attribute("after_apply.#", Equals("2")),
1179+
Attribute("after_apply.0", Equals("ls -la")),
1180+
Attribute("after_apply.1", Equals("rm -rf /")),
1181+
Attribute("after_destroy.#", Equals("1")),
1182+
Attribute("after_destroy.0", Equals("echo 'after_destroy'")),
1183+
Attribute("after_init.#", Equals("2")),
1184+
Attribute("after_init.0", Equals("terraform fmt -check")),
1185+
Attribute("after_init.1", Equals("tflint")),
1186+
Attribute("after_perform.#", Equals("1")),
1187+
Attribute("after_perform.0", Equals("echo 'after_perform'")),
1188+
Attribute("after_plan.#", Equals("1")),
1189+
Attribute("after_plan.0", Equals("echo 'after_plan'")),
1190+
Attribute("autodeploy", Equals("true")),
1191+
Attribute("autoretry", Equals("false")),
1192+
Attribute("before_apply.#", Equals("2")),
1193+
Attribute("before_apply.0", Equals("ls -la")),
1194+
Attribute("before_apply.1", Equals("rm -rf /")),
1195+
Attribute("before_destroy.#", Equals("1")),
1196+
Attribute("before_destroy.0", Equals("echo 'before_destroy'")),
1197+
Attribute("before_init.#", Equals("2")),
1198+
Attribute("before_init.0", Equals("terraform fmt -check")),
1199+
Attribute("before_init.1", Equals("tflint")),
1200+
Attribute("before_perform.#", Equals("1")),
1201+
Attribute("before_perform.0", Equals("echo 'before_perform'")),
1202+
Attribute("before_plan.#", Equals("1")),
1203+
Attribute("before_plan.0", Equals("echo 'before_plan'")),
1204+
Attribute("branch", Equals("master")),
1205+
SetEquals("labels", "one", "two"),
1206+
Attribute("name", StartsWith("Provider test stack")),
1207+
Attribute("project_root", Equals("root")),
1208+
Attribute("repository", Equals("demo")),
1209+
Attribute("runner_image", Equals("custom_image:runner")),
11671210
Attribute("cloudformation.0.entry_template_file", Equals("main.yaml")),
11681211
Attribute("cloudformation.0.region", Equals("eu-central-1")),
11691212
Attribute("cloudformation.0.template_bucket", Equals("s3://bucket")),
@@ -1173,45 +1216,112 @@ func TestStackResourceSpace(t *testing.T) {
11731216
Attribute("kubernetes.#", Equals("0")),
11741217
),
11751218
},
1219+
})
1220+
})
1221+
1222+
t.Run("with GitHub and Kubernetes", func(t *testing.T) {
1223+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1224+
1225+
testSteps(t, []resource.TestStep{
11761226
{
1177-
Config: config(`kubernetes {}`),
1178-
Check: Resource(
1179-
resourceName,
1180-
Attribute("id", StartsWith("provider-test-stack")),
1181-
Attribute("kubernetes.0.namespace", Equals("")),
1182-
Attribute("ansible.#", Equals("0")),
1183-
Attribute("pulumi.#", Equals("0")),
1184-
Attribute("cloudformation.#", Equals("0")),
1185-
),
1186-
},
1187-
{
1188-
Config: config(`kubernetes {
1227+
Config: fmt.Sprintf(`resource "spacelift_stack" "test" {
1228+
administrative = true
1229+
after_apply = ["ls -la", "rm -rf /"]
1230+
after_destroy = ["echo 'after_destroy'"]
1231+
after_init = ["terraform fmt -check", "tflint"]
1232+
after_perform = ["echo 'after_perform'"]
1233+
after_plan = ["echo 'after_plan'"]
1234+
autodeploy = true
1235+
autoretry = false
1236+
before_apply = ["ls -la", "rm -rf /"]
1237+
before_destroy = ["echo 'before_destroy'"]
1238+
before_init = ["terraform fmt -check", "tflint"]
1239+
before_perform = ["echo 'before_perform'"]
1240+
before_plan = ["echo 'before_plan'"]
1241+
branch = "master"
1242+
labels = ["one", "two"]
1243+
name = "Provider test stack %s"
1244+
project_root = "root"
1245+
repository = "demo"
1246+
runner_image = "custom_image:runner"
1247+
kubernetes {
11891248
namespace = "myapp-prod"
1190-
}`),
1249+
}
1250+
}`, randomID),
11911251
Check: Resource(
11921252
resourceName,
11931253
Attribute("id", StartsWith("provider-test-stack")),
1254+
Attribute("administrative", Equals("true")),
1255+
Attribute("after_apply.#", Equals("2")),
1256+
Attribute("after_apply.0", Equals("ls -la")),
1257+
Attribute("after_apply.1", Equals("rm -rf /")),
1258+
Attribute("after_destroy.#", Equals("1")),
1259+
Attribute("after_destroy.0", Equals("echo 'after_destroy'")),
1260+
Attribute("after_init.#", Equals("2")),
1261+
Attribute("after_init.0", Equals("terraform fmt -check")),
1262+
Attribute("after_init.1", Equals("tflint")),
1263+
Attribute("after_perform.#", Equals("1")),
1264+
Attribute("after_perform.0", Equals("echo 'after_perform'")),
1265+
Attribute("after_plan.#", Equals("1")),
1266+
Attribute("after_plan.0", Equals("echo 'after_plan'")),
1267+
Attribute("autodeploy", Equals("true")),
1268+
Attribute("autoretry", Equals("false")),
1269+
Attribute("before_apply.#", Equals("2")),
1270+
Attribute("before_apply.0", Equals("ls -la")),
1271+
Attribute("before_apply.1", Equals("rm -rf /")),
1272+
Attribute("before_destroy.#", Equals("1")),
1273+
Attribute("before_destroy.0", Equals("echo 'before_destroy'")),
1274+
Attribute("before_init.#", Equals("2")),
1275+
Attribute("before_init.0", Equals("terraform fmt -check")),
1276+
Attribute("before_init.1", Equals("tflint")),
1277+
Attribute("before_perform.#", Equals("1")),
1278+
Attribute("before_perform.0", Equals("echo 'before_perform'")),
1279+
Attribute("before_plan.#", Equals("1")),
1280+
Attribute("before_plan.0", Equals("echo 'before_plan'")),
1281+
Attribute("branch", Equals("master")),
1282+
SetEquals("labels", "one", "two"),
1283+
Attribute("name", StartsWith("Provider test stack")),
1284+
Attribute("project_root", Equals("root")),
1285+
Attribute("repository", Equals("demo")),
1286+
Attribute("runner_image", Equals("custom_image:runner")),
11941287
Attribute("kubernetes.0.namespace", Equals("myapp-prod")),
11951288
Attribute("ansible.#", Equals("0")),
11961289
Attribute("pulumi.#", Equals("0")),
11971290
Attribute("cloudformation.#", Equals("0")),
11981291
),
11991292
},
1293+
})
1294+
})
1295+
1296+
t.Run("with GitHub and Ansible", func(t *testing.T) {
1297+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1298+
1299+
testSteps(t, []resource.TestStep{
12001300
{
1201-
Config: config(`ansible {
1301+
Config: fmt.Sprintf(`resource "spacelift_stack" "test" {
1302+
administrative = true
1303+
after_apply = ["ls -la", "rm -rf /"]
1304+
after_destroy = ["echo 'after_destroy'"]
1305+
after_init = ["terraform fmt -check", "tflint"]
1306+
after_perform = ["echo 'after_perform'"]
1307+
after_plan = ["echo 'after_plan'"]
1308+
autodeploy = true
1309+
autoretry = false
1310+
before_apply = ["ls -la", "rm -rf /"]
1311+
before_destroy = ["echo 'before_destroy'"]
1312+
before_init = ["terraform fmt -check", "tflint"]
1313+
before_perform = ["echo 'before_perform'"]
1314+
before_plan = ["echo 'before_plan'"]
1315+
branch = "master"
1316+
labels = ["one", "two"]
1317+
name = "Provider test stack %s"
1318+
project_root = "root"
1319+
repository = "demo"
1320+
runner_image = "custom_image:runner"
1321+
ansible {
12021322
playbook = "main.yml"
1203-
}`),
1204-
Check: Resource(
1205-
resourceName,
1206-
Attribute("id", StartsWith("provider-test-stack")),
1207-
Attribute("ansible.0.playbook", Equals("main.yml")),
1208-
Attribute("cloudformation.#", Equals("0")),
1209-
Attribute("kubernetes.#", Equals("0")),
1210-
Attribute("pulumi.#", Equals("0")),
1211-
),
1212-
},
1213-
{
1214-
Config: config(``),
1323+
}
1324+
}`, randomID),
12151325
Check: Resource(
12161326
resourceName,
12171327
Attribute("id", StartsWith("provider-test-stack")),
@@ -1248,10 +1358,10 @@ func TestStackResourceSpace(t *testing.T) {
12481358
Attribute("project_root", Equals("root")),
12491359
Attribute("repository", Equals("demo")),
12501360
Attribute("runner_image", Equals("custom_image:runner")),
1251-
Attribute("ansible.#", Equals("0")),
1361+
Attribute("ansible.0.playbook", Equals("main.yml")),
12521362
Attribute("cloudformation.#", Equals("0")),
1253-
Attribute("pulumi.#", Equals("0")),
12541363
Attribute("kubernetes.#", Equals("0")),
1364+
Attribute("pulumi.#", Equals("0")),
12551365
),
12561366
},
12571367
})

0 commit comments

Comments
 (0)