Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module "vpc" {
- source = "terraform-aws-modules/vpc/aws"
- version = "~> 5.0"
- name = "ddemo-vpc"
- cidr = "10.0.0.0/16"
- azs = ["us-west-1b", "us-west-1c"]
- public_subnets = ["10.0.10.0/24", "10.0.20.0/24"]
- private_subnets = ["10.0.100.0/24", "10.0.200.0/24"]
- manage_default_route_table = true
- enable_nat_gateway = true
- single_nat_gateway = true
- }
- module "asg" {
- source = "terraform-aws-modules/autoscaling/aws"
- name = "ddemo-asg"
- instance_type = "t2.micro"
- image_id = "ami-014d05e6b24240371"
- min_size = "2"
- max_size = "2"
- desired_capacity = "2"
- min_elb_capacity = "2"
- vpc_zone_identifier = module.vpc.private_subnets
- # key_name = "foobar-aws2023-key"
- user_data = base64encode(local.user_data)
- security_groups = [module.alb.security_group_id]
- target_group_arns = [for k, v in module.alb.target_groups : v.arn]
- }
- module "alb" {
- source = "terraform-aws-modules/alb/aws"
- vpc_id = module.vpc.vpc_id
- subnets = module.vpc.private_subnets
- enable_deletion_protection = false
- security_group_ingress_rules = {
- all_http = {
- from_port = 80
- to_port = 80
- ip_protocol = "tcp"
- description = "HTTP"
- cidr_ipv4 = "0.0.0.0/0"
- }
- }
- security_group_egress_rules = {
- all = {
- ip_protocol = "-1"
- cidr_ipv4 = "0.0.0.0/0"
- }
- }
- listeners = {
- ddemo-http = {
- port = 80
- protocol = "HTTP"
- forward = {
- target_group_key = "ddemo-tg"
- }
- }
- }
- target_groups = {
- ddemo-tg = {
- name_prefix = "ddemo-"
- protocol = "HTTP"
- port = 8080
- target_type = "instance"
- create_attachment = false
- }
- }
- }
- locals {
- user_data = <<-EOT
- #!/bin/bash
- set -e
- /usr/bin/apt update
- /usr/bin/apt install -y nginx
- sed -i 's/listen 80 default_server;/listen 8080 default_server;/g' /etc/nginx/sites-available/default
- echo "hello how are you." > /var/www/html/index.html
- /usr/bin/systemctl restart nginx
- EOT
- }
Add Comment
Please, Sign In to add comment