Repository: diggerhq/digger
Pull request #342 (2023-06-08 15:14:35)

merge develop into split-digger-config


Patch:
diff --git a/pkg/core/execution/execution.go b/pkg/core/execution/execution.go
index ddd47a90..d32087a6 100644
--- a/pkg/core/execution/execution.go
+++ b/pkg/core/execution/execution.go
@@ -32,7 +32,7 @@ type DiggerExecutor struct {
 }
 
 func (d DiggerExecutor) planFileName() string {
-	return d.ProjectNamespace + "#" + d.ProjectName + ".tfplan"
+	return strings.ReplaceAll(d.ProjectNamespace, "/", ":") + "#" + d.ProjectName + ".tfplan"
 }
 
 func (d DiggerExecutor) localPlanFilePath() string {
@@ -257,6 +257,10 @@ func cleanupTerraformOutput(nonEmptyOutput bool, planError error, stdout string,
 		}
 	}
 
+	// This should not happen but in case we get here we avoid slice bounds out of range exception by resetting endPos
+	if endPos <= startPos {
+		endPos = len(stdout)
+	}
 	return stdout[startPos:endPos]
 }
 


Test patch:
diff --git a/pkg/core/execution/execution_test.go b/pkg/core/execution/execution_test.go
new file mode 100644
index 00000000..7ed9c4f1
--- /dev/null
+++ b/pkg/core/execution/execution_test.go
@@ -0,0 +1,71 @@
+package execution
+
+import (
+	"github.com/stretchr/testify/assert"
+	"strings"
+	"testing"
+)
+
+func TestCorrectCleanUpWithoutRegexDoesNotProduceException(t *testing.T) {
+	stdout := `
+Note: Objects have changed outside of Terraform
+
+Terraform detected the following changes made outside of Terraform since the
+last "terraform apply" which may have affected this plan:
+
+  # docker_image.xxxx has been deleted
+  - resource "docker_image" "aaa" {
+
+    }
+
+
+Unless you have made equivalent changes to your configuration, or ignored the
+relevant attributes using ignore_changes, the following plan may include
+actions to undo or respond to these changes.
+
+─────────────────────────────────────────────────────────────────────────────
+
+Terraform used the selected providers to generate the following execution
+plan. Resource actions are indicated with the following symbols:
+  + create
+
+Terraform will perform the following actions:
+
+  # docker_image.xxxx will be created
+  + resource "docker_image" "xxx" {
+      + id          = (known after apply)
+      + image_id    = (known after apply)
+      + name        = "***.dkr.ecr.***.amazonaws.com/xxx-yyy:latest"
+      + repo_digest = (known after apply)
+      + triggers    = {
+          + "dir_sha1" = "aaaa"
+        }
+
+      + build {
+          + cache_from   = []
+          + context      = "docker/"
+          + dockerfile   = "Dockerfile"
+          + extra_hosts  = []
+          + remove       = true
+          + security_opt = []
+          + tag          = [
+              + "xxx:latest",
+            ]
+        }
+    }
+
+  # docker_registry_image.xxx will be created
+  + resource "docker_registry_image" "xxx" {
+      + id                   = (known after apply)
+      + insecure_skip_verify = false
+      + keep_remotely        = true
+      + name                 = "***.dkr.ecr.***.amazonaws.com/xxx-yyy:latest"
+      + sha256_digest        = (known after apply)
+    }
+
+Plan: 2 to add, 0 to change, 0 to destroy.
+`
+	res := cleanupTerraformPlan(true, nil, stdout, "")
+	index := strings.Index(stdout, "Terraform will perform the following actions:")
+	assert.Equal(t, stdout[index:], res)
+}