Skip to content

Commit 2754db5

Browse files
authored
add aws as storage backend for plan storage (#1346)
1 parent 3995c5b commit 2754db5

File tree

9 files changed

+660
-311
lines changed

9 files changed

+660
-311
lines changed

action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ inputs:
7878
required: false
7979
default: 'true'
8080
upload-plan-destination:
81-
description: Destination to upload the plan to. gcp and github are currently supported
81+
description: Destination to upload the plan to. gcp, github and aws are currently supported.
82+
required: false
83+
upload-plan-destination-s3-bucket:
84+
description: Name of the destination bucket for AWS S3. Should be provided if destination == aws
85+
required: false
86+
upload-plan-destination-gcp-bucket:
87+
description: Name of the destination bucket for a GCP bucket. Should be provided if destination == gcp
8288
required: false
8389
setup-checkov:
8490
description: Setup Checkov
@@ -268,6 +274,8 @@ runs:
268274
shell: bash
269275
env:
270276
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
277+
GOOGLE_STORAGE_BUCKET: ${{ inputs.upload-plan-destination-gcp-bucket }}
278+
AWS_S3_BUCKET: ${{ inputs.upload-plan-destination-s3-bucket }}
271279
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
272280
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
273281
DIGGER_TOKEN: ${{ inputs.digger-token }}
@@ -294,6 +302,8 @@ runs:
294302
env:
295303
actionref: ${{ github.action_ref }}
296304
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
305+
GOOGLE_STORAGE_BUCKET: ${{ inputs.upload-plan-destination-gcp-bucket }}
306+
AWS_S3_BUCKET: ${{ inputs.upload-plan-destination-s3-bucket }}
297307
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
298308
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
299309
DIGGER_TOKEN: ${{ inputs.digger-token }}

cli/cmd/digger/main.go

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"github.com/diggerhq/digger/cli/pkg/comment_updater"
8-
core_drift "github.com/diggerhq/digger/cli/pkg/core/drift"
9-
core_reporting "github.com/diggerhq/digger/cli/pkg/core/reporting"
10-
"github.com/diggerhq/digger/cli/pkg/drift"
117
"log"
128
"net/http"
139
"os"
1410
"strconv"
1511
"strings"
1612
"time"
1713

14+
"github.com/diggerhq/digger/cli/pkg/comment_updater"
15+
core_drift "github.com/diggerhq/digger/cli/pkg/core/drift"
16+
core_reporting "github.com/diggerhq/digger/cli/pkg/core/reporting"
17+
"github.com/diggerhq/digger/cli/pkg/drift"
18+
1819
"github.com/diggerhq/digger/cli/pkg/azure"
1920
"github.com/diggerhq/digger/cli/pkg/bitbucket"
2021
core_backend "github.com/diggerhq/digger/cli/pkg/core/backend"
@@ -263,23 +264,23 @@ func gitHubCI(lock core_locking.Lock, policyChecker core_policy.Checker, backend
263264
workflow := diggerConfig.Workflows[projectConfig.Workflow]
264265

265266
stateEnvVars, commandEnvVars := digger_config.CollectTerraformEnvConfig(workflow.EnvVars)
266-
267+
267268
StateEnvProvider, CommandEnvProvider := orchestrator.GetStateAndCommandProviders(projectConfig)
268-
269+
269270
job := orchestrator.Job{
270-
ProjectName: projectConfig.Name,
271-
ProjectDir: projectConfig.Dir,
272-
ProjectWorkspace: projectConfig.Workspace,
273-
Terragrunt: projectConfig.Terragrunt,
274-
OpenTofu: projectConfig.OpenTofu,
275-
Commands: []string{"digger drift-detect"},
276-
ApplyStage: orchestrator.ToConfigStage(workflow.Apply),
277-
PlanStage: orchestrator.ToConfigStage(workflow.Plan),
278-
CommandEnvVars: commandEnvVars,
279-
StateEnvVars: stateEnvVars,
280-
RequestedBy: githubActor,
281-
Namespace: ghRepository,
282-
EventName: "drift-detect",
271+
ProjectName: projectConfig.Name,
272+
ProjectDir: projectConfig.Dir,
273+
ProjectWorkspace: projectConfig.Workspace,
274+
Terragrunt: projectConfig.Terragrunt,
275+
OpenTofu: projectConfig.OpenTofu,
276+
Commands: []string{"digger drift-detect"},
277+
ApplyStage: orchestrator.ToConfigStage(workflow.Apply),
278+
PlanStage: orchestrator.ToConfigStage(workflow.Plan),
279+
CommandEnvVars: commandEnvVars,
280+
StateEnvVars: stateEnvVars,
281+
RequestedBy: githubActor,
282+
Namespace: ghRepository,
283+
EventName: "drift-detect",
283284
StateEnvProvider: StateEnvProvider,
284285
CommandEnvProvider: CommandEnvProvider,
285286
}
@@ -683,19 +684,19 @@ func bitbucketCI(lock core_locking.Lock, policyChecker core_policy.Checker, back
683684
StateEnvProvider, CommandEnvProvider := orchestrator.GetStateAndCommandProviders(projectConfig)
684685

685686
job := orchestrator.Job{
686-
ProjectName: projectConfig.Name,
687-
ProjectDir: projectConfig.Dir,
688-
ProjectWorkspace: projectConfig.Workspace,
689-
Terragrunt: projectConfig.Terragrunt,
690-
OpenTofu: projectConfig.OpenTofu,
691-
Commands: []string{"digger drift-detect"},
692-
ApplyStage: orchestrator.ToConfigStage(workflow.Apply),
693-
PlanStage: orchestrator.ToConfigStage(workflow.Plan),
694-
CommandEnvVars: commandEnvVars,
695-
StateEnvVars: stateEnvVars,
696-
RequestedBy: actor,
697-
Namespace: repository,
698-
EventName: "drift-detect",
687+
ProjectName: projectConfig.Name,
688+
ProjectDir: projectConfig.Dir,
689+
ProjectWorkspace: projectConfig.Workspace,
690+
Terragrunt: projectConfig.Terragrunt,
691+
OpenTofu: projectConfig.OpenTofu,
692+
Commands: []string{"digger drift-detect"},
693+
ApplyStage: orchestrator.ToConfigStage(workflow.Apply),
694+
PlanStage: orchestrator.ToConfigStage(workflow.Plan),
695+
CommandEnvVars: commandEnvVars,
696+
StateEnvVars: stateEnvVars,
697+
RequestedBy: actor,
698+
Namespace: repository,
699+
EventName: "drift-detect",
699700
CommandEnvProvider: CommandEnvProvider,
700701
StateEnvProvider: StateEnvProvider,
701702
}
@@ -887,7 +888,8 @@ func newPlanStorage(ghToken string, ghRepoOwner string, ghRepositoryName string,
887888
var planStorage core_storage.PlanStorage
888889

889890
uploadDestination := strings.ToLower(os.Getenv("PLAN_UPLOAD_DESTINATION"))
890-
if uploadDestination == "github" {
891+
switch {
892+
case uploadDestination == "github":
891893
zipManager := utils.Zipper{}
892894
planStorage = &storage.GithubPlanStorage{
893895
Client: github.NewTokenClient(context.Background(), ghToken),
@@ -896,19 +898,33 @@ func newPlanStorage(ghToken string, ghRepoOwner string, ghRepositoryName string,
896898
PullRequestNumber: *prNumber,
897899
ZipManager: zipManager,
898900
}
899-
} else if uploadDestination == "gcp" {
901+
case uploadDestination == "gcp":
900902
ctx, client := gcp.GetGoogleStorageClient()
901903
bucketName := strings.ToLower(os.Getenv("GOOGLE_STORAGE_BUCKET"))
902904
if bucketName == "" {
903-
reportErrorAndExit(requestedBy, fmt.Sprintf("GOOGLE_STORAGE_BUCKET is not defined"), 9)
905+
reportErrorAndExit(requestedBy, "GOOGLE_STORAGE_BUCKET is not defined", 9)
904906
}
905907
bucket := client.Bucket(bucketName)
906908
planStorage = &storage.PlanStorageGcp{
907909
Client: client,
908910
Bucket: bucket,
909911
Context: ctx,
910912
}
911-
} else if uploadDestination == "gitlab" {
913+
case uploadDestination == "aws":
914+
ctx, client, err := storage.GetAWSStorageClient()
915+
if err != nil {
916+
reportErrorAndExit(requestedBy, fmt.Sprintf("Failed to create AWS storage client: %s", err), 9)
917+
}
918+
bucketName := strings.ToLower(os.Getenv("AWS_S3_BUCKET"))
919+
if bucketName == "" {
920+
reportErrorAndExit(requestedBy, "AWS_S3_BUCKET is not defined", 9)
921+
}
922+
planStorage = &storage.PlanStorageAWS{
923+
Context: ctx,
924+
Client: client,
925+
Bucket: bucketName,
926+
}
927+
case uploadDestination == "gitlab":
912928
//TODO implement me
913929
}
914930

cli/go.mod

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ require (
1919
)
2020

2121
require (
22+
github.com/aws/aws-sdk-go-v2 v1.26.1
23+
github.com/aws/aws-sdk-go-v2/config v1.27.11
24+
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
25+
github.com/aws/smithy-go v1.20.2
2226
github.com/caarlos0/env/v8 v8.0.0
2327
github.com/diggerhq/digger/libs v0.4.13
2428
github.com/dominikbraun/graph v0.23.0
25-
github.com/goccy/go-json v0.10.2
2629
github.com/google/go-github/v58 v58.0.0
27-
github.com/google/go-github/v59 v59.0.0
28-
github.com/google/go-github/v60 v60.0.0
2930
github.com/spf13/cobra v1.8.0
3031
github.com/spf13/pflag v1.0.5
3132
github.com/spf13/viper v1.18.2
33+
gotest.tools/v3 v3.0.3
3234
)
3335

3436
require (
@@ -51,6 +53,20 @@ require (
5153
github.com/apparentlymart/go-versions v1.0.1 // indirect
5254
github.com/armon/go-metrics v0.4.1 // indirect
5355
github.com/armon/go-radix v1.0.0 // indirect
56+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
57+
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
58+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
59+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
60+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
61+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
62+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
63+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
64+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
65+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
66+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
67+
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
68+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
69+
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
5470
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
5571
github.com/blang/semver v3.5.1+incompatible // indirect
5672
github.com/bmatcuk/doublestar v1.3.1 // indirect
@@ -60,9 +76,9 @@ require (
6076
github.com/dimchansky/utfbom v1.1.1 // indirect
6177
github.com/fatih/color v1.15.0 // indirect
6278
github.com/felixge/httpsnoop v1.0.4 // indirect
63-
github.com/frankban/quicktest v1.14.6 // indirect
6479
github.com/fsnotify/fsnotify v1.7.0 // indirect
6580
github.com/go-errors/errors v1.4.2 // indirect
81+
github.com/goccy/go-json v0.10.2 // indirect
6682
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
6783
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
6884
github.com/golang/snappy v0.0.4 // indirect
@@ -74,7 +90,7 @@ require (
7490
github.com/gruntwork-io/terragrunt v0.54.11 // indirect
7591
github.com/gruntwork-io/terratest v0.41.0 // indirect
7692
github.com/hashicorp/errwrap v1.1.0 // indirect
77-
github.com/hashicorp/go-getter v1.7.3 // indirect
93+
github.com/hashicorp/go-getter v1.7.4 // indirect
7894
github.com/hashicorp/go-hclog v1.5.0 // indirect
7995
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
8096
github.com/hashicorp/go-multierror v1.1.1 // indirect
@@ -109,7 +125,6 @@ require (
109125
github.com/mattn/go-colorable v0.1.13 // indirect
110126
github.com/mattn/go-isatty v0.0.18 // indirect
111127
github.com/mattn/go-zglob v0.0.3 // indirect
112-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
113128
github.com/mitchellh/copystructure v1.2.0 // indirect
114129
github.com/mitchellh/go-homedir v1.1.0 // indirect
115130
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
@@ -194,7 +209,6 @@ require (
194209
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
195210
github.com/jmespath/go-jmespath v0.4.0 // indirect
196211
github.com/kylelemons/godebug v1.1.0 // indirect
197-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
198212
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
199213
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
200214
github.com/prometheus/client_golang v1.19.0 // indirect
@@ -217,7 +231,6 @@ require (
217231
golang.org/x/sys v0.18.0 // indirect
218232
golang.org/x/text v0.14.0 // indirect
219233
golang.org/x/time v0.5.0 // indirect
220-
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
221234
google.golang.org/api v0.167.0 // indirect
222235
google.golang.org/appengine v1.6.8 // indirect
223236
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect

0 commit comments

Comments
 (0)