From 51a4a6eb9183ea8d5a94e568a4cccc052f4220aa Mon Sep 17 00:00:00 2001 From: Jan Ritter Date: Wed, 19 Aug 2020 14:46:51 +0200 Subject: [PATCH 1/2] feat: added support for s3 acl variable --- backend/s3/create.go | 3 ++- backend/s3/parsercall.go | 6 ++++++ backend/s3/types.go | 1 + test/test.tfvars | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/s3/create.go b/backend/s3/create.go index 498073d..6b20d3d 100644 --- a/backend/s3/create.go +++ b/backend/s3/create.go @@ -15,9 +15,10 @@ func createBackendConfigurationFile(in stateConfig) error { {{ if .Region }}region = "{{ .Region }}"{{ end }} {{ if .Key }}key = "{{ .Key }}"{{ end }} {{ if .DynamoDBTable }}dynamodb_table = "{{ .DynamoDBTable }}"{{ end }} + {{ if .ACL }}acl = "{{ .ACL }}"{{ end }} } } - `) +`) if err != nil { color.Red(err.Error()) return err diff --git a/backend/s3/parsercall.go b/backend/s3/parsercall.go index 0dec2b7..d8fe52f 100644 --- a/backend/s3/parsercall.go +++ b/backend/s3/parsercall.go @@ -33,5 +33,11 @@ func callParserForBackendParameters(in interface{}, out *stateConfig) error { } out.Region = helper.GetStringAfterSettingPlaceholderValues(region) + acl, _, err := varParser.GetBackendParameterString("acl", false) + if err != nil { + return err + } + out.ACL = helper.GetStringAfterSettingPlaceholderValues(acl) + return nil } diff --git a/backend/s3/types.go b/backend/s3/types.go index 36ea385..5ab04d0 100644 --- a/backend/s3/types.go +++ b/backend/s3/types.go @@ -5,4 +5,5 @@ type stateConfig struct { DynamoDBTable string Key string Region string + ACL string } diff --git a/test/test.tfvars b/test/test.tfvars index 6cd8e25..9786c7a 100644 --- a/test/test.tfvars +++ b/test/test.tfvars @@ -12,4 +12,6 @@ state_key = "terrastate/{{ current.dir }}/terraform.tfstate" state_auto_remove_old = true +acl = "bucket-owner-full-control" + stage = "test" From a1b028068c23855d6441d27d973dfb32199f9b79 Mon Sep 17 00:00:00 2001 From: Jan Ritter Date: Wed, 19 Aug 2020 14:52:34 +0200 Subject: [PATCH 2/2] refactor: only show given values and made s3 acl optional --- backend/s3/parsercall.go | 2 +- helper/output.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/s3/parsercall.go b/backend/s3/parsercall.go index d8fe52f..2770d31 100644 --- a/backend/s3/parsercall.go +++ b/backend/s3/parsercall.go @@ -33,7 +33,7 @@ func callParserForBackendParameters(in interface{}, out *stateConfig) error { } out.Region = helper.GetStringAfterSettingPlaceholderValues(region) - acl, _, err := varParser.GetBackendParameterString("acl", false) + acl, _, err := varParser.GetBackendParameterString("acl", true) if err != nil { return err } diff --git a/helper/output.go b/helper/output.go index 19aeaf8..8af8020 100644 --- a/helper/output.go +++ b/helper/output.go @@ -11,7 +11,10 @@ func PrintStateValues(in interface{}) { fmt.Println("------- Using the following values -------") for i := 0; i < v.NumField(); i++ { name := v.Type().Field(i).Name - fmt.Printf("%s = %s \n", name, v.Field(i).Interface()) + value := v.Field(i).Interface() + if value != "" { + fmt.Printf("%s = %s \n", name, v.Field(i).Interface()) + } } fmt.Println("------------------------------------------") }