-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data source for cloud bucket object
- Loading branch information
1 parent
2f490f0
commit c86a3da
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters