Skip to content
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

Add retention_policy to storage_bucket #2064

Conversation

megan07
Copy link
Contributor

@megan07 megan07 commented Jul 17, 2019

Added support for retention_policy to google_storage_bucket

Retention Policy attribute is_locked is not able to be set at creation time, but instead requires a call to LockRetentionPolicy and requires the bucket's meta-generation number to be passed in. We get the meta-generation number from the response after our initial create/update. Therefore, we have to make a separate call to the API after our initial creation/update of the bucket.

Another thing to be aware of is, once the retention policy has been locked, it cannot be unlocked.

Release Note for Downstream PRs (will be copied)

add support for `retention_policy` to resource `google_storage_bucket`

@megan07 megan07 requested a review from paddycarver July 18, 2019 14:13
@megan07 megan07 changed the title Megan bucket retention policy Add retention_policy to storage_bucket Jul 22, 2019
@megan07 megan07 requested review from rileykarson and removed request for paddycarver July 22, 2019 20:16
Copy link
Member

@rileykarson rileykarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far- I made a first pass, mostly covering schema. Do you mind update the resource's website docs as well?

if v, ok := d.GetOk("retention_policy"); ok {
retention_policies := v.([]interface{})

if len(retention_policies) > 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid having to check this in CRUD code/catch it at plan time instead of at apply time by using MaxItems in the resource schema.

if d.HasChange("retention_policy") {
// Changing from locked to unlocked is not possible, throw an error
old, new := d.GetChange("retention_policy.0.is_locked")
if old.(bool) && !new.(bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change isn't necessary, but we could actually add a conditional ForceNew using CustomizeDiff. If we perform this check there, we can mark the field with diff.ForceNew, causing Terraform to attempt to destroy + recreate the resource.

This behaviour might be unintuitive, though, since the deletion will only succeed if every object in the bucket is past the retention policy and is removed, and buckets with force_destroy set will probably attempt to remove all the objects and only delete those who've had their policies expire.

@megan07 megan07 requested a review from rileykarson July 23, 2019 19:03
}
}
}

log.Printf("[DEBUG] Created bucket %v at location %v\n\n", res.Name, res.SelfLink)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message is probably worth moving above the SetId call after creation, and we can log that a retention policy lock was enabled here instead.

@@ -554,6 +646,20 @@ func resourceStorageBucketDelete(d *schema.ResourceData, meta interface{}) error
}

if len(res.Items) != 0 {
if d.Get("retention_policy.0.is_locked").(bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job avoiding the possible problem with not-old-enough items 👍

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@megan07 megan07 force-pushed the megan_bucket_retention_policy branch from b176fab to f724217 Compare July 24, 2019 19:48
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
This PR seems not to have generated downstream PRs before, as of 8bc3fe4.

Pull request statuses

No diff detected in terraform-google-conversion.
No diff detected in Ansible.
No diff detected in Inspec.

New Pull Requests

I built this PR into one or more new PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#973
depends: hashicorp/terraform-provider-google#4100

@modular-magician modular-magician force-pushed the megan_bucket_retention_policy branch from 8bc3fe4 to c979cb4 Compare July 24, 2019 22:55
@modular-magician modular-magician merged commit 23c4592 into GoogleCloudPlatform:master Jul 24, 2019
@SarahFrench SarahFrench deleted the megan_bucket_retention_policy branch March 26, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants