Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to compress state file for s3 remote state #20329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SebastianCzoch
Copy link

@SebastianCzoch SebastianCzoch commented Feb 13, 2019

Thanks to that option (optional, default to false), we will be able to use gzip compression for state file.
More info available in feature request #20328

Acceptance tests output

$ make testacc TEST=./backend/remote-state/s3 TESTARGS='-run=TestRemoteClient_stateChecksum'
TF_ACC=1 go test ./backend/remote-state/s3 -v -run=TestRemoteClient_stateChecksum -mod=vendor -timeout 120m
=== RUN   TestRemoteClient_stateChecksum
=== RUN   TestRemoteClient_stateChecksum/with_compression
=== RUN   TestRemoteClient_stateChecksum/without_compression
--- PASS: TestRemoteClient_stateChecksum (31.97s)
    --- PASS: TestRemoteClient_stateChecksum/with_compression (17.22s)
        client_test.go:225: TestBackendConfig on *s3.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("terraform-remote-s3-test-5c647859"), "compression":cty.True, "dynamodb_table":cty.StringVal("terraform-remote-s3-test-5c647859"), "key":cty.StringVal("te
stState")}}
        backend_test.go:370: creating S3 bucket terraform-remote-s3-test-5c647859 in eu-west-2
        client_test.go:258: TestBackendConfig on *s3.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("terraform-remote-s3-test-5c647859"), "key":cty.StringVal("testState")}}
    --- PASS: TestRemoteClient_stateChecksum/without_compression (14.76s)
        client_test.go:225: TestBackendConfig on *s3.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("terraform-remote-s3-test-5c64786a"), "compression":cty.False, "dynamodb_table":cty.StringVal("terraform-remote-s3-test-5c64786a"), "key":cty.StringVal("t
estState")}}
        backend_test.go:370: creating S3 bucket terraform-remote-s3-test-5c64786a in eu-west-2
        client_test.go:258: TestBackendConfig on *s3.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("terraform-remote-s3-test-5c64786a"), "key":cty.StringVal("testState")}}
PASS
ok      github.com/hashicorp/terraform/backend/remote-state/s3  32.017s

Logs truncated

Solves #20328

@hashicorp-cla
Copy link

hashicorp-cla commented Feb 13, 2019

CLA assistant check
All committers have signed the CLA.

@j3parker
Copy link

j3parker commented Mar 9, 2021

Bump on this? (from Hashicorp, really.)

I would make two slight modifications:

  • Set the Content-Encoding metadata on the object to gzip when doing PutObject (but don't set it to anything if compression isn't enabled): this would be the most compatible with other tools. For example, in an extreme case, if you're proxying the bucket over HTTP for some reason browsers will transparently handle Content-Encoding.
  • When fetching the state I like how you're not paying attention to the compression flag -- this makes it easier to migrate. I would maybe be a bit more strict and decompress if-and-only-if the Content-Encoding metadata for the response object is gzip.

It would be nice to default to compression but I doubt Hashicorp would go for that :)

@crw crw added backend/s3 and removed backend/s3 labels Aug 29, 2024
"compression": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable gzip compression before sending sate file into bucket",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Description: "Enable gzip compression before sending sate file into bucket",
Description: "Enable gzip compression before sending state file into bucket",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants