Multi ENV deploy working on dev and prod
This commit is contained in:
35
master.tf
35
master.tf
@@ -9,24 +9,24 @@ terraform {
|
||||
|
||||
# Configure the AWS Provider
|
||||
provider "aws" {
|
||||
region = "eu-west-1"
|
||||
region = var.region
|
||||
profile = "StandOut_Terraform"
|
||||
}
|
||||
|
||||
# Create a VPC
|
||||
resource "aws_vpc" "vpc_standout" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
cidr_block = var.env == "dev" ? "10.0.0.0/16" : "10.10.0.0/16"
|
||||
}
|
||||
|
||||
# create an s3 bucket for config
|
||||
resource "aws_s3_bucket" "s3_standout_config" {
|
||||
bucket = "standout-config"
|
||||
bucket = "standout-config-${var.env}"
|
||||
force_destroy = false
|
||||
}
|
||||
|
||||
# create an s3 bucket for data
|
||||
resource "aws_s3_bucket" "s3_standout" {
|
||||
bucket = "standout-data"
|
||||
bucket = "standout-data-${var.env}"
|
||||
force_destroy = true
|
||||
}
|
||||
|
||||
@@ -135,30 +135,35 @@ data "aws_iam_policy_document" "lambda_role" {
|
||||
}
|
||||
|
||||
resource "aws_iam_role" "iam_for_lambda" {
|
||||
name = "iam_for_lambda"
|
||||
name = "iam_for_lambda-${var.env}"
|
||||
assume_role_policy = data.aws_iam_policy_document.lambda_role.json
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy_attachment" "iam_for_lambda_allow_logs" {
|
||||
role = aws_iam_role.iam_for_lambda.name
|
||||
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
||||
}
|
||||
|
||||
data "archive_file" "lambda_standout_code" {
|
||||
type = "zip"
|
||||
source_dir = "./lambda_redirect"
|
||||
output_path = "./lambda_zip/standout_lambda_redirect.zip"
|
||||
output_path = "./lambda_zip/standout_lambda_redirect-${var.env}.zip"
|
||||
}
|
||||
|
||||
data "archive_file" "lambda_standout_config_code" {
|
||||
type = "zip"
|
||||
source_dir = "./lambda_config"
|
||||
output_path = "./lambda_zip/standout_lambda_config.zip"
|
||||
output_path = "./lambda_zip/standout_lambda_config-${var.env}.zip"
|
||||
}
|
||||
|
||||
data "archive_file" "lambda_layer_deps" {
|
||||
type = "zip"
|
||||
source_dir = "./lambda_layer"
|
||||
output_path = "./lambda_zip/lambda_layer.zip"
|
||||
output_path = "./lambda_zip/lambda_layer-${var.env}.zip"
|
||||
}
|
||||
|
||||
resource "aws_lambda_layer_version" "lambda_layer" {
|
||||
filename = "./lambda_zip/lambda_layer.zip"
|
||||
filename = "./lambda_zip/lambda_layer-${var.env}.zip"
|
||||
layer_name = "lambda_deps"
|
||||
compatible_runtimes = ["python3.12"]
|
||||
}
|
||||
@@ -166,8 +171,8 @@ resource "aws_lambda_layer_version" "lambda_layer" {
|
||||
resource "aws_lambda_function" "lambda_standout_redirect" {
|
||||
# If the file is not in the current working directory you will need to include a
|
||||
# path.module in the filename.
|
||||
filename = "./lambda_zip/standout_lambda_redirect.zip"
|
||||
function_name = "standout-redirect"
|
||||
filename = "./lambda_zip/standout_lambda_redirect-${var.env}.zip"
|
||||
function_name = "standout-redirect-${var.env}"
|
||||
role = aws_iam_role.iam_for_lambda.arn
|
||||
handler = "lambda_redirect.lambda_handler"
|
||||
|
||||
@@ -190,8 +195,8 @@ resource "aws_lambda_function" "lambda_standout_redirect" {
|
||||
resource "aws_lambda_function" "lambda_standout_config" {
|
||||
# If the file is not in the current working directory you will need to include a
|
||||
# path.module in the filename.
|
||||
filename = "./lambda_zip/standout_lambda_config.zip"
|
||||
function_name = "standout-config"
|
||||
filename = "./lambda_zip/standout_lambda_config-${var.env}.zip"
|
||||
function_name = "standout-config-${var.env}"
|
||||
role = aws_iam_role.iam_for_lambda.arn
|
||||
handler = "lambda_config.lambda_handler"
|
||||
|
||||
@@ -233,7 +238,7 @@ resource "aws_s3_bucket_notification" "bucket_notification" {
|
||||
|
||||
# create API gateway for lambda triger and connect
|
||||
resource "aws_apigatewayv2_api" "api_standout_gateway" {
|
||||
name = "standout-api"
|
||||
name = "standout-api-${var.env}"
|
||||
protocol_type = "HTTP"
|
||||
}
|
||||
|
||||
@@ -251,7 +256,7 @@ resource "aws_apigatewayv2_integration" "api_standout_integration" {
|
||||
resource "aws_apigatewayv2_stage" "api_standout_lambda_stage" {
|
||||
api_id = aws_apigatewayv2_api.api_standout_gateway.id
|
||||
|
||||
name = "dev"
|
||||
name = var.env
|
||||
auto_deploy = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user