terraform-provider-google/google/resource_logging_billing_account_sink.go
Chris Stephens 30773a784d 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.
2018-09-06 09:48:48 -07:00

81 lines
2.3 KiB
Go

package google
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceLoggingBillingAccountSink() *schema.Resource {
schm := &schema.Resource{
Create: resourceLoggingBillingAccountSinkCreate,
Read: resourceLoggingBillingAccountSinkRead,
Delete: resourceLoggingBillingAccountSinkDelete,
Update: resourceLoggingBillingAccountSinkUpdate,
Schema: resourceLoggingSinkSchema(),
Importer: &schema.ResourceImporter{
State: resourceLoggingSinkImportState("billing_account"),
},
}
schm.Schema["billing_account"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
}
return schm
}
func resourceLoggingBillingAccountSinkCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
id, sink := expandResourceLoggingSink(d, "billingAccounts", d.Get("billing_account").(string))
// The API will reject any requests that don't explicitly set 'uniqueWriterIdentity' to true.
_, err := config.clientLogging.BillingAccounts.Sinks.Create(id.parent(), sink).UniqueWriterIdentity(true).Do()
if err != nil {
return err
}
d.SetId(id.canonicalId())
return resourceLoggingBillingAccountSinkRead(d, meta)
}
func resourceLoggingBillingAccountSinkRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
sink, err := config.clientLogging.BillingAccounts.Sinks.Get(d.Id()).Do()
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("Billing Logging Sink %s", d.Get("name").(string)))
}
flattenResourceLoggingSink(d, sink)
return nil
}
func resourceLoggingBillingAccountSinkUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
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).
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(true).Do()
if err != nil {
return err
}
return resourceLoggingBillingAccountSinkRead(d, meta)
}
func resourceLoggingBillingAccountSinkDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
_, err := config.clientLogging.Projects.Sinks.Delete(d.Id()).Do()
if err != nil {
return err
}
return nil
}