-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
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, |
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.
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?
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.
Also, prefer names to always be in tf_label
fmt.
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.
Changed
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.
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" |
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.
rename to retention_days
for clarity
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.
Renamed
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.
I don't see that it was renamed. It still says retention
=P
|
Is this still relevant? |
ami_backup.py
Outdated
Filters=[ | ||
{'Name': 'tag-key', 'Values': ['backup', 'Backup', 'Snapshot']}, | ||
try: | ||
retention_days = os.environ['retention_days'] |
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.
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: |
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.
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" { |
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.
We don't need label_id
module as it is a copy of label
module.
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.
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}" |
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.
Apply terraform fmt
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.
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" |
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.
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" |
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.
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.
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.
Pinned
@@ -17,13 +17,15 @@ Notes: | |||
|
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.
Delete
Notes:
* `ami_owner` is an AWS account id.
Because there is a Variables
section.
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.
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 |
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.
@comeanother all of our tags are camel case. Not sure why we are changing to snake case.
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.
e.g. Namespace
, Stage
, Name
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.
Tag has been modified to AMIDeleteOn
Invalidated by #4 |
What
Why