mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
![Chris Stephens](/assets/img/avatar_default.png)
[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.
107 lines
2.6 KiB
Go
107 lines
2.6 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
)
|
|
|
|
const nonUniqueWriterAccount = "serviceAccount:cloud-logs@system.gserviceaccount.com"
|
|
|
|
func resourceLoggingProjectSink() *schema.Resource {
|
|
schm := &schema.Resource{
|
|
Create: resourceLoggingProjectSinkCreate,
|
|
Read: resourceLoggingProjectSinkRead,
|
|
Delete: resourceLoggingProjectSinkDelete,
|
|
Update: resourceLoggingProjectSinkUpdate,
|
|
Schema: resourceLoggingSinkSchema(),
|
|
Importer: &schema.ResourceImporter{
|
|
State: resourceLoggingSinkImportState("project"),
|
|
},
|
|
}
|
|
schm.Schema["project"] = &schema.Schema{
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Computed: true,
|
|
ForceNew: true,
|
|
}
|
|
schm.Schema["unique_writer_identity"] = &schema.Schema{
|
|
Type: schema.TypeBool,
|
|
Optional: true,
|
|
Default: false,
|
|
ForceNew: true,
|
|
}
|
|
return schm
|
|
}
|
|
|
|
func resourceLoggingProjectSinkCreate(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
|
|
project, err := getProject(d, config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
id, sink := expandResourceLoggingSink(d, "projects", project)
|
|
uniqueWriterIdentity := d.Get("unique_writer_identity").(bool)
|
|
|
|
_, err = config.clientLogging.Projects.Sinks.Create(id.parent(), sink).UniqueWriterIdentity(uniqueWriterIdentity).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId(id.canonicalId())
|
|
|
|
return resourceLoggingProjectSinkRead(d, meta)
|
|
}
|
|
|
|
func resourceLoggingProjectSinkRead(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
|
|
project, err := getProject(d, config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sink, err := config.clientLogging.Projects.Sinks.Get(d.Id()).Do()
|
|
if err != nil {
|
|
return handleNotFoundError(err, d, fmt.Sprintf("Project Logging Sink %s", d.Get("name").(string)))
|
|
}
|
|
|
|
d.Set("project", project)
|
|
flattenResourceLoggingSink(d, sink)
|
|
if sink.WriterIdentity != nonUniqueWriterAccount {
|
|
d.Set("unique_writer_identity", true)
|
|
} else {
|
|
d.Set("unique_writer_identity", false)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func resourceLoggingProjectSinkUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
|
|
sink := expandResourceLoggingSinkForUpdate(d)
|
|
uniqueWriterIdentity := d.Get("unique_writer_identity").(bool)
|
|
|
|
_, err := config.clientLogging.Projects.Sinks.Patch(d.Id(), sink).
|
|
UpdateMask(defaultLogSinkUpdateMask).UniqueWriterIdentity(uniqueWriterIdentity).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return resourceLoggingProjectSinkRead(d, meta)
|
|
}
|
|
|
|
func resourceLoggingProjectSinkDelete(d *schema.ResourceData, meta interface{}) error {
|
|
config := meta.(*Config)
|
|
|
|
_, err := config.clientLogging.Projects.Sinks.Delete(d.Id()).Do()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.SetId("")
|
|
return nil
|
|
}
|