Repository: diggerhq/digger
Pull request #211 (2023-05-05 21:29:50)

fix(deps): update module github.com/aws/aws-sdk-go to v1.44.260
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/aws/aws-sdk-go](https://togithub.com/aws/aws-sdk-go) | require | patch | `v1.44.257` -> `v1.44.260` |

---

### Release Notes

<details>
<summary>aws/aws-sdk-go</summary>

### [`v1.44.260`](https://togithub.com/aws/aws-sdk-go/blob/HEAD/CHANGELOG.md#Release-v144260-2023-05-09)

[Compare Source](https://togithub.com/aws/aws-sdk-go/compare/v1.44.259...v1.44.260)

\===

##### Service Client Updates

-   `service/application-autoscaling`: Updates service API, documentation, and examples
-   `service/glue`: Updates service API and documentation
    -   This release adds AmazonRedshift Source and Target nodes in addition to DynamicTransform OutputSchemas
-   `service/sagemaker`: Updates service API and documentation
    -   This release includes support for (1) Provisioned Concurrency for Amazon SageMaker Serverless Inference and (2) UpdateEndpointWeightsAndCapacities API for Serverless endpoints.

### [`v1.44.259`](https://togithub.com/aws/aws-sdk-go/blob/HEAD/CHANGELOG.md#Release-v144259-2023-05-08)

[Compare Source](https://togithub.com/aws/aws-sdk-go/compare/v1.44.258...v1.44.259)

\===

##### Service Client Updates

-   `service/glue`: Updates service API and documentation
    -   Support large worker types G.4x and G.8x for Glue Spark”
-   `service/guardduty`: Updates service API and documentation
    -   Add AccessDeniedException 403 Error message code to support 3 Tagging related APIs
-   `service/iotsitewise`: Updates service API and documentation
-   `service/sts`: Updates service documentation
    -   Documentation updates for AWS Security Token Service.

##### SDK Bugs

-   `restjson`: Correct failure to deserialize errors.
    -   Deserialize generic error information when no response body is present.

### [`v1.44.258`](https://togithub.com/aws/aws-sdk-go/blob/HEAD/CHANGELOG.md#Release-v144258-2023-05-05)

[Compare Source](https://togithub.com/aws/aws-sdk-go/compare/v1.44.257...v1.44.258)

\===

##### Service Client Updates

-   `service/ec2`: Updates service API
    -   This release adds support the inf2 and trn1n instances. inf2 instances are purpose built for deep learning inference while trn1n instances are powered by AWS Trainium accelerators and they build on the capabilities of Trainium-powered trn1 instances.
-   `service/inspector2`: Updates service API, documentation, and paginators
-   `service/mediatailor`: Updates service API and documentation
-   `service/sqs`: Updates service API, documentation, and paginators
    -   Revert previous SQS protocol change.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/diggerhq/digger).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS43MS40IiwidXBkYXRlZEluVmVyIjoiMzUuNzQuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->



Patch:
diff --git a/.gitignore b/.gitignore
index bcc05484..e8ae7727 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 venv/
 **/__pycache__/
 __azurite*
+digger
diff --git a/go.mod b/go.mod
index 1592e107..431e1f40 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	cloud.google.com/go/storage v1.30.1
 	github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0
 	github.com/Azure/azure-sdk-for-go/sdk/data/aztables v1.0.1
-	github.com/aws/aws-sdk-go v1.44.257
+	github.com/aws/aws-sdk-go v1.44.260
 	github.com/bmatcuk/doublestar/v4 v4.6.0
 	github.com/google/go-github/v51 v51.0.0
 	github.com/google/go-github/v52 v52.0.0
diff --git a/go.sum b/go.sum
index 8685856b..b5f27116 100644
--- a/go.sum
+++ b/go.sum
@@ -37,6 +37,8 @@ github.com/aws/aws-sdk-go v1.44.255 h1:tOd7OP5V6BeHhANksc7CFB/ILS2mHj3kRhTfZKFns
 github.com/aws/aws-sdk-go v1.44.255/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/aws/aws-sdk-go v1.44.257 h1:HwelXYZZ8c34uFFhgVw3ybu2gB5fkk8KLj2idTvzZb8=
 github.com/aws/aws-sdk-go v1.44.257/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
+github.com/aws/aws-sdk-go v1.44.260 h1:78IJkDpDPXvLXvIkNAKDP/i3z8Vj+3sTAtQYw/v/2o8=
+github.com/aws/aws-sdk-go v1.44.260/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
 github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc=
 github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
 github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
diff --git a/pkg/digger/digger.go b/pkg/digger/digger.go
index c14bb7cf..a9dca538 100644
--- a/pkg/digger/digger.go
+++ b/pkg/digger/digger.go
@@ -73,16 +73,19 @@ func RunCommandsPerProject(commandsPerProject []ProjectCommand, repoOwner string
 			}
 
 			var terraformExecutor terraform.TerraformExecutor
-
+			projectPath := path.Join(workingDir, projectCommands.ProjectDir)
 			if projectCommands.Terragrunt {
-				terraformExecutor = terraform.Terragrunt{WorkingDir: path.Join(workingDir, projectCommands.ProjectDir)}
+				terraformExecutor = terraform.Terragrunt{WorkingDir: projectPath}
 			} else {
-				terraformExecutor = terraform.Terraform{WorkingDir: path.Join(workingDir, projectCommands.ProjectDir), Workspace: projectCommands.ProjectWorkspace}
+				terraformExecutor = terraform.Terraform{WorkingDir: projectPath, Workspace: projectCommands.ProjectWorkspace}
 			}
 
 			commandRunner := CommandRunner{}
 			diggerExecutor := DiggerExecutor{
+				repoOwner,
+				repoName,
 				projectCommands.ProjectName,
+				projectPath,
 				projectCommands.StateEnvVars,
 				projectCommands.CommandEnvVars,
 				projectCommands.ApplyStage,
@@ -338,7 +341,10 @@ func parseProjectName(comment string) string {
 }
 
 type DiggerExecutor struct {
+	repoOwner         string
+	repoName          string
 	projectName       string
+	projectPath       string
 	stateEnvVars      map[string]string
 	commandEnvVars    map[string]string
 	applyStage        *configuration.Stage
@@ -378,11 +384,18 @@ func (c CommandRunner) Run(command string) (string, string, error) {
 }
 
 func (d DiggerExecutor) planFileName() string {
-	return d.projectName + ".tfplan"
+	return d.repoName + "#" + d.projectName + ".tfplan"
 }
 
-func (d DiggerExecutor) Plan(prNumber int) error {
+func (d DiggerExecutor) localPlanFilePath() string {
+	return path.Join(d.projectPath, d.planFileName())
+}
+
+func (d DiggerExecutor) storedPlanFilePath() string {
+	return path.Join(d.repoOwner, d.planFileName())
+}
 
+func (d DiggerExecutor) Plan(prNumber int) error {
 	res, err := d.lock.Lock(prNumber)
 	if err != nil {
 		return fmt.Errorf("error locking project: %v", err)
@@ -418,7 +431,7 @@ func (d DiggerExecutor) Plan(prNumber int) error {
 					return fmt.Errorf("error executing plan: %v", err)
 				}
 				if d.planStorage != nil {
-					err = d.planStorage.StorePlan(d.planFileName())
+					err = d.planStorage.StorePlan(d.localPlanFilePath(), d.storedPlanFilePath())
 					if err != nil {
 						return fmt.Errorf("error storing plan: %v", err)
 					}
@@ -443,7 +456,7 @@ func (d DiggerExecutor) Apply(prNumber int) error {
 	var plansFilename *string
 	if d.planStorage != nil {
 		var err error
-		plansFilename, err = d.planStorage.RetrievePlan(d.planFileName())
+		plansFilename, err = d.planStorage.RetrievePlan(d.localPlanFilePath(), d.storedPlanFilePath())
 		if err != nil {
 			return fmt.Errorf("error retrieving plan: %v", err)
 		}
@@ -509,6 +522,10 @@ func (d DiggerExecutor) Unlock(prNumber int) error {
 	if err != nil {
 		return fmt.Errorf("failed to aquire lock: %s, %v", d.lock.LockId(), err)
 	}
+	err = d.planStorage.DeleteStoredPlan(d.storedPlanFilePath())
+	if err != nil {
+		return fmt.Errorf("failed to delete stored plan file '%v':  %v", d.storedPlanFilePath(), err)
+	}
 	return nil
 }
 
diff --git a/pkg/utils/mocks.go b/pkg/utils/mocks.go
index 020ea06d..4f986c48 100644
--- a/pkg/utils/mocks.go
+++ b/pkg/utils/mocks.go
@@ -77,10 +77,14 @@ func (t MockPullRequestManager) IsClosed(prNumber int) (bool, error) {
 type MockPlanStorage struct {
 }
 
-func (t MockPlanStorage) StorePlan(planfile string) error {
+func (t MockPlanStorage) StorePlan(localPlanFilePath string, storedPlanFilePath string) error {
 	return nil
 }
 
-func (t MockPlanStorage) RetrievePlan(planfile string) (*string, error) {
+func (t MockPlanStorage) RetrievePlan(localPlanFilePath string, storedPlanFilePath string) (*string, error) {
 	return nil, nil
 }
+
+func (t MockPlanStorage) DeleteStoredPlan(storedPlanFilePath string) error {
+	return nil
+}
diff --git a/pkg/utils/plan_storage.go b/pkg/utils/plan_storage.go
index 1ed83218..a71e500d 100644
--- a/pkg/utils/plan_storage.go
+++ b/pkg/utils/plan_storage.go
@@ -14,8 +14,9 @@ import (
 )
 
 type PlanStorage interface {
-	StorePlan(planFileName string) error
-	RetrievePlan(planFileName string) (*string, error)
+	StorePlan(localPlanFilePath string, storedPlanFilePath string) error
+	RetrievePlan(localPlanFilePath string, storedPlanFilePath string) (*string, error)
+	DeleteStoredPlan(storedPlanFilePath string) error
 }
 
 type PlanStorageGcp struct {
@@ -32,14 +33,14 @@ type GithubPlanStorage struct {
 	ZipManager        Zipper
 }
 
-func (psg *PlanStorageGcp) StorePlan(planFileName string) error {
-	file, err := os.Open(planFileName)
+func (psg *PlanStorageGcp) StorePlan(localPlanFilePath string, storedPlanFilePath string) error {
+	file, err := os.Open(localPlanFilePath)
 	if err != nil {
 		return fmt.Errorf("unable to open file: %v", err)
 	}
 	defer file.Close()
 
-	obj := psg.Bucket.Object(planFileName)
+	obj := psg.Bucket.Object(storedPlanFilePath)
 	wc := obj.NewWriter(psg.Context)
 
 	if _, err = io.Copy(wc, file); err != nil {
@@ -54,15 +55,15 @@ func (psg *PlanStorageGcp) StorePlan(planFileName string) error {
 	return nil
 }
 
-func (psg *PlanStorageGcp) RetrievePlan(planFileName string) (*string, error) {
-	obj := psg.Bucket.Object(planFileName)
+func (psg *PlanStorageGcp) RetrievePlan(localPlanFilePath string, storedPlanFilePath string) (*string, error) {
+	obj := psg.Bucket.Object(storedPlanFilePath)
 	rc, err := obj.NewReader(psg.Context)
 	if err != nil {
 		return nil, fmt.Errorf("unable to read data from bucket: %v", err)
 	}
 	defer rc.Close()
 
-	file, err := os.Create(planFileName)
+	file, err := os.Create(localPlanFilePath)
 	if err != nil {
 		return nil, fmt.Errorf("unable to create file: %v", err)
 	}
@@ -72,15 +73,25 @@ func (psg *PlanStorageGcp) RetrievePlan(planFileName string) (*string, error) {
 		return nil, fmt.Errorf("unable to write data to file: %v", err)
 	}
 
-	return &planFileName, nil
+	return &localPlanFilePath, nil
 }
 
-func (gps *GithubPlanStorage) StorePlan(planFileName string) error {
-	_ = fmt.Sprintf("Skipping storing plan %s. It should be achieved using actions/upload-artifact@v3", planFileName)
+func (psg *PlanStorageGcp) DeleteStoredPlan(storedPlanFilePath string) error {
+	obj := psg.Bucket.Object(storedPlanFilePath)
+	err := obj.Delete(psg.Context)
+
+	if err != nil {
+		return fmt.Errorf("unable to delete file '%v' from bucket: %v", storedPlanFilePath, err)
+	}
 	return nil
 }
 
-func (gps *GithubPlanStorage) RetrievePlan(planFileName string) (*string, error) {
+func (gps *GithubPlanStorage) StorePlan(localPlanFilePath string, storedPlanFilePath string) error {
+	_ = fmt.Sprintf("Skipping storing plan %s. It should be achieved using actions/upload-artifact@v3", localPlanFilePath)
+	return nil
+}
+
+func (gps *GithubPlanStorage) RetrievePlan(localPlanFilePath string, storedPlanFilePath string) (*string, error) {
 	plansFilename, err := gps.DownloadLatestPlans()
 
 	if err != nil {
@@ -91,7 +102,7 @@ func (gps *GithubPlanStorage) RetrievePlan(planFileName string) (*string, error)
 		return nil, fmt.Errorf("no plans found for this PR")
 	}
 
-	plansFilename, err = gps.ZipManager.GetFileFromZip(plansFilename, planFileName)
+	plansFilename, err = gps.ZipManager.GetFileFromZip(plansFilename, storedPlanFilePath)
 
 	if err != nil {
 		return nil, fmt.Errorf("error extracting plan: %v", err)
@@ -99,6 +110,10 @@ func (gps *GithubPlanStorage) RetrievePlan(planFileName string) (*string, error)
 	return &plansFilename, nil
 }
 
+func (gps *GithubPlanStorage) DeleteStoredPlan(storedPlanFilePath string) error {
+	return nil
+}
+
 func (gps *GithubPlanStorage) DownloadLatestPlans() (string, error) {
 	artifacts, _, err := gps.Client.Actions.ListArtifacts(context.Background(), gps.Owner, gps.RepoName, &github.ListOptions{
 		PerPage: 100,


Test patch:
diff --git a/pkg/digger/digger_test.go b/pkg/digger/digger_test.go
index 9f33753c..56451603 100644
--- a/pkg/digger/digger_test.go
+++ b/pkg/digger/digger_test.go
@@ -128,16 +128,21 @@ type MockPlanStorage struct {
 	Commands []RunInfo
 }
 
-func (m *MockPlanStorage) StorePlan(planFileName string) error {
-	m.Commands = append(m.Commands, RunInfo{"StorePlan", planFileName, time.Now()})
+func (m *MockPlanStorage) StorePlan(localPlanFilePath string, storedPlanFilePath string) error {
+	m.Commands = append(m.Commands, RunInfo{"StorePlan", localPlanFilePath, time.Now()})
 	return nil
 }
 
-func (m *MockPlanStorage) RetrievePlan(planFileName string) (*string, error) {
-	m.Commands = append(m.Commands, RunInfo{"RetrievePlan", planFileName, time.Now()})
+func (m *MockPlanStorage) RetrievePlan(localPlanFilePath string, storedPlanFilePath string) (*string, error) {
+	m.Commands = append(m.Commands, RunInfo{"RetrievePlan", localPlanFilePath, time.Now()})
 	return nil, nil
 }
 
+func (m *MockPlanStorage) DeleteStoredPlan(storedPlanFilePath string) error {
+	m.Commands = append(m.Commands, RunInfo{"DeleteStoredPlan", storedPlanFilePath, time.Now()})
+	return nil
+}
+
 func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
 
 	commandRunner := &MockCommandRunner{}
@@ -177,7 +182,7 @@ func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock, planStorage)
 
-	assert.Equal(t, []string{"RetrievePlan .tfplan", "IsMergeable 1", "Lock 1", "Init ", "Apply ", "LockId ", "PublishComment 1 <details>\n  <summary>Apply for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run echo", "LockId "}, commandStrings)
+	assert.Equal(t, []string{"RetrievePlan #.tfplan", "IsMergeable 1", "Lock 1", "Init ", "Apply ", "LockId ", "PublishComment 1 <details>\n  <summary>Apply for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run echo", "LockId "}, commandStrings)
 }
 
 func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
@@ -219,7 +224,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock, planStorage)
 
-	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out .tfplan", "StorePlan .tfplan", "LockId ", "PublishComment 1 <details>\n  <summary>Plan for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run echo", "LockId "}, commandStrings)
+	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out #.tfplan", "StorePlan #.tfplan", "LockId ", "PublishComment 1 <details>\n  <summary>Plan for ****</summary>\n\n  ```terraform\n\n  ```\n</details>", "Run echo", "LockId "}, commandStrings)
 }
 
 func allCommandsInOrderWithParams(terraformExecutor *MockTerraformExecutor, commandRunner *MockCommandRunner, prManager *MockPRManager, lock *MockProjectLock, planStorage *MockPlanStorage) []string {