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

(terraform-providers/terraform-provider-aws#11986) Add ability to enable/disable logging config #11987

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion aws/cloudfront_distribution_configuration_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,14 @@ func expandLoggingConfig(m map[string]interface{}) *cloudfront.LoggingConfig {
lc.Prefix = aws.String(m["prefix"].(string))
lc.Bucket = aws.String(m["bucket"].(string))
lc.IncludeCookies = aws.Bool(m["include_cookies"].(bool))
lc.Enabled = aws.Bool(true)

var rawEnableFlag interface{} = m["enabled"]
if rawEnableFlag != nil {
lc.Enabled = aws.Bool(rawEnableFlag.(bool))
} else {
lc.Enabled = aws.Bool(true) // preserve backwards compatibility
}

} else {
lc.Prefix = aws.String("")
lc.Bucket = aws.String("")
Expand Down
27 changes: 27 additions & 0 deletions aws/cloudfront_distribution_configuration_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ func loggingConfigConf() map[string]interface{} {
}
}

func loggingConfigConfDisabled() map[string]interface{} {
return map[string]interface{}{
"include_cookies": false,
"bucket": "mylogs.s3.amazonaws.com",
"prefix": "myprefix",
"enabled": false,
}
}

func customErrorResponsesConfSet() *schema.Set {
return schema.NewSet(customErrorResponseHash, customErrorResponsesConf())
}
Expand Down Expand Up @@ -848,6 +857,24 @@ func TestCloudFrontStructure_expandLoggingConfig(t *testing.T) {
}
}

func TestCloudFrontStructure_expandLoggingConfigDisabled(t *testing.T) {
data := loggingConfigConfDisabled()

lc := expandLoggingConfig(data)
if *lc.Enabled {
t.Fatalf("Expected Enabled to be false, got %v", *lc.Enabled)
}
if *lc.Prefix != "myprefix" {
t.Fatalf("Expected Prefix to be myprefix, got %v", *lc.Prefix)
}
if *lc.Bucket != "mylogs.s3.amazonaws.com" {
t.Fatalf("Expected Bucket to be mylogs.s3.amazonaws.com, got %v", *lc.Bucket)
}
if *lc.IncludeCookies {
t.Fatalf("Expected IncludeCookies to be false, got %v", *lc.IncludeCookies)
}
}

func TestCloudFrontStructure_expandLoggingConfig_nilValue(t *testing.T) {
lc := expandLoggingConfig(nil)
if *lc.Enabled {
Expand Down