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
# Backend Variables | |
variable "state_bucket_name" { | |
default = "2-tier-state-bucket" | |
} | |
variable "state_table_name" { | |
default = "2-tier-state-table" | |
} | |
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
#Outputs | |
output "web_server_public_ip" { | |
description = "Public IP of Web Servers" | |
value = module.create_two_tier_aws.web_server_public_ip | |
} | |
output "ec2_ssh_access" { | |
description = "Remote Access to EC2" | |
value = module.create_two_tier_aws.ec2_ssh_access | |
} |
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
# Modules | |
module "create_two_tier_aws" { | |
source = "./modules" | |
env = var.env | |
aws_region = var.aws_region | |
vpc_cidr_block = var.vpc_cidr | |
public_subnet_cidr_block = [var.public_subnet1_az1_cidr, var.public_subnet2_az2_cidr] | |
private_subnet_cidr_block = [var.private_subnet1_az1_cidr, var.private_subnet2_az2_cidr] |
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
# Terraform and Provider Blocks | |
terraform { | |
required_providers { | |
aws = { | |
version = "~> 4.55" | |
source = "hashicorp/aws" | |
} | |
} | |
#####Uncomment this backend section after creating s3 bucket and dynamodb table#### |
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
# Variables | |
variable "env" { | |
description = "Environment Name" | |
type = string | |
} | |
variable "aws_region" { | |
description = "AWS deployment region" | |
type = string |
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
# Outputs | |
output "web_server_public_ip" { | |
description = "Public IP of Web Servers" | |
value = [for i in aws_instance.web_server[*] : i.public_ip] | |
} | |
output "ec2_ssh_access" { | |
description = "SSH Remote Access to the first EC2 instance" | |
value = "ssh -i ${var.ssh_key}.pem ubuntu@${aws_instance.web_server[0].public_ip}" | |
} |
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
# VPC | |
resource "aws_vpc" "vpc" { | |
cidr_block = var.vpc_cidr_block | |
enable_dns_hostnames = true | |
tags = { | |
Name = "${var.env}-vpc" | |
Environment = 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
# Security Group | |
resource "aws_security_group" "db_security_group" { | |
name = "${var.env}-db-security-group" | |
description = "Security Group for RDS instance" | |
vpc_id = aws_vpc.vpc.id | |
ingress { | |
description = "MySQL traffic from Web Servers" | |
from_port = 3306 | |
to_port = 3306 |
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 | |
# Obtain User Local Public IP | |
data "external" "myipaddr" { | |
program = ["bash", "-c", "curl -s 'https://ipinfo.io/json'"] | |
} | |
resource "aws_security_group" "ec2_security_group" { | |
name = "${var.env}-ec2-security-group" | |
description = "Security Group for EC2 Web Servers" |
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 | |
resource "aws_security_group" "alb_security_group" { | |
name = "${var.env}-alb-security-group" | |
description = "ALB Security Group" | |
vpc_id = aws_vpc.vpc.id | |
ingress { | |
description = "HTTP from Internet" | |
from_port = 80 | |
to_port = 80 |
NewerOlder