Setting a default update_mask for all log sinks

[According to log sink documentation](https://cloud.google.com/logging/docs/reference/v2/rest/v2/sinks/update)
the api will eventually throw an error if update mask isn't provided. The
default specified here is what the api is currently using when an empty mask
is passed.
This commit is contained in:
Chris Stephens 2018-08-30 13:54:54 -07:00
parent 3f906b3c8d
commit 30773a784d
6 changed files with 15 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package google
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
@ -58,7 +59,8 @@ func resourceLoggingBillingAccountSinkUpdate(d *schema.ResourceData, meta interf
sink := expandResourceLoggingSinkForUpdate(d)
// The API will reject any requests that don't explicitly set 'uniqueWriterIdentity' to true.
_, err := config.clientLogging.BillingAccounts.Sinks.Patch(d.Id(), sink).UniqueWriterIdentity(true).Do()
_, err := config.clientLogging.BillingAccounts.Sinks.Patch(d.Id(), sink).
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(true).Do()
if err != nil {
return err
}

View File

@ -77,7 +77,8 @@ func resourceLoggingFolderSinkUpdate(d *schema.ResourceData, meta interface{}) e
sink.ForceSendFields = append(sink.ForceSendFields, "IncludeChildren")
// The API will reject any requests that don't explicitly set 'uniqueWriterIdentity' to true.
_, err := config.clientLogging.Folders.Sinks.Patch(d.Id(), sink).UniqueWriterIdentity(true).Do()
_, err := config.clientLogging.Folders.Sinks.Patch(d.Id(), sink).
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(true).Do()
if err != nil {
return err
}

View File

@ -77,7 +77,8 @@ func resourceLoggingOrganizationSinkUpdate(d *schema.ResourceData, meta interfac
sink.ForceSendFields = append(sink.ForceSendFields, "IncludeChildren")
// The API will reject any requests that don't explicitly set 'uniqueWriterIdentity' to true.
_, err := config.clientLogging.Organizations.Sinks.Patch(d.Id(), sink).UniqueWriterIdentity(true).Do()
_, err := config.clientLogging.Organizations.Sinks.Patch(d.Id(), sink).
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(true).Do()
if err != nil {
return err
}

View File

@ -84,7 +84,8 @@ func resourceLoggingProjectSinkUpdate(d *schema.ResourceData, meta interface{})
sink := expandResourceLoggingSinkForUpdate(d)
uniqueWriterIdentity := d.Get("unique_writer_identity").(bool)
_, err := config.clientLogging.Projects.Sinks.Patch(d.Id(), sink).UniqueWriterIdentity(uniqueWriterIdentity).Do()
_, err := config.clientLogging.Projects.Sinks.Patch(d.Id(), sink).
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(uniqueWriterIdentity).Do()
if err != nil {
return err
}

View File

@ -5,6 +5,9 @@ import (
"google.golang.org/api/logging/v2"
)
// Empty update masks will eventually cause updates to fail, currently empty masks default to this string
const defaultLogSinkUpdateMask = "destination,filter,includeChildren"
func resourceLoggingSinkSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {

View File

@ -14,8 +14,9 @@ Manages a project-level logging sink. For more information see
and
[API](https://cloud.google.com/logging/docs/reference/v2/rest/).
Note that you must have the "Logs Configuration Writer" IAM role (`roles/logging.configWriter`)
granted to the credentials used with terraform.
~> **Note:** You must have [granted the "Logs Configuration Writer"](https://cloud.google.com/logging/docs/access-control) IAM role (`roles/logging.configWriter`) to the credentials used with terraform.
~> **Note** You must [enable the Cloud Resource Manager API](https://console.cloud.google.com/apis/library/cloudresourcemanager.googleapis.com)
## Example Usage