Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

Prevent spurious modified resources on every TF plan/apply #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ terraform.tfstate.backup
.terraform
key.pub
key
tmp
tmp/*
lambda
lambda/*
lambda-*
26 changes: 10 additions & 16 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,31 @@ data "template_file" "vars" {
}
}


resource "null_resource" "buildlambdazip" {
triggers { key = "${uuid()}" }
provisioner "local-exec" {
command = <<EOF
mkdir -p ${path.module}/lambda && mkdir -p ${path.module}/tmp
cp ${path.module}/ebs_bckup/ebs_bckup.py ${path.module}/tmp/ebs_bckup.py
echo "${data.template_file.vars.rendered}" > ${path.module}/tmp/vars.ini
EOF
}
}
data "archive_file" "lambda_zip" {
type = "zip"
source_dir = "${path.module}/tmp"
output_path = "${path.module}/lambda/${var.stack_prefix}-${var.unique_name}.zip"
depends_on = ["null_resource.buildlambdazip"]
output_path = "${path.module}/lambda-${var.stack_prefix}-${var.unique_name}.zip"
source {
filename = "ebs_bckup.py"
content = "${file("${path.module}/ebs_bckup/ebs_bckup.py")}"
}
source {
filename = "vars.ini"
content = "${data.template_file.vars.rendered}"
}
}

# Create lambda function
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

resource "aws_lambda_function" "ebs_bckup_lambda" {
function_name = "${var.stack_prefix}_lambda_${var.unique_name}"
filename = "${path.module}/lambda/${var.stack_prefix}-${var.unique_name}.zip"
filename = "${path.module}/lambda-${var.stack_prefix}-${var.unique_name}.zip"
source_code_hash = "${data.archive_file.lambda_zip.output_base64sha256}"
role = "${aws_iam_role.ebs_bckup-role-lambdarole.arn}"
runtime = "python2.7"
handler = "ebs_bckup.lambda_handler"
timeout = "60"
publish = true
depends_on = ["null_resource.buildlambdazip"]
}

# Run the function with CloudWatch Event cronlike scheduler
Expand Down