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

Change approach to choose instance in order to backup #3

Closed
wants to merge 6 commits into from

Conversation

s2504s
Copy link

@s2504s s2504s commented Aug 17, 2017

What

  • Change approach to choose instance for backup.

Why

  • We do not want to create special tag on each AWS instance in order to backup.

@s2504s s2504s requested review from osterman and const-bon August 17, 2017 14:42
@s2504s s2504s self-assigned this Aug 17, 2017
@s2504s s2504s changed the title Updated README Change approach to choose instance in order to backup Aug 17, 2017
ami_backup.py Outdated
create_fmt = create_time.strftime('%Y-%m-%d')

AMIid = ec.create_image(InstanceId=ec2_instance_id,
Name="Lambda - " + os.environ['instance_id'] + " from " + create_fmt,
Copy link
Member

Choose a reason for hiding this comment

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

Really don't like this name. Lamda is the strategy, but label_id would be much better and more descriptive. Would that be an easy change?

Copy link
Member

Choose a reason for hiding this comment

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

Also, prefer names to always be in tf_label fmt.

Copy link
Author

Choose a reason for hiding this comment

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

Changed

Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

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

Use hyphenated Name field: label_id-instance_id-create_fmt

Remove

README.md Outdated
@@ -24,6 +24,8 @@ module "lambda_ami_backup" {
namespace = "${var.namespace}"
region = "${var.region}"
ami_owner = "${var.ami_owner}"
instance_id = "${var.instance_id}"
retention = "14"
Copy link
Member

Choose a reason for hiding this comment

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

rename to retention_days for clarity

Copy link
Author

Choose a reason for hiding this comment

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

Renamed

Copy link
Member

Choose a reason for hiding this comment

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

I don't see that it was renamed. It still says retention =P

@osterman
Copy link
Member

osterman commented Aug 18, 2017

  • fix README.md repo URL

@osterman
Copy link
Member

WARNING! AMI cleanup works not yet.

Is this still relevant?

osterman
osterman previously approved these changes Aug 21, 2017
ami_backup.py Outdated
Filters=[
{'Name': 'tag-key', 'Values': ['backup', 'Backup', 'Snapshot']},
try:
retention_days = os.environ['retention_days']

Choose a reason for hiding this comment

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

Let's use explicit transformation retention_days = int(os.environ['retention_days'])

ami_backup.py Outdated
{'Name': 'tag-key', 'Values': ['backup', 'Backup', 'Snapshot']},
try:
retention_days = os.environ['retention_days']
except:

Choose a reason for hiding this comment

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

It is good practice to use named exceptions. In this way we know what exception happened and why we use it.
Let's use except ValueError:

main.tf Outdated
@@ -73,6 +73,13 @@ module "label_cleanup" {
name = "${var.name}-cleanup"
}

module "label_id" {

Choose a reason for hiding this comment

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

We don't need label_id module as it is a copy of label module.

Copy link
Author

Choose a reason for hiding this comment

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

Used label module. The module label_id was removed

main.tf Outdated
@@ -98,6 +105,9 @@ resource "aws_lambda_function" "ami_backup" {
variables = {
region = "${var.region}"
ami_owner = "${var.ami_owner}"
instance_id = "${var.instance_id}"

Choose a reason for hiding this comment

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

Apply terraform fmt

Copy link
Author

Choose a reason for hiding this comment

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

Applied

main.tf Outdated
@@ -87,7 +94,7 @@ resource "aws_iam_role_policy" "ami_backup" {
resource "aws_lambda_function" "ami_backup" {
filename = "${path.module}/ami_backup.zip"
function_name = "${module.label_backup.id}"
description = "Automatically backup instances tagged with 'Snapshot: true'"
description = "Automatically backup EC2 instance using instance id"

Choose a reason for hiding this comment

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

Let's use more direct description "Automatically backup EC2 instance ${var.instance_id} (create AMI)"

README.md Outdated
@@ -17,13 +17,15 @@ Notes:

```
module "lambda_ami_backup" {
source = "git::https://github.com/cloudposse/tf_lambda_ami_backup.git?ref=master"
source = "git::https://github.com/cloudposse/tf_ami_backup.git?ref=master"

Choose a reason for hiding this comment

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

Pin to the tag which will be added after this PR merged.
I think, we should do major tag version change, because logic of the module was heavily modified.

Copy link
Author

Choose a reason for hiding this comment

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

Pinned

@@ -17,13 +17,15 @@ Notes:

Choose a reason for hiding this comment

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

Delete

 Notes:
 * `ami_owner` is an AWS account id.

Because there is a Variables section.

Copy link
Author

Choose a reason for hiding this comment

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

Removed

ami_backup.py Outdated
#
# After creating the AMI it creates a "DeleteOn" tag on the AMI indicating when
# After creating the AMI it creates a "ami_delete_on" tag on the AMI indicating when
Copy link
Member

Choose a reason for hiding this comment

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

@comeanother all of our tags are camel case. Not sure why we are changing to snake case.

Copy link
Member

Choose a reason for hiding this comment

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

e.g. Namespace, Stage, Name

Copy link
Author

Choose a reason for hiding this comment

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

Tag has been modified to AMIDeleteOn

@const-bon
Copy link

Invalidated by #4

@const-bon const-bon closed this Aug 25, 2017
@const-bon const-bon deleted the without_tags branch August 25, 2017 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants