Skip to content

Commit

Permalink
fix: state path in s3 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev-snyk committed Jul 12, 2022
1 parent 7ded2d2 commit f4a92e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions pkg/terraform/hcl/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ func (b BackendBlock) parseS3Backend(ws string) *config.SupplierConfig {
if b.Bucket == "" || b.Key == "" {
return nil
}
keyPrefix := ws
if keyPrefix == DefaultStateName {
keyPrefix = ""

keyPrefix := b.WorkspaceKeyPrefix
if ws != DefaultStateName {
if b.WorkspaceKeyPrefix == "" {
b.WorkspaceKeyPrefix = "env:"
}
keyPrefix = path.Join(b.WorkspaceKeyPrefix, ws)
}

return &config.SupplierConfig{
Key: state.TerraformStateReaderSupplier,
Backend: backend.BackendKeyS3,
Path: path.Join(b.Bucket, b.WorkspaceKeyPrefix, keyPrefix, b.Key),
Path: path.Join(b.Bucket, keyPrefix, b.Key),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/terraform/hcl/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestBackend_SupplierConfig(t *testing.T) {
want: &config.SupplierConfig{
Key: "tfstate",
Backend: "s3",
Path: "terraform-state-prod/bar/network/terraform.tfstate",
Path: "terraform-state-prod/env:/bar/network/terraform.tfstate",
},
},
{
Expand Down

0 comments on commit f4a92e7

Please sign in to comment.