diff --git a/server/events/models/models.go b/server/events/models/models.go index c5d89b99b0..4d9ccc60a1 100644 --- a/server/events/models/models.go +++ b/server/events/models/models.go @@ -385,7 +385,7 @@ type PolicySetStatus struct { // Summary regexes var ( reChangesOutside = regexp.MustCompile(`Note: Objects have changed outside of Terraform`) - rePlanChanges = regexp.MustCompile(`Plan: (\d+) to add, (\d+) to change, (\d+) to destroy.`) + rePlanChanges = regexp.MustCompile(`Plan: (?:(\d+) to import, )?(\d+) to add, (\d+) to change, (\d+) to destroy.`) reNoChanges = regexp.MustCompile(`No changes. (Infrastructure is up-to-date|Your infrastructure matches the configuration).`) ) @@ -631,8 +631,8 @@ type WorkflowHookCommandContext struct { // PlanSuccessStats holds stats for a plan. type PlanSuccessStats struct { - Add, Change, Destroy int - Changes, ChangesOutside bool + Import, Add, Change, Destroy int + Changes, ChangesOutside bool } func NewPlanSuccessStats(output string) PlanSuccessStats { @@ -647,9 +647,10 @@ func NewPlanSuccessStats(output string) PlanSuccessStats { // We can skip checking the error here as we can assume // Terraform output will always render an integer on these // blocks. - s.Add, _ = strconv.Atoi(m[1]) - s.Change, _ = strconv.Atoi(m[2]) - s.Destroy, _ = strconv.Atoi(m[3]) + s.Import, _ = strconv.Atoi(m[1]) + s.Add, _ = strconv.Atoi(m[2]) + s.Change, _ = strconv.Atoi(m[3]) + s.Destroy, _ = strconv.Atoi(m[4]) } return s diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index b698581d29..126d89c60a 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -368,6 +368,10 @@ func TestPlanSuccess_Summary(t *testing.T) { "dummy\nPlan: 100 to add, 111 to change, 222 to destroy.", "Plan: 100 to add, 111 to change, 222 to destroy.", }, + { + "dummy\nPlan: 42 to import, 53 to add, 64 to change, 75 to destroy.", + "Plan: 42 to import, 53 to add, 64 to change, 75 to destroy.", + }, { "Note: Objects have changed outside of Terraform\ndummy\nNo changes. Infrastructure is up-to-date.", "\n**Note: Objects have changed outside of Terraform**\nNo changes. Infrastructure is up-to-date.", @@ -629,6 +633,7 @@ func TestPlanSuccessStats(t *testing.T) { Plan: 1 to add, 3 to change, 2 to destroy.`, models.PlanSuccessStats{ Changes: true, + Add: 1, Change: 3, Destroy: 2, @@ -651,6 +656,25 @@ func TestPlanSuccessStats(t *testing.T) { ChangesOutside: true, }, }, + { + "with imports", + `Terraform used the selected providers to generate the following execution + plan. Resource actions are indicated with the following symbols: + + create + ~ update in-place + - destroy + Terraform will perform the following actions: + - null_resource.hi[1] + Plan: 42 to import, 31 to add, 20 to change, 1 to destroy.`, + models.PlanSuccessStats{ + Changes: true, + + Import: 42, + Add: 31, + Change: 20, + Destroy: 1, + }, + }, { "changes and changes outside", `Note: Objects have changed outside of Terraform