-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Storage Notification Resource #1033
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ba3c60c
Storage Default Object ACL resource
ishashchuk 19912ec
Fixed the doc
ishashchuk 6810e53
Renamed the resource id. Log change
ishashchuk 2c80aee
Merged latest upstream changes into the branch
ishashchuk 58c7e0e
Merge pull request #1 from wayfair/storage_default_acl
amoiseiev e7cebf7
Complying with go vet
ishashchuk 5e35381
Changes for review
ishashchuk c702a73
Merge remote-tracking branch 'upstream/master'
ishashchuk bca2b1b
Merge pull request #2 from wayfair/ishashchuk_storage_defaul_acl
amoiseiev a89bc5d
link to default object acl docs in sidebar
danawillow 61d2db7
Support for GCS notifications
ishashchuk bff7fd5
Merge remote-tracking branch 'upstream/master'
ishashchuk 5c1e5b9
Merge branch 'master' into ishashchuk_storage_notifications
ishashchuk 14ebfc9
docs for storage notification
ishashchuk 7f5951c
docs for storage notification
ishashchuk 79a38d9
Clarified the doc
ishashchuk d224374
Doc modifications
ishashchuk d7ec385
Merge pull request #3 from wayfair/ishashchuk_storage_notifications
amoiseiev f153c0f
Addressing requested changes from review
ishashchuk e5a0d27
Merge pull request #4 from wayfair/ishashchuk_storage_notifications
amoiseiev 0d00aff
Addressing requested changes from review
ishashchuk 93dd896
Merge pull request #6 from wayfair/ishashchuk_notifications
amoiseiev 4794d18
Using ImportStatePassthrough
ishashchuk c4b6a26
Merge pull request #7 from wayfair/ishashchuk_notifications
amoiseiev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,157 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"google.golang.org/api/storage/v1" | ||
) | ||
|
||
func resourceStorageNotification() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceStorageNotificationCreate, | ||
Read: resourceStorageNotificationRead, | ||
Delete: resourceStorageNotificationDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: resourceStorageNotificationImportState, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"bucket": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"payload_format": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{"JSON_API_V1", "NONE"}, false), | ||
}, | ||
|
||
"topic": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: compareSelfLinkOrResourceName, | ||
}, | ||
|
||
"custom_attributes": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"event_types": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"OBJECT_FINALIZE", "OBJECT_METADATA_UPDATE", "OBJECT_DELETE", "OBJECT_ARCHIVE"}, | ||
false), | ||
}, | ||
}, | ||
|
||
"object_name_prefix": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"self_link": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceStorageNotificationCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
bucket := d.Get("bucket").(string) | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
computedTopicName := getComputedTopicName(project, d.Get("topic").(string)) | ||
|
||
storageNotification := &storage.Notification{ | ||
CustomAttributes: expandStringMap(d, "custom_attributes"), | ||
EventTypes: convertStringSet(d.Get("event_types").(*schema.Set)), | ||
ObjectNamePrefix: d.Get("object_name_prefix").(string), | ||
PayloadFormat: d.Get("payload_format").(string), | ||
Topic: computedTopicName, | ||
} | ||
|
||
res, err := config.clientStorage.Notifications.Insert(bucket, storageNotification).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error creating notification config for bucket %s: %v", bucket, err) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%s/notificationConfigs/%s", bucket, res.Id)) | ||
|
||
return resourceStorageNotificationRead(d, meta) | ||
} | ||
|
||
func resourceStorageNotificationRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
bucket, notificationID := resourceStorageNotificationParseID(d.Id()) | ||
|
||
res, err := config.clientStorage.Notifications.Get(bucket, notificationID).Do() | ||
if err != nil { | ||
return handleNotFoundError(err, d, fmt.Sprintf("Notification configuration %s for bucket %s", notificationID, bucket)) | ||
} | ||
|
||
d.Set("payload_format", res.PayloadFormat) | ||
d.Set("topic", res.Topic) | ||
d.Set("object_name_prefix", res.ObjectNamePrefix) | ||
d.Set("event_types", res.EventTypes) | ||
d.Set("self_link", res.SelfLink) | ||
d.Set("custom_attributes", res.CustomAttributes) | ||
|
||
return nil | ||
} | ||
|
||
func resourceStorageNotificationDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
bucket, notificationID := resourceStorageNotificationParseID(d.Id()) | ||
|
||
err := config.clientStorage.Notifications.Delete(bucket, notificationID).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error deleting notification configuration %s for bucket %s: %v", notificationID, bucket, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceStorageNotificationImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be removed now (you can just set the importer to schema.ImportStatePassthrough, see other resources for examples), and then you can do the |
||
bucket, _ := resourceStorageNotificationParseID(d.Id()) | ||
|
||
d.Set("bucket", bucket) | ||
|
||
if err := resourceStorageNotificationRead(d, meta); err != nil { | ||
return nil, err | ||
} | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} | ||
|
||
func resourceStorageNotificationParseID(id string) (string, string) { | ||
//bucket, NotificationID | ||
parts := strings.Split(id, "/") | ||
|
||
return parts[0], parts[2] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a DiffSuppressFunc here? Example in PubSub topic resource