Skip to content

Commit bc8b6b3

Browse files
fix: added a fix to the projects DA variation to address a bug where the order of projects outputs was not consistent (#100)
BREAKING CHANGE: In order to fix this issue, the code was refactored in a way where your code engine projects may be destroyed and recreated. If upgrading from an older version of the DA and your plan has identified your projects to be recreated, bare in mind that any apps running in those projects will also be destroyed.
1 parent d773d2e commit bc8b6b3

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

solutions/projects/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module "resource_group" {
2323
########################################################################################################################
2424

2525
module "project" {
26-
for_each = toset(local.projects)
26+
count = length(local.projects)
2727
source = "../../modules/project"
28-
name = each.value
28+
name = local.projects[count.index]
2929
resource_group_id = module.resource_group.resource_group_id
3030
}

solutions/projects/outputs.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,50 @@ output "project_name_id_map" {
1111
# As a workaround, we will output the first 5 projects individually. If a project does not exist, the output will be null.
1212
output "project_1_name" {
1313
description = "Name of the first project."
14-
value = length(values(module.project)) > 0 ? values(module.project)[0].name : null
14+
value = length(module.project) > 0 ? module.project[0].name : null
1515
}
1616

1717
output "project_1_id" {
1818
description = "ID of the first project."
19-
value = length(values(module.project)) > 0 ? values(module.project)[0].project_id : null
19+
value = length(module.project) > 0 ? module.project[0].project_id : null
2020
}
2121

2222
output "project_2_name" {
2323
description = "Name of the second project."
24-
value = length(values(module.project)) > 1 ? values(module.project)[1].name : null
24+
value = length(module.project) > 1 ? module.project[1].name : null
2525
}
2626

2727
output "project_2_id" {
2828
description = "ID of the second project."
29-
value = length(values(module.project)) > 1 ? values(module.project)[1].project_id : null
29+
value = length(module.project) > 1 ? module.project[1].project_id : null
3030
}
3131

3232
output "project_3_name" {
3333
description = "Name of the third project."
34-
value = length(values(module.project)) > 2 ? values(module.project)[2].name : null
34+
value = length(module.project) > 2 ? module.project[2].name : null
3535
}
3636

3737
output "project_3_id" {
3838
description = "ID of the third project."
39-
value = length(values(module.project)) > 2 ? values(module.project)[2].project_id : null
39+
value = length(module.project) > 2 ? module.project[2].project_id : null
4040
}
4141

4242
output "project_4_name" {
4343
description = "Name of the fourth project."
44-
value = length(values(module.project)) > 3 ? values(module.project)[3].name : null
44+
value = length(module.project) > 3 ? module.project[3].name : null
4545
}
4646

4747
output "project_4_id" {
4848
description = "ID of the fourth project."
49-
value = length(values(module.project)) > 3 ? values(module.project)[3].project_id : null
49+
value = length(module.project) > 3 ? module.project[3].project_id : null
5050
}
5151

5252
output "project_5_name" {
5353
description = "Name of the fifth project."
54-
value = length(values(module.project)) > 4 ? values(module.project)[4].name : null
54+
value = length(module.project) > 4 ? module.project[4].name : null
5555
}
5656

5757
output "project_5_id" {
5858
description = "ID of the fifth project."
59-
value = length(values(module.project)) > 4 ? values(module.project)[4].project_id : null
59+
value = length(module.project) > 4 ? module.project[4].project_id : null
6060
}

tests/pr_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package test
33

44
import (
5+
"fmt"
56
"log"
67
"os"
78
"testing"
@@ -174,6 +175,30 @@ func TestRunUpgradeAppSolution(t *testing.T) {
174175
}
175176
}
176177

178+
func TestUpgradeCEProjectsDA(t *testing.T) {
179+
t.Parallel()
180+
181+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
182+
Testing: t,
183+
TerraformDir: "solutions/projects",
184+
Prefix: "ce-da",
185+
})
186+
187+
options.TerraformVars = map[string]interface{}{
188+
"resource_group_name": resourceGroup,
189+
"existing_resource_group": true,
190+
"prefix": options.Prefix,
191+
"project_names": "[\"test-1\", \"test-2\", \"test-3\", \"test-4\", \"test-5\"]",
192+
}
193+
194+
output, err := options.RunTestUpgrade()
195+
196+
if !options.UpgradeTestSkipped {
197+
assert.Nil(t, err, "This should not have errored")
198+
assert.NotNil(t, output, "Expected some output")
199+
}
200+
}
201+
177202
func TestDeployCEProjectsDA(t *testing.T) {
178203
t.Parallel()
179204

@@ -187,10 +212,23 @@ func TestDeployCEProjectsDA(t *testing.T) {
187212
"resource_group_name": resourceGroup,
188213
"existing_resource_group": true,
189214
"prefix": options.Prefix,
190-
"project_names": "[\"test-1\", \"test-2\"]",
215+
"project_names": "[\"test-1\", \"test-2\", \"test-3\", \"test-4\", \"test-5\"]",
191216
}
192217

193218
output, err := options.RunTestConsistency()
219+
194220
assert.Nil(t, err, "This should not have errored")
195221
assert.NotNil(t, output, "Expected some output")
222+
223+
// Check outputs for project names in correct order
224+
expectedOutputs := []string{"project_1_name", "project_2_name", "project_3_name", "project_4_name", "project_5_name"}
225+
_, outputErr := testhelper.ValidateTerraformOutputs(options.LastTestTerraformOutputs, expectedOutputs...)
226+
if assert.NoErrorf(t, outputErr, "Some outputs not found or nil") {
227+
assert.Equal(t, fmt.Sprintf("%s-test-1", options.Prefix), options.LastTestTerraformOutputs["project_1_name"], "Project 1 name not as expected")
228+
assert.Equal(t, fmt.Sprintf("%s-test-2", options.Prefix), options.LastTestTerraformOutputs["project_2_name"], "Project 2 name not as expected")
229+
assert.Equal(t, fmt.Sprintf("%s-test-3", options.Prefix), options.LastTestTerraformOutputs["project_3_name"], "Project 3 name not as expected")
230+
assert.Equal(t, fmt.Sprintf("%s-test-4", options.Prefix), options.LastTestTerraformOutputs["project_4_name"], "Project 4 name not as expected")
231+
assert.Equal(t, fmt.Sprintf("%s-test-5", options.Prefix), options.LastTestTerraformOutputs["project_5_name"], "Project 5 name not as expected")
232+
}
233+
196234
}

0 commit comments

Comments
 (0)