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 support for setting bucket's logging config #946

Merged
merged 2 commits into from
Jan 25, 2018
Merged

Add support for setting bucket's logging config #946

merged 2 commits into from
Jan 25, 2018

Conversation

skinp
Copy link
Contributor

@skinp skinp commented Jan 11, 2018

Mostly self explanatory, this enables setting up which bucket to log access/storage logs to.

In theory, GCP also allows us to set a log_object_prefix. Unfortunately I couldn't easily get this working, so this is a first step. It's also why logging ends up being a TypeList instead of TypeString... to allow for future support of log_object_prefix.

Setting log_object_prefix wasn't obvious for the following reasons... In theory, this should an optional field but GCP sets it to the bucket name by default. It wasn't straightforward to go back and forth from an explicitly set value to the default because the expected TF state is "" but GCP reports it as the bucket name. It seems like the easiest approach would be to set a Default(Func) value for log_object_prefix dynamically to be the bucket's name, but I couldn't figure out how to make this work. Open for suggestions here...

@rosbo rosbo self-assigned this Jan 11, 2018
@amoiseiev
Copy link

Added an issue for this pull request, for tracking purposes on our end: #972

@skinp
Copy link
Contributor Author

skinp commented Jan 24, 2018

@rosbo friendly bump?
I'm not sure we need to care about log_object_prefix immediately, it'd be useful for completeness, but just adding log_bucket support by itself is a step in the right direction I think (I just use log_bucket myself, not the prefix).

@rosbo rosbo assigned danawillow and unassigned rosbo Jan 24, 2018
Copy link
Contributor

@danawillow danawillow left a comment

Choose a reason for hiding this comment

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

Thanks @skinp, looks good! Just one quick nit.

Also, for log_object_prefix, setting the value as Computed would be a start (it would stop having diffs between empty and the default), but it does mean that if you set it to a custom value it won't show a diff if you try to set it back to the default. I'm generally in favor of having something that works most of the time now instead of something that works all the time later, but if you'd like to get something that works all the time check out some of the customdiff helpers (example from within our codebase here)

if v, ok := d.GetOk("logging"); ok {
sb.Logging = expandBucketLogging(v.([]interface{}))
}
if sb.Logging == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can just be else, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, will fix

@skinp
Copy link
Contributor Author

skinp commented Jan 25, 2018

Right, I toyed with Computed for awhile but couldn't get it to revert back to the default if I removed the explicit config like you're describing. I'll go with the "something that works most of the time" for now.

@skinp
Copy link
Contributor Author

skinp commented Jan 25, 2018

Test run fwiw.

$ make testacc TEST=./google TESTARGS='-run=TestAccStorageBucket_' GOOGLE_USE_DEFAULT_CREDENTIALS=true
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./google -v -run=TestAccStorageBucket_ -timeout 120m
=== RUN   TestAccStorageBucket_basic
=== RUN   TestAccStorageBucket_lowercaseLocation
=== RUN   TestAccStorageBucket_customAttributes
=== RUN   TestAccStorageBucket_lifecycleRules
=== RUN   TestAccStorageBucket_storageClass
=== RUN   TestAccStorageBucket_update
=== RUN   TestAccStorageBucket_forceDestroy
=== RUN   TestAccStorageBucket_versioning
=== RUN   TestAccStorageBucket_logging
=== RUN   TestAccStorageBucket_cors
=== RUN   TestAccStorageBucket_labels
--- PASS: TestAccStorageBucket_lifecycleRules (4.15s)
--- PASS: TestAccStorageBucket_basic (4.17s)
--- PASS: TestAccStorageBucket_cors (2.91s)
--- PASS: TestAccStorageBucket_forceDestroy (15.21s)
--- PASS: TestAccStorageBucket_logging (16.47s)
--- PASS: TestAccStorageBucket_update (25.86s)
--- PASS: TestAccStorageBucket_versioning (12.97s)
--- PASS: TestAccStorageBucket_labels (24.35s)
--- PASS: TestAccStorageBucket_customAttributes (5.43s)
--- PASS: TestAccStorageBucket_lowercaseLocation (5.33s)
--- PASS: TestAccStorageBucket_storageClass (8.70s)
PASS
ok  	github.com/terraform-providers/terraform-provider-google/google	37.028s

@danawillow
Copy link
Contributor

Thanks @skinp! Merging now.

@danawillow danawillow merged commit eaac260 into hashicorp:master Jan 25, 2018
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Add support for setting bucket's logging config

* Add log_object_prefix and fix nil Logging condition
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Sep 27, 2019
Signed-off-by: Modular Magician <magic-modules@google.com>
@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants