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 stackdriver project sink support #432

Merged
merged 10 commits into from
Sep 15, 2017

Conversation

selmanj
Copy link
Contributor

@selmanj selmanj commented Sep 13, 2017

This adds support for management of Stackdriver Logging sinks. The use case is to setup logging exports to buckets, pubsub topics or bigtable datasets.

See the example in the logging_project_sink.html.markdown file for an example of using terraform to manage logging a VM.

Adding followup support for logging folders, organizations, billingAccounts etc should be easier once this initial sink is checked in.

Documentation: https://cloud.google.com/logging/docs/api/tasks/exporting-logs


# google\_logging\_project\_sink

Manages a project-level logging sink.. For more information see
Copy link
Contributor

Choose a reason for hiding this comment

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

typo ".."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, fixed

Name: d.Get("name").(string),
Destination: d.Get("destination").(string),
}
if v, ok := d.GetOk("filter"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need this if block? d.Get("filter") will return "" and should work without this extra if block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's easier to read. Fixed.

// LoggingSinkId represents the parts that make up the canonical id used within terraform for a logging resource.
type LoggingSinkId struct {
typ string
typName string
Copy link
Contributor

Choose a reason for hiding this comment

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

In the docs, the parent parameter documentation says:

The resource in which to create the sink:
"projects/[PROJECT_ID]"
"organizations/[ORGANIZATION_ID]"
"billingAccounts/[BILLING_ACCOUNT_ID]"
"folders/[FOLDER_ID]"

Instead of type, we could use resource.

resourceType instead of typ
resourceId instead of typName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your names are much better! Fixed.

@rosbo
Copy link
Contributor

rosbo commented Sep 13, 2017

Very good. Just some minor typos and suggestions.

config := meta.(*Config)

sink, err := config.clientLogging.Projects.Sinks.Get(d.Id()).Do()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch; added

return nil
}

func testAccCheckLoggingProjectSinkExists(n string, sink *logging.LogSink) resource.TestCheckFunc {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since everything this function does is also in the next one, is it worth it to keep them separate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept them separate for now since testAccCheckLoggingProjectSinkExists assigns the found api object to a provided *logging.LogSink parameter and testAccCheckLoggingProjectSink checks the remote object against the locally stored attributes

However, since they both look up the api object I changed testAccCheckLoggingProjectSink to take an api object as the first parameter; now it does less duplicate work

}

func testAccLoggingProjectSink_basic(name, bucketName string) string {
return fmt.Sprintf(`resource "google_logging_project_sink" "basic" {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you put a line break after the `? (makes it easier to see what's going on and copy and paste too) (here and elsewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


resource "google_storage_bucket" "log-bucket" {
name = "%s"
}`, name, getTestProjectFromEnv(), bucketName)
Copy link
Contributor

Choose a reason for hiding this comment

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

likewise, line break before the `

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

})
}

func TestAccLoggingProjectSink_updateUniqueWriter(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this updating the bucket (/ the destination), not the unique writer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it is. The test is poorly named. I changed it to '_updatePreservesUniqueWriter' (as that's explicitly tested)

resource "google_logging_project_sink" "my-sink" {
name = "my-pubsub-instance-sink"

// Can export to pubsub, cloud storage, or bigtable
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah apparently it also accepts // as i've been using them in my hcl unknowingly for a while!

Changed to #

@selmanj selmanj requested a review from danawillow September 14, 2017 17:51
@selmanj selmanj force-pushed the add_stackdriver_project_sink branch from 4a15dd2 to 41415ec Compare September 15, 2017 02:14
@selmanj selmanj merged commit 3d5eccc into hashicorp:master Sep 15, 2017
negz pushed a commit to negz/terraform-provider-google that referenced this pull request Oct 17, 2017
* Vendor cloud logging api

* Add logging sink support

* Remove typo

* Set Filter simpler

* Rename typ, typName to resourceType, resourceId

* Handle notFoundError

* Use # instead of // for hcl comments

* Cleanup test code

* Change testAccCheckLoggingProjectSink to take a provided api object

* Fix whitespace change after merge conflict
chrisst pushed a commit to chrisst/terraform-provider-google that referenced this pull request Nov 9, 2018
* Vendor cloud logging api

* Add logging sink support

* Remove typo

* Set Filter simpler

* Rename typ, typName to resourceType, resourceId

* Handle notFoundError

* Use # instead of // for hcl comments

* Cleanup test code

* Change testAccCheckLoggingProjectSink to take a provided api object

* Fix whitespace change after merge conflict
luis-silva pushed a commit to luis-silva/terraform-provider-google that referenced this pull request May 21, 2019
@ghost
Copy link

ghost commented Mar 31, 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 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants