This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# External ALB | |
# --------------------------------------------------------------- | |
resource "aws_alb" "ext_alb" { | |
name = "${data.consul_keys.ck.var.project_name}-${var.install_name}-${var.env}-edeal-alb-pub" | |
subnets = ["${data.terraform_remote_state.network.aws_subnet_front}"] | |
security_groups = ["${data.consul_keys.ck.var.sg_alb_pub_id}"] | |
internal = false | |
idle_timeout = "${data.consul_keys.ck.var.alb_idle_timeout}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# Step 1 : Create APIGateway | |
# --------------------------------------------------------------- | |
resource "aws_api_gateway_rest_api" "apigateway" { | |
name = "${data.consul_keys.ck.var.project_name}-${data.consul_keys.ck.var.env}-${var.install_name}-backend" | |
description = "Serverless application for SLM" | |
} | |
# -------------------------------------------------------------- | |
# Step 2 : Create APIGateway Ressource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate Plan and apply | |
terraform plan -out=biznet.plan | |
terraform apply "thehktech.plan" | |
# If you want to destroy | |
terraform destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# RDS SUBNET | |
# --------------------------------------------------------------- | |
resource "aws_db_subnet_group" "db" { | |
name = "${data.consul_keys.ck.var.project_name}-${var.install_name}" | |
subnet_ids = [ | |
"${data.terraform_remote_state.network.aws_subnet_dataapp}"] | |
tags { | |
Name = "${data.consul_keys.ck.var.project_name}-${var.install_name}" | |
BillingBusinessApp = "${data.consul_keys.ck.var.billing_business_app}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# IAM ROLES FOR LAMBDA FUNCTION | |
# --------------------------------------------------------------- | |
resource "aws_iam_role" "aws_iam_role_lambda" { | |
name = "${data.consul_keys.ck.var.project_name}-${var.install_name}-${var.env}-lambda-processing" | |
assume_role_policy = "${data.aws_iam_policy_document.lambda_assume.json}" | |
tags { | |
env = "${var.env}" | |
resource-name = "${data.consul_keys.ck.var.project_name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# Security Group Rules For RDS | |
# --------------------------------------------------------------- | |
resource "aws_security_group" "db" { | |
name = "${data.consul_keys.ck.var.project_name}-${var.install_name}-rds" | |
description = "Security group for ${data.consul_keys.ck.var.project_name} db rds" | |
vpc_id = "${data.terraform_remote_state.network.aws_vpc_id}" | |
tags { | |
resource-env = "${data.consul_keys.ck.var.env}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# LAMBDA FUNCTION FOR BACKEND | |
# --------------------------------------------------------------- | |
resource "aws_lambda_function" "backend_lambda" { | |
function_name = "${data.consul_keys.ck.var.project_name}-${data.consul_keys.ck.var.env}-${var.install_name}-backend" | |
role = "${aws_iam_role.aws_iam_role_lambda.arn}" | |
handler = "slm_processing.handler" | |
runtime = "python2.7" | |
s3_bucket = "hktech-repo-lambda" | |
s3_key = "projects/${data.consul_keys.ck.var.project_name}/releases/${var.version_lot}/slm-backend.zip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# Security Group Rules For Lambda Backend | |
# --------------------------------------------------------------- | |
resource "aws_security_group_rule" "sg-lambda-backend-egress-rule" { | |
from_port = "0" | |
protocol = "-1" | |
to_port = "0" | |
cidr_blocks = ["0.0.0.0/0"] | |
security_group_id = "${aws_security_group.sg-lambda.id}" | |
type = "egress" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------------------------------------- | |
# ROUTE53 ASSOCIATE TO CLOUDFRONT DISTRIBUTION | |
# --------------------------------------------------------------- | |
resource "aws_route53_record" "front" { | |
provider = "aws.mgmt" | |
zone_id = "thehktech.com" | |
name = "tuto" | |
type = "A" | |
alias { | |
evaluate_target_health = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudfront_distribution" "site_distribution" { | |
origin { | |
domain_name = "${aws_s3_bucket.website_front.bucket_domain_name}" | |
origin_id = "${data.consul_keys.ck.var.project_name}-${data.consul_keys.ck.var.env}-${var.install_name}" | |
} | |
enabled = true | |
aliases = ["${data.consul_keys.ck.var.project_name}-${data.consul_keys.ck.var.env}-${var.install_name}.thehktech.com"] // DNS route53 | |
//price_class = "PriceClass_100" | |
default_root_object = "index.html" | |
default_cache_behavior { |