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

provider/aws: Add versioning option to S3 bucket #2942

Merged
merged 4 commits into from
Sep 6, 2015

Conversation

kjmkznr
Copy link
Contributor

@kjmkznr kjmkznr commented Aug 5, 2015

This commit is allows to versioning configuration to S3 bucket resource.

resource "aws_s3_bucket" "bucket" {
    bucket = "bucket"
    acl = "private"
    versioning = true
}

@apparentlymart
Copy link
Contributor

This seems like a reasonable change and implementation.

A couple thoughts:

  • The S3 API for versioning includes another attribute called "MFADelete" that seems to provide extra protection around the permanent deletion of objects. Do you think we should make versioning a child configuration block that contains both of these options? If we make versioning a boolean now then adding support for mfa_delete in future would require it to be a top-level attribute. I don't know much about the S3 versioning feature so I don't know what configuration would be most intuitive to a user.
  • In the underlying API it looks like S3 versioning can be in three different states: not enabled, enabled, or suspended. In your implementation you've collapsed "not enabled" and "suspended" into false. I'm not sure whether it's a good idea to abstract away the distinction between these two states, since it seems to have some implications for the behavior of the S3 bucket object operations. What do you think? Could it be better to make this attribute a string that can either be "" (meaning "disabled"), "enabled" or "suspended"?

Just some things to think about, since these decisions will be hard to change later without breaking backward compatibility.

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Aug 14, 2015

Thanks review.

The S3 API for versioning includes another attribute called "MFADelete" that seems to provide extra protection around the permanent deletion of objects. Do you think we should make versioning a child configuration block that contains both of these options? If we make versioning a boolean now then adding support for mfa_delete in future would require it to be a top-level attribute. I don't know much about the S3 versioning feature so I don't know what configuration would be most intuitive to a user.

If conform the AWS API, I think should make status and mfa_delete in versioning block.
And, I think intuitive versioning block, because "MFA Delete" depends versioning option.
I will try change this.

In the underlying API it looks like S3 versioning can be in three different states: not enabled, enabled,
or suspended. In your implementation you've collapsed "not enabled" and "suspended" into false.
I'm not sure whether it's a good idea to abstract away the distinction between these two states,
since it seems to have some implications for the behavior of the S3 bucket object operations.
What do you think? Could it be better to make this attribute a string that can either be "" (meaning "disabled"),
"enabled" or "suspended"?

I agree make attribute a string.
How about follow plan?

  • status attribute can set nil(meaning disabled), "enabled", "suspended".

  • If currently status value is "enabled" or "suspended", can't set nil.

    Display error when apply action.
    (I don't know way, how to write to fail in plan action when change to nil from not nil.)

@apparentlymart
Copy link
Contributor

That sounds reasonable to me. IIRC schema attributes can't actually be nil, and if you try to set hem that way it will instead set the "zero value" of the type. So your unset case would actually be the empty string, not literally nil. Then just make sure the attribute is defined as Optional and that it has the empty string as the default.

@radeksimko
Copy link
Member

Hi @kjmkznr
Thanks for sending this PR!

Would you mind rebasing last commits from upstream master & resolve conflicts in your branch?

In the underlying API it looks like S3 versioning can be in three different states: not enabled, enabled, or suspended. In your implementation you've collapsed "not enabled" and "suspended" into false. I'm not sure whether it's a good idea to abstract away the distinction between these two states, since it seems to have some implications for the behavior of the S3 bucket object operations.

I actually think that boolean here makes sense. The reason suspended exists is to differentiate between a state when versioning has never been enabled on that bucket (i.e. no past versions exist) and when we just "pause" tracking of versions. There is no way to get back to disabled state once you enable versioning, you can only suspend.
See http://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html

Important
Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket.

I think we should hide this detail away from user, hence I think that default state, when there'll be no versioning block could mean either disabled or suspended, but user doesn't need to be worried about the difference. Terraform should IMO figure out what to do.

versioning.mfa_delete can be a boolean as well and it would be nice to have it as well. I would not worry too much about dependencies between these two since we don't have mechanisms how to define & check this inside schema yet.

To clarify, this would be adequate to default state, when user doesn't define versioning at all:

versioning {
  enabled = false
  mfa_delete = false
}

Let me know if there's anything else you need to finish this up, so we can merge it. 😉

"versioning": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Computed: true,
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why keep this Computed: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I mistake it.

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Sep 5, 2015

@radeksimko
Thanks review.

I rebase upstream master and resolve conflicts.
And, changed to versioning block and enabled bool from single versioning bool value.

versioning.enabled has three states.

  1. disabled
    This state is undefined versioning.enabled.
  2. enabled
    This state is versioning.enabled=true
  3. suspended
    This state is versioning.enabled=false or removed versioning block.

Set: func(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
buf.WriteString(fmt.Sprintf("%d-", m["enabled"].(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 is now reported by go vet:

builtin/providers/aws/resource_aws_s3_bucket.go:108: arg m["enabled"].(bool) for printf verb %d of wrong type: bool

the right modifier is %t.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@radeksimko
Copy link
Member

Schema looks ok, do you plan adding mfa_delete? If not that's 👌 , we can add it later.
Also it would be great if you could update related docs. 😉

Besides that one vet nitpick it's overall OK.

@kjmkznr
Copy link
Contributor Author

kjmkznr commented Sep 6, 2015

@radeksimko

I updated S3 bucket resource document.

I don't have adding mfa_delete plan.
mfa_delete needs authentication device's serial number and displayed value.
I don't know how to pass value to command. Sorry.

@radeksimko
Copy link
Member

LGTM 👍

radeksimko added a commit that referenced this pull request Sep 6, 2015
provider/aws: Add versioning option to S3 bucket
@radeksimko radeksimko merged commit 4c057ff into hashicorp:master Sep 6, 2015
@kjmkznr
Copy link
Contributor Author

kjmkznr commented Sep 6, 2015

Thanks!

@kjmkznr kjmkznr deleted the s3-bucket-versioning branch September 6, 2015 23:54
@ghost
Copy link

ghost commented May 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants