mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
035a581b9f
Fixes #1494. * Add import support for `google_logging_organization_sink`, `google_logging_folder_sink`, `google_logging_billing_account_sink`. Using `StateFunc` over `DiffSuppressFunc` should only affect tests; for some reason `TestAccLoggingFolderSink_folderAcceptsFullFolderPath` expected a `folder` value of `folders/{{id}}` vs expecting `{{id}}` when only `DiffSuppressFunc` was used, when in real use `DiffSuppressFunc` should be sufficient.
79 lines
2.2 KiB
Go
79 lines
2.2 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).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
|
|
}
|