Skip to content

Commit

Permalink
Add data source for cloud bucket object
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisst authored and modular-magician committed Dec 13, 2018
1 parent 2f490f0 commit c86a3da
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions google/data_source_google_storage_bucket_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package google

import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceGoogleStorageBucketObject() *schema.Resource {
return &schema.Resource{
Read: dataSourceGoogleStorageBucketObjectRead,
Schema: map[string]*schema.Schema{
"object": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"bucket": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceGoogleStorageBucketObjectRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
bucket := d.Get("bucket").(string)
object := d.Get("object").(string)

// Using REST apis because the storage go client doesn't support folders
url := fmt.Sprintf("https://www.googleapis.com/storage/v1/b/%s/o/%s", bucket, object)

res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return fmt.Errorf("Error retrieving storage bucket object: %s", err)
}

log.Printf("ZOMG res: %v\n", res)

return nil
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func Provider() terraform.ResourceProvider {
"google_project_services": dataSourceGoogleProjectServices(),
"google_service_account": dataSourceGoogleServiceAccount(),
"google_service_account_key": dataSourceGoogleServiceAccountKey(),
"google_storage_bucket_object": dataSourceGoogleStorageBucketObject(),
"google_storage_object_signed_url": dataSourceGoogleSignedUrl(),
"google_storage_project_service_account": dataSourceGoogleStorageProjectServiceAccount(),
},
Expand Down

0 comments on commit c86a3da

Please sign in to comment.