mirror of
				https://github.com/mr-vercetti/tf-aws-demo.git
				synced 2025-11-04 01:15:46 +01:00 
			
		
		
		
	Add demo-app autoscaling group
This commit is contained in:
		
							
								
								
									
										55
									
								
								prod/main.tf
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								prod/main.tf
									
									
									
									
									
								
							@@ -5,7 +5,7 @@ provider "aws" {
 | 
			
		||||
 | 
			
		||||
# Create VPC with NAT Gateway and route tables
 | 
			
		||||
module "vpc" {
 | 
			
		||||
  source = "terraform-aws-modules/vpc/aws"
 | 
			
		||||
  source  = "terraform-aws-modules/vpc/aws"
 | 
			
		||||
  version = "3.14.2"
 | 
			
		||||
 | 
			
		||||
  name = var.DEMO_VPC_NAME
 | 
			
		||||
@@ -15,22 +15,22 @@ module "vpc" {
 | 
			
		||||
  private_subnets = var.DEMO_VPC_PRIVATE_SUBNET_CIDRS
 | 
			
		||||
  public_subnets  = var.DEMO_VPC_PUBLIC_SUBNET_CIDRS
 | 
			
		||||
 | 
			
		||||
  enable_nat_gateway = true
 | 
			
		||||
  single_nat_gateway = true
 | 
			
		||||
  enable_nat_gateway     = true
 | 
			
		||||
  single_nat_gateway     = true
 | 
			
		||||
  one_nat_gateway_per_az = false
 | 
			
		||||
 | 
			
		||||
  tags = {
 | 
			
		||||
    Terraform = "true"
 | 
			
		||||
    Project = var.PROJECT_TAG
 | 
			
		||||
    Project   = var.PROJECT_TAG
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Get VPC data
 | 
			
		||||
module "vpc_data" {
 | 
			
		||||
  depends_on = [module.vpc]
 | 
			
		||||
  source = "../modules/vpc_data"
 | 
			
		||||
  source     = "../modules/vpc_data"
 | 
			
		||||
 | 
			
		||||
  VPC_NAME = var.DEMO_VPC_NAME
 | 
			
		||||
  VPC_NAME        = var.DEMO_VPC_NAME
 | 
			
		||||
  BASTION_HOST_AZ = var.DEMO_BASTION_HOST_AZ
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -38,9 +38,46 @@ module "vpc_data" {
 | 
			
		||||
module "bastion_host" {
 | 
			
		||||
  source = "../modules/bastion_host"
 | 
			
		||||
 | 
			
		||||
  VPC_ID        = module.vpc_data.vpc.id
 | 
			
		||||
  SUBNET_ID     = module.vpc_data.bastion_host_subnet.id
 | 
			
		||||
  VPC_ID    = module.vpc_data.vpc.id
 | 
			
		||||
  SUBNET_ID = module.vpc_data.bastion_host_subnet.id
 | 
			
		||||
 | 
			
		||||
  INSTANCE_TYPE = var.DEMO_BASTION_HOST_TYPE
 | 
			
		||||
  INSTANCE_NAME = var.DEMO_BASTION_HOST_NAME
 | 
			
		||||
  KEY_NAME      = var.DEMO_BASTION_HOST_KEY_NAME
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
data "aws_ami" "amazon-linux" {
 | 
			
		||||
  most_recent = true
 | 
			
		||||
 | 
			
		||||
  filter {
 | 
			
		||||
    name   = "name"
 | 
			
		||||
    values = ["amzn2-ami-*-gp2"]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  filter {
 | 
			
		||||
    name   = "architecture"
 | 
			
		||||
    values = ["x86_64"]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  filter {
 | 
			
		||||
    name   = "virtualization-type"
 | 
			
		||||
    values = ["hvm"]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  owners = ["amazon"]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Create demo app
 | 
			
		||||
module "app" {
 | 
			
		||||
  source = "../modules/app"
 | 
			
		||||
 | 
			
		||||
  VPC_ID          = module.vpc_data.vpc.id
 | 
			
		||||
  VPC_SUBNETS_IDS = module.vpc_data.private_subnets.ids
 | 
			
		||||
 | 
			
		||||
  EC2_IMAGE_ID = data.aws_ami.amazon-linux.id
 | 
			
		||||
  EC2_TYPE     = var.DEMO_APP_EC2_TYPE
 | 
			
		||||
  EC2_KEY_NAME = var.DEMO_APP_EC2_KEY_NAME
 | 
			
		||||
 | 
			
		||||
  ASG_MIN_SIZE     = var.DEMO_APP_ASG_MIN_SIZE
 | 
			
		||||
  ASG_MAX_SIZE     = var.DEMO_APP_ASG_MAX_SIZE
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
output "demo_vpc_id" {
 | 
			
		||||
  value       = module.vpc_data.vpc.id
 | 
			
		||||
  value = module.vpc_data.vpc.id
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
output "public_subnets" {
 | 
			
		||||
@@ -11,11 +11,7 @@ output "private_subnets" {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
output "demo_bastion_host_subnet_id" {
 | 
			
		||||
  value       = module.vpc_data.bastion_host_subnet.id
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
output "demo_bastion_host_private_ip" {
 | 
			
		||||
  value = module.bastion_host.bastion_host_private_ip
 | 
			
		||||
  value = module.vpc_data.bastion_host_subnet.id
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
output "demo_bastion_host_public_ip" {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# General
 | 
			
		||||
# general
 | 
			
		||||
variable "REGION" {
 | 
			
		||||
  type    = string
 | 
			
		||||
  default = "eu-west-3"
 | 
			
		||||
@@ -8,7 +8,7 @@ variable "PROJECT_TAG" {
 | 
			
		||||
  type = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# DEMO_VPC (network, network_data)
 | 
			
		||||
# vpc
 | 
			
		||||
variable "DEMO_VPC_NAME" {
 | 
			
		||||
  type = string
 | 
			
		||||
}
 | 
			
		||||
@@ -30,7 +30,7 @@ variable "DEMO_VPC_PUBLIC_SUBNET_CIDRS" {
 | 
			
		||||
  type = list(string)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Bastion host (bastion_host)
 | 
			
		||||
# bastion host
 | 
			
		||||
variable "DEMO_BASTION_HOST_TYPE" {
 | 
			
		||||
  type    = string
 | 
			
		||||
  default = "t2.micro"
 | 
			
		||||
@@ -47,3 +47,20 @@ variable "DEMO_BASTION_HOST_KEY_NAME" {
 | 
			
		||||
variable "DEMO_BASTION_HOST_AZ" {
 | 
			
		||||
  type = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# demo app
 | 
			
		||||
variable "DEMO_APP_EC2_TYPE" {
 | 
			
		||||
  type = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "DEMO_APP_EC2_KEY_NAME" {
 | 
			
		||||
  type = string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "DEMO_APP_ASG_MIN_SIZE" {
 | 
			
		||||
  type = number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
variable "DEMO_APP_ASG_MAX_SIZE" {
 | 
			
		||||
  type = number
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user