Skip to content

Commit

Permalink
tefform modules
Browse files Browse the repository at this point in the history
  • Loading branch information
clamorisse committed Oct 24, 2016
1 parent eb50dcf commit 747d126
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 143 deletions.
31 changes: 0 additions & 31 deletions infrastructure/terraform/buckets_for_lambda.tf

This file was deleted.

58 changes: 0 additions & 58 deletions infrastructure/terraform/iam_lambda.tf

This file was deleted.

38 changes: 0 additions & 38 deletions infrastructure/terraform/lambda_function.tf

This file was deleted.

91 changes: 91 additions & 0 deletions infrastructure/terraform/main_terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# ------------------------------------------------
# CONFIGURATION OF AWS ACCOUNT
# ------------------------------------------------


variable "tf_region" { default = "us-east-1" }
variable "profile" { default = "default" }

variable "application-name" { }
variable "env" { }

variable "source_bucket" { }

variable "lambda_role_policy_tmpl" { }
variable "lambda_function_zip_file" { }


provider "aws" {
region = "${var.tf_region}"
profile = "${var.profile}"
}


#-------------------------------------------------
# Source and target Buckets
# for Lambda f(x)
#-------------------------------------------------

module "s3_buckets" {
source = "../modules/s3"

source_bucket = "${var.source_bucket}"
app_name = "${var.application-name}"
env = "${var.env}"
}

# -------------------------------------------------
# CREATING POLICIES AND ROLES FOR
# LAMBDA f(x)
# -------------------------------------------------

# File that contains the policy for Lambda to access S3 resources

resource "template_file" "lambda_policy" {
template = "${file("${var.lambda_role_policy_tmpl}")}"
vars {
input_bucket_name = "${module.s3_buckets.source-bucket-id}"
html_bucket_name = "${module.s3_buckets.target-bucket-id}"
}
}

module "iam_lambda" {
source = "../modules/iam"

app_name = "${var.application-name}"
policy_file = "${template_file.lambda_policy.rendered}"

}

# ------------------------------------------------
# CREATES LAMBDA f(X)
# ------------------------------------------------

module "lambda_function" {
source = "../modules/lambda"

zip_file = "${var.lambda_function_zip_file}"
app-name = "${var.application-name}"
role = "${module.iam_lambda.execution_role_arn}"
handler = "main.handle"
runtime = "python2.7"

source_arn = "${module.s3_buckets.source-bucket-arn}"
source_id = "${module.s3_buckets.source-bucket-id}"

events = "s3:ObjectCreated:*"
filter_prefix = "images/"
filter_suffix = ".jpg"
}

output "lambda_function_arn" { value = "${module.lambda_function.lambda_function_arn}" }
output "exectution_role_arn" { value = "${module.iam_lambda.execution_role_arn}" }

output "source-bucket-id" { value = "${module.s3_buckets.source-bucket-id}" }
output "source-bucket-arn" { value = "${module.s3_buckets.source-bucket-arn}" }
output "target-bucket-id" { value = "${module.s3_buckets.target-bucket-id}" }
output "target-bucket-arn" { value = "${module.s3_buckets.target-bucket-arn}" }




8 changes: 4 additions & 4 deletions infrastructure/terraform/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
aws-region = "us-east-1"
profile-name = "default"
object-name = "terraform.tfstate"
application-name = "s3_trigger_function"
application-name = "lambda_s3_triggered"
env = "dev"

source_bucket = "source_bvc_files"
lambda_role_policy_tmpl = "template_files/lambda_policy_s3_resources.tmpl"
lambda_function_zip = "template_files/lambda_resize_image.zip"
source_bucket = "source_bvc_files"
lambda_role_policy_tmpl = "template_files/lambda_policy_s3_resources.tmpl"
lambda_function_zip_file = "template_files/lambda_resize_image.zip"
12 changes: 0 additions & 12 deletions infrastructure/terraform/tf_config_var_aws.tf

This file was deleted.

0 comments on commit 747d126

Please sign in to comment.