Skip to content

Clean up google_project_usage_export_bucket code and docs. #1922

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions google/resource_usage_export_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func resourceProjectUsageBucket() *schema.Resource {
Read: resourceProjectUsageBucketRead,
Delete: resourceProjectUsageBucketDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
State: resourceProjectUsageBucketImportState,
},

Schema: map[string]*schema.Schema{
Expand All @@ -40,7 +40,11 @@ func resourceProjectUsageBucket() *schema.Resource {

func resourceProjectUsageBucketRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project := d.Id()

project, err := getProject(d, config)
if err != nil {
return err
}

p, err := config.clientCompute.Projects.Get(project).Do()
if err != nil {
Expand All @@ -60,6 +64,7 @@ func resourceProjectUsageBucketRead(d *schema.ResourceData, meta interface{}) er

func resourceProjectUsageBucketCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

project, err := getProject(d, config)
if err != nil {
return err
Expand All @@ -86,18 +91,29 @@ func resourceProjectUsageBucketCreate(d *schema.ResourceData, meta interface{})

func resourceProjectUsageBucketDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project := d.Id()

project, err := getProject(d, config)
if err != nil {
return err
}

op, err := config.clientCompute.Projects.SetUsageExportBucket(project, nil).Do()
if err != nil {
return err
}
d.SetId(project)
err = computeOperationWait(config.clientCompute, op, project, "Setting usage export bucket.")

err = computeOperationWait(config.clientCompute, op, project,
"Setting usage export bucket to nil, automatically disabling usage export.")
if err != nil {
return err
}
d.SetId("")

return nil
}

func resourceProjectUsageBucketImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
project := d.Id()
d.Set("project", project)
return []*schema.ResourceData{d}, nil
}
27 changes: 18 additions & 9 deletions website/docs/r/usage_export_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: "google"
page_title: "Google: google_project_usage_export_bucket"
sidebar_current: "docs-google-project-usage-export-bucket"
description: |-
Creates a dataset resource for Google BigQuery.
Manages a project's usage export bucket.
---

# google_project_usage_export_bucket
Expand All @@ -16,23 +16,32 @@ For more information see the [Docs](https://cloud.google.com/compute/docs/usage-
and for further details, the
[API Documentation](https://cloud.google.com/compute/docs/reference/rest/beta/projects/setUsageExportBucket).

~> **Note:** You should specify only one of these per project. If there are two or more
they will fight over which bucket the reports should be stored in. It is
safe to have multiple resources with the same backing bucket.

## Example Usage

```hcl
resource "google_project_usage_export_bucket" "export" {
project = "foo"
bucket_name = "bar"
resource "google_project_usage_export_bucket" "usage_export" {
project = "development-project"
bucket_name = "usage-tracking-bucket"
}
```

## Argument Reference
* `project`: (Required) The project to set the export bucket on.
* `bucket_name`: (Required) The bucket to store reports in.

- - -

* `prefix`: (Optional) A prefix for the reports, for instance, the project name.

## Note
* `project`: (Optional) The project to set the export bucket on. If it is not provided, the provider project is used.

You should specify only one of these per project. If there are two or more
they will fight over which bucket the reports should be stored in. It is
safe to have multiple resources with the same backing bucket.
## Import

A project's Usage Export Bucket can be imported using this format:

```
$ terraform import google_project_usage_export_bucket.usage_export {{project}}
```