diff --git a/aws/aws_asg/main.tf b/aws/aws_asg/main.tf new file mode 100644 index 0000000..5d2fce2 --- /dev/null +++ b/aws/aws_asg/main.tf @@ -0,0 +1,66 @@ +terraform { + backend "s3" { + bucket = "my-tf-bucket-ghndrx" + key = "terraform.tfstate" + region = "us-west-2" + } +} +# Define provider +provider "aws" { + region = var.aws_region +} + +# Define modules +module "vpc-east" { + source = "./modules/vpc/vpc-east" + region = "us-east-1" + + us_east_subnet_1_id = module.subnets_us_east.us_east_subnet_1_id + us_east_subnet_2_id = module.subnets_us_east.us_east_subnet_2_id + us_east_subnet_3_id = module.subnets_us_east.us_east_subnet_3_id +} + +module "vpc-west" { + source = "./modules/vpc/vpc-west" + region = "us-west-2" + + us_west_subnet_1_id = module.subnets_us_west.us_west_subnet_1_id + us_west_subnet_2_id = module.subnets_us_west.us_west_subnet_2_id + us_west_subnet_3_id = module.subnets_us_west.us_west_subnet_3_id +} + +module "subnets_us_west" { + source = "./modules/vpc/subnets/us-west" + + vpc_id_west_2 = module.vpc-west.vpc_id_west_2 +} + +module "subnets_us_east" { + source = "./modules/vpc/subnets/us-east" + vpc_id_east_1 = module.vpc-east.vpc_id_east_1 +} + +module "ec2-east" { + source = "./modules/ec2/ec2-east" + + min_size = "4" + max_size = "10" + us_east_subnet_1_id = module.subnets_us_east.us_east_subnet_1_id + us_east_subnet_2_id = module.subnets_us_east.us_east_subnet_2_id + us_east_subnet_3_id = module.subnets_us_east.us_east_subnet_3_id + + vpc_id_east_1 = module.vpc-east.vpc_id_east_1 +} + +module "ec2-west" { + source = "./modules/ec2/ec2-west" + + min_size = "4" + max_size = "10" + us_west_subnet_1_id = module.subnets_us_west.us_west_subnet_1_id + us_west_subnet_2_id = module.subnets_us_west.us_west_subnet_2_id + us_west_subnet_3_id = module.subnets_us_west.us_west_subnet_3_id + + vpc_id_west_2 = module.vpc-west.vpc_id_west_2 +} + diff --git a/aws/aws_asg/modules/ec2/ec2-east/ec2-east.tf b/aws/aws_asg/modules/ec2/ec2-east/ec2-east.tf new file mode 100644 index 0000000..b68f61d --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-east/ec2-east.tf @@ -0,0 +1,88 @@ +provider "aws" { + region = "us-east-1" +} + +# Create a security group for the EC2 instance +resource "aws_security_group" "instance-east" { + name_prefix = "instance-east-" + vpc_id = var.vpc_id_east_1 + # HTTP access + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + # HTTPS access + ingress { + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + # SSH access + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "instance-security-group-east" + } +} + +# Define the Launch Template +resource "aws_launch_template" "lt-east" { + name_prefix = "lt-east-" + image_id = "ami-0237a465e7f465b10" + instance_type = "t3.small" + user_data = base64encode(file("${path.module}/user-data.sh")) + block_device_mappings { + device_name = "/dev/xvda" + ebs { + volume_size = 300 + } + } + network_interfaces { + associate_public_ip_address = true + security_groups = [aws_security_group.instance-east.id] + } +} + +# Define the Auto Scaling Group +resource "aws_autoscaling_group" "asg-east" { + name_prefix = "asg-east-" + launch_template { + id = aws_launch_template.lt-east.id + version = "$Latest" + } + vpc_zone_identifier = [ + var.us_east_subnet_1_id, + var.us_east_subnet_2_id, + var.us_east_subnet_3_id + ] + min_size = var.min_size + max_size = var.max_size + desired_capacity = var.min_size + health_check_grace_period = 300 + health_check_type = "EC2" + termination_policies = ["OldestInstance"] + tag { + key = "Name" + value = "asg-instance-east" + propagate_at_launch = true + } + + depends_on = [ + aws_security_group.instance-east, + aws_launch_template.lt-east + ] +} + +data "aws_instances" "asg_instances-east" { + instance_tags = { + "aws:autoscaling:groupName" = aws_autoscaling_group.asg-east.name + } +} diff --git a/aws/aws_simple/efs/main.tf b/aws/aws_asg/modules/ec2/ec2-east/outputs.tf similarity index 100% rename from aws/aws_simple/efs/main.tf rename to aws/aws_asg/modules/ec2/ec2-east/outputs.tf diff --git a/aws/aws_asg/modules/ec2/ec2-east/terraform.tfvars b/aws/aws_asg/modules/ec2/ec2-east/terraform.tfvars new file mode 100644 index 0000000..a3c3722 --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-east/terraform.tfvars @@ -0,0 +1,2 @@ +min_size = "3" +max_size = "10" \ No newline at end of file diff --git a/aws/aws_simple/ec2/user-data.sh b/aws/aws_asg/modules/ec2/ec2-east/user-data.sh similarity index 96% rename from aws/aws_simple/ec2/user-data.sh rename to aws/aws_asg/modules/ec2/ec2-east/user-data.sh index afffcf9..b9e8710 100644 --- a/aws/aws_simple/ec2/user-data.sh +++ b/aws/aws_asg/modules/ec2/ec2-east/user-data.sh @@ -25,4 +25,4 @@ HOSTNAME="$INSTANCE_ID-$AVAILABILITY_ZONE" sudo hostnamectl set-hostname $HOSTNAME # Run cloud-init.sh script -sudo sh /path/to/cloud-init.sh +# sudo sh /path/to/cloud-init.sh diff --git a/aws/aws_asg/modules/ec2/ec2-east/variables.tf b/aws/aws_asg/modules/ec2/ec2-east/variables.tf new file mode 100644 index 0000000..db897bd --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-east/variables.tf @@ -0,0 +1,35 @@ + +# Define variables +variable "min_size" { + type = number + description = "Minimum number of instances in the Auto Scaling Group" +} + +variable "max_size" { + type = number + description = "Maximum number of instances in the Auto Scaling Group" +} + + +variable "us_east_subnet_1_id" { + description = "The ID of the first US East subnet" + type = string +} + +variable "us_east_subnet_2_id" { + description = "The ID of the second US East subnet" + type = string +} + +variable "us_east_subnet_3_id" { + description = "The ID of the third US East subnet" + type = string +} + +variable "vpc_id_east_1" { + description = "The ID of the VPC" + type = string +} + + + diff --git a/aws/aws_asg/modules/ec2/ec2-west/ec2-west..tf b/aws/aws_asg/modules/ec2/ec2-west/ec2-west..tf new file mode 100644 index 0000000..9cdc72f --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-west/ec2-west..tf @@ -0,0 +1,90 @@ +provider "aws" { + region = "us-west-2" +} + +# Create a security group for the EC2 instance +resource "aws_security_group" "instance-west" { + name_prefix = "instance-west-" + vpc_id = var.vpc_id_west_2 + # HTTP access + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # HTTPS access + ingress { + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # SSH access + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "instance-security-group-west" + } +} + +# Define the Launch Template +resource "aws_launch_template" "lt-west" { + name_prefix = "lt-west" + image_id = "ami-03bf1eb153d14803f" + instance_type = "t3.small" + user_data = base64encode(file("${path.module}/user-data.sh")) + block_device_mappings { + device_name = "/dev/xvda" + ebs { + volume_size = 300 + } + } + network_interfaces { + associate_public_ip_address = true + security_groups = [aws_security_group.instance-west.id] + + } +} + +# Define the Auto Scaling Group +resource "aws_autoscaling_group" "asg-west" { + name_prefix = "asg-west-" + launch_template { + id = aws_launch_template.lt-west.id + version = "$Latest" + } + vpc_zone_identifier = [ + var.us_west_subnet_1_id, + var.us_west_subnet_2_id, + var.us_west_subnet_3_id + ] + min_size = var.min_size + max_size = var.max_size + desired_capacity = var.min_size + health_check_grace_period = 300 + health_check_type = "EC2" + termination_policies = ["OldestInstance"] + tag { + key = "Name" + value = "asg-instance-west" + propagate_at_launch = true + } + depends_on = [ + aws_security_group.instance-west, + aws_launch_template.lt-west + ] +} + +data "aws_instances" "asg_instances-west" { + instance_tags = { + "aws:autoscaling:groupName" = aws_autoscaling_group.asg-west.name + } +} diff --git a/aws/aws_asg/modules/ec2/ec2-west/outputs.tf b/aws/aws_asg/modules/ec2/ec2-west/outputs.tf new file mode 100644 index 0000000..d5f2320 --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-west/outputs.tf @@ -0,0 +1,4 @@ +# output "public_ips" { +# description = "Public IP addresses of the instances in the Auto Scaling group" +# value = [for i in data.aws_instances.asg_instances.ids : aws_instance[i].public_ip] +# } \ No newline at end of file diff --git a/aws/aws_asg/modules/ec2/ec2-west/terraform.tfvars b/aws/aws_asg/modules/ec2/ec2-west/terraform.tfvars new file mode 100644 index 0000000..a3c3722 --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-west/terraform.tfvars @@ -0,0 +1,2 @@ +min_size = "3" +max_size = "10" \ No newline at end of file diff --git a/aws/aws_asg/modules/ec2/ec2-west/user-data.sh b/aws/aws_asg/modules/ec2/ec2-west/user-data.sh new file mode 100644 index 0000000..b845ff9 --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-west/user-data.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Install necessary packages +sudo apt-get update +sudo apt-get install -y git amazon-efs-utils vim-nox neofetch htop tmux curl wget + +# Create new user with sudo privileges +sudo useradd -m -s /bin/bash greg +sudo usermod -aG sudo greg + +# Add authorized keys for your public key +sudo mkdir -p /home/greg/.ssh +sudo touch /home/greg/.ssh/authorized_keys +sudo chmod 700 /home/greg/.ssh +sudo chmod 600 /home/greg/.ssh/authorized_keys +sudo chown -R greg:greg /home/greg/.ssh + +# Add your public key to authorized_keys +sudo echo " +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCdOF80z0piQEnYzNCu2OGvOJdm7+3wfDuiC+Jzi8VbSC5VW4iJAQXOuDNGLzyqNi6uMjI77xpEL6Xzn29uJiQti6Y/LxhOZwNNIQiGUpFco1wkBYeBFbtgHQxsMLwumrxQGEj2fyCiSrACAPyy/l1fP4mlN7abBGD5aozBrYKxXPS/kfwO5nsWmw27RgTzfHJzie2dUU3ew/kd7td3wEdWrRXq8wNbu+yvAyiog54huUUWmYZwY3QVwXr6R1wsVudawM6BEl45QFq+hdB4t83azHG94XLy2NCAncohdU7zP40nsbvIDyh+4wIKeU90z6TLrXfHUYuBT6/ky7qOFm/Ym1QG4zCDz3jin8Qoa31PGaObzj/zoMJXgOXKcp16W0j9SZAenvnSfuWUEfBR1yBRR0T5Wg5v1vi7KGBTATaz8el802uliL+yZbGtMbNpAPGR5nK5C4yorf8yVYvIgo/LJaWCDND2O1e2mdut1WyRmvIwMnq7PFZT8zAsgGXfhDM= greg@ligma" >> /home/greg/.ssh/authorized_keys + +# Set hostname +INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) +AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) +HOSTNAME="$INSTANCE_ID-$AVAILABILITY_ZONE" +sudo hostnamectl set-hostname $HOSTNAME + +# Run cloud-init.sh script +# sudo sh /path/to/cloud-init.sh diff --git a/aws/aws_asg/modules/ec2/ec2-west/variables.tf b/aws/aws_asg/modules/ec2/ec2-west/variables.tf new file mode 100644 index 0000000..dd4bd97 --- /dev/null +++ b/aws/aws_asg/modules/ec2/ec2-west/variables.tf @@ -0,0 +1,32 @@ + +# Define variables +variable "min_size" { + type = number + description = "Minimum number of instances in the Auto Scaling Group" +} + +variable "max_size" { + type = number + description = "Maximum number of instances in the Auto Scaling Group" +} + +variable "us_west_subnet_1_id" { + description = "The ID of the first US West subnet" + type = string +} + +variable "us_west_subnet_2_id" { + description = "The ID of the second US West subnet" + type = string +} + +variable "us_west_subnet_3_id" { + description = "The ID of the third US West subnet" + type = string +} + +variable "vpc_id_west_2" { + description = "The ID of the VPC" + type = string +} + diff --git a/aws/aws_asg/modules/vpc/subnets/us-east/outputs.tf b/aws/aws_asg/modules/vpc/subnets/us-east/outputs.tf new file mode 100644 index 0000000..e73df5c --- /dev/null +++ b/aws/aws_asg/modules/vpc/subnets/us-east/outputs.tf @@ -0,0 +1,16 @@ +# In your vpc/subnets/us-east module + +output "us_east_subnet_1_id" { + description = "The ID of the first US East subnet" + value = aws_subnet.us_east_subnet_1.id +} + +output "us_east_subnet_2_id" { + description = "The ID of the second US East subnet" + value = aws_subnet.us_east_subnet_2.id +} + +output "us_east_subnet_3_id" { + description = "The ID of the third US East subnet" + value = aws_subnet.us_east_subnet_3.id +} diff --git a/aws/aws_simple/vpc/subnets/us-east/subnets-east.tf b/aws/aws_asg/modules/vpc/subnets/us-east/subnets-east.tf similarity index 77% rename from aws/aws_simple/vpc/subnets/us-east/subnets-east.tf rename to aws/aws_asg/modules/vpc/subnets/us-east/subnets-east.tf index a182a30..b15c20a 100644 --- a/aws/aws_simple/vpc/subnets/us-east/subnets-east.tf +++ b/aws/aws_asg/modules/vpc/subnets/us-east/subnets-east.tf @@ -1,30 +1,32 @@ - provider "aws" { region = "us-east-1" } resource "aws_subnet" "us_east_subnet_1" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_east_1 cidr_block = var.us_east_subnet_1_cidr_block availability_zone = var.us_east_subnet_1_az + map_public_ip_on_launch = true tags = { Name = "${var.region}_${var.us_east_subnet_1_az}_subnet" } } resource "aws_subnet" "us_east_subnet_2" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_east_1 cidr_block = var.us_east_subnet_2_cidr_block availability_zone = var.us_east_subnet_2_az + map_public_ip_on_launch = true tags = { Name = "${var.region}_${var.us_east_subnet_2_az}_subnet" } } resource "aws_subnet" "us_east_subnet_3" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_east_1 cidr_block = var.us_east_subnet_3_cidr_block availability_zone = var.us_east_subnet_3_az + map_public_ip_on_launch = true tags = { Name = "${var.region}_${var.us_east_subnet_3_az}_subnet" } diff --git a/aws/aws_simple/vpc/subnets/us-east/terraform.tfvars b/aws/aws_asg/modules/vpc/subnets/us-east/terraform.tfvars similarity index 100% rename from aws/aws_simple/vpc/subnets/us-east/terraform.tfvars rename to aws/aws_asg/modules/vpc/subnets/us-east/terraform.tfvars diff --git a/aws/aws_simple/vpc/subnets/us-east/variables.tf b/aws/aws_asg/modules/vpc/subnets/us-east/variables.tf similarity index 67% rename from aws/aws_simple/vpc/subnets/us-east/variables.tf rename to aws/aws_asg/modules/vpc/subnets/us-east/variables.tf index 784dc3a..e8b4108 100644 --- a/aws/aws_simple/vpc/subnets/us-east/variables.tf +++ b/aws/aws_asg/modules/vpc/subnets/us-east/variables.tf @@ -16,13 +16,19 @@ variable "region" { variable "us_east_subnet_1_cidr_block" { - default = "10.0.4.0/24" + default = "10.1.4.0/24" } variable "us_east_subnet_2_cidr_block" { - default = "10.0.5.0/24" + default = "10.1.5.0/24" } variable "us_east_subnet_3_cidr_block" { - default = "10.0.6.0/24" -} \ No newline at end of file + default = "10.1.6.0/24" +} + +variable "vpc_id_east_1" { + description = "The ID of the VPC" + type = string +} + diff --git a/aws/aws_asg/modules/vpc/subnets/us-west/outputs.tf b/aws/aws_asg/modules/vpc/subnets/us-west/outputs.tf new file mode 100644 index 0000000..9fa8450 --- /dev/null +++ b/aws/aws_asg/modules/vpc/subnets/us-west/outputs.tf @@ -0,0 +1,16 @@ +# In your vpc/subnets/us-east module + +output "us_west_subnet_1_id" { + description = "The ID of the first US East subnet" + value = aws_subnet.us_west_subnet_1.id +} + +output "us_west_subnet_2_id" { + description = "The ID of the second US East subnet" + value = aws_subnet.us_west_subnet_2.id +} + +output "us_west_subnet_3_id" { + description = "The ID of the third US East subnet" + value = aws_subnet.us_west_subnet_3.id +} \ No newline at end of file diff --git a/aws/aws_simple/vpc/subnets/us-west/subnets-west.tf b/aws/aws_asg/modules/vpc/subnets/us-west/subnets-west.tf similarity index 65% rename from aws/aws_simple/vpc/subnets/us-west/subnets-west.tf rename to aws/aws_asg/modules/vpc/subnets/us-west/subnets-west.tf index 07281c7..4e6d645 100644 --- a/aws/aws_simple/vpc/subnets/us-west/subnets-west.tf +++ b/aws/aws_asg/modules/vpc/subnets/us-west/subnets-west.tf @@ -1,27 +1,36 @@ +provider "aws" { + region = "us-west-2" +} resource "aws_subnet" "us_west_subnet_1" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_west_2 cidr_block = var.us_west_subnet_1_cidr_block availability_zone = var.us_west_subnet_1_az tags = { Name = "${var.region}_${var.us_west_subnet_1_az}_subnet" } + map_public_ip_on_launch = true + depends_on = [var.vpc_id_west_2] } resource "aws_subnet" "us_west_subnet_2" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_west_2 cidr_block = var.us_west_subnet_2_cidr_block availability_zone = var.us_west_subnet_2_az tags = { Name = "${var.region}_${var.us_west_subnet_2_az}_subnet" } + map_public_ip_on_launch = true + depends_on = [var.vpc_id_west_2] } resource "aws_subnet" "us_west_subnet_3" { - vpc_id = aws_vpc.my_vpc.id + vpc_id = var.vpc_id_west_2 cidr_block = var.us_west_subnet_3_cidr_block availability_zone = var.us_west_subnet_3_az tags = { Name = "${var.region}_${var.us_west_subnet_3_az}_subnet" } + map_public_ip_on_launch = true + depends_on = [var.vpc_id_west_2] } diff --git a/aws/aws_simple/vpc/subnets/us-west/terraform.tfvars b/aws/aws_asg/modules/vpc/subnets/us-west/terraform.tfvars similarity index 99% rename from aws/aws_simple/vpc/subnets/us-west/terraform.tfvars rename to aws/aws_asg/modules/vpc/subnets/us-west/terraform.tfvars index b43cf99..d8d98e3 100644 --- a/aws/aws_simple/vpc/subnets/us-west/terraform.tfvars +++ b/aws/aws_asg/modules/vpc/subnets/us-west/terraform.tfvars @@ -7,4 +7,3 @@ us_west_subnet_2_az = "us-west-2b" us_west_subnet_3_cidr_block = "10.0.3.0/24" us_west_subnet_3_az = "us-west-2c" - diff --git a/aws/aws_simple/vpc/subnets/us-west/variables.tf b/aws/aws_asg/modules/vpc/subnets/us-west/variables.tf similarity index 83% rename from aws/aws_simple/vpc/subnets/us-west/variables.tf rename to aws/aws_asg/modules/vpc/subnets/us-west/variables.tf index 14cba45..0237ab3 100644 --- a/aws/aws_simple/vpc/subnets/us-west/variables.tf +++ b/aws/aws_asg/modules/vpc/subnets/us-west/variables.tf @@ -25,4 +25,10 @@ variable "us_west_subnet_3_az" { variable "region" { default = "us-west-2" +} + + +variable "vpc_id_west_2" { + description = "The ID of the VPC" + type = string } \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-east/outputs.tf b/aws/aws_asg/modules/vpc/vpc-east/outputs.tf new file mode 100644 index 0000000..8695c74 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-east/outputs.tf @@ -0,0 +1,8 @@ +output "vpc_id_east_1" { + value = aws_vpc.vpc_us_east_1.id +} + +output "vpc_cidr_block" { + description = "The CIDR block of the VPC" + value = aws_vpc.vpc_us_east_1.cidr_block +} \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-east/terraform.tfvars b/aws/aws_asg/modules/vpc/vpc-east/terraform.tfvars new file mode 100644 index 0000000..a4b92a4 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-east/terraform.tfvars @@ -0,0 +1,2 @@ +vpc_cidr_block = "10.1.0.0/16" +region = "us-east-1" \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-east/variables.tf b/aws/aws_asg/modules/vpc/vpc-east/variables.tf new file mode 100644 index 0000000..a112697 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-east/variables.tf @@ -0,0 +1,23 @@ +variable "vpc_cidr_block" { + default = "10.1.0.0/16" +} + +variable "us_east_subnet_1_id" { + description = "The ID of the first US East subnet" + type = string +} + +variable "us_east_subnet_2_id" { + description = "The ID of the second US East subnet" + type = string +} + +variable "us_east_subnet_3_id" { + description = "The ID of the third US East subnet" + type = string +} + +variable "region" { + description = "The region to deploy to" + type = string +} \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-east/vpc-east.tf b/aws/aws_asg/modules/vpc/vpc-east/vpc-east.tf new file mode 100644 index 0000000..2cdeb8b --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-east/vpc-east.tf @@ -0,0 +1,42 @@ +provider "aws" { + region = "us-east-1" +} + +resource "aws_vpc" "vpc_us_east_1" { + cidr_block = var.vpc_cidr_block + tags = { + Name = "vpc_us_east_1" + Environment = "production" + } +} + +# Create aws internet gateway +resource "aws_internet_gateway" "my_igw_east_1" { + vpc_id = aws_vpc.vpc_us_east_1.id +} + +# Create route table entries for the east subnets +resource "aws_route_table" "us_east_route_table" { + vpc_id = aws_vpc.vpc_us_east_1.id +} + +resource "aws_route" "us_east_route" { + route_table_id = aws_route_table.us_east_route_table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.my_igw_east_1.id +} + +resource "aws_route_table_association" "us_east_subnet_1_association" { + subnet_id = var.us_east_subnet_1_id + route_table_id = aws_route_table.us_east_route_table.id +} + +resource "aws_route_table_association" "us_east_subnet_2_association" { + subnet_id = var.us_east_subnet_2_id + route_table_id = aws_route_table.us_east_route_table.id +} + +resource "aws_route_table_association" "us_east_subnet_3_association" { + subnet_id = var.us_east_subnet_3_id + route_table_id = aws_route_table.us_east_route_table.id +} diff --git a/aws/aws_asg/modules/vpc/vpc-west/outputs.tf b/aws/aws_asg/modules/vpc/vpc-west/outputs.tf new file mode 100644 index 0000000..62963e1 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-west/outputs.tf @@ -0,0 +1,8 @@ +output "vpc_id_west_2" { + value = aws_vpc.vpc_us_west_2.id +} + +output "vpc_cidr_block" { + description = "The CIDR block of the VPC" + value = aws_vpc.vpc_us_west_2.cidr_block +} \ No newline at end of file diff --git a/aws/aws_simple/vpc/terraform.tfvars b/aws/aws_asg/modules/vpc/vpc-west/terraform.tfvars similarity index 60% rename from aws/aws_simple/vpc/terraform.tfvars rename to aws/aws_asg/modules/vpc/vpc-west/terraform.tfvars index d0f2291..517c863 100644 --- a/aws/aws_simple/vpc/terraform.tfvars +++ b/aws/aws_asg/modules/vpc/vpc-west/terraform.tfvars @@ -1,2 +1,2 @@ vpc_cidr_block = "10.0.0.0/16" - +region = "us-west-2" \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-west/variables.tf b/aws/aws_asg/modules/vpc/vpc-west/variables.tf new file mode 100644 index 0000000..c901f87 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-west/variables.tf @@ -0,0 +1,23 @@ +variable "vpc_cidr_block" { + default = "10.0.0.0/16" +} + +variable "us_west_subnet_1_id" { + description = "The ID of the first US West subnet" + type = string +} + +variable "us_west_subnet_2_id" { + description = "The ID of the second US West subnet" + type = string +} + +variable "us_west_subnet_3_id" { + description = "The ID of the third US West subnet" + type = string +} + +variable "region" { + description = "The region to deploy to" + type = string +} \ No newline at end of file diff --git a/aws/aws_asg/modules/vpc/vpc-west/vpc-west.tf b/aws/aws_asg/modules/vpc/vpc-west/vpc-west.tf new file mode 100644 index 0000000..eed9b31 --- /dev/null +++ b/aws/aws_asg/modules/vpc/vpc-west/vpc-west.tf @@ -0,0 +1,46 @@ +provider "aws" { + region = var.region +} + +#Create aws vpc +resource "aws_vpc" "vpc_us_west_2" { + cidr_block = var.vpc_cidr_block + tags = { + Name = "vpc_us_west_1" + Environment = "production" + } +} + +# Create aws internet gateway +resource "aws_internet_gateway" "my_igw_west_2" { + vpc_id = aws_vpc.vpc_us_west_2.id +} + +# Create route table entries for the west subnets +resource "aws_route_table" "us_west_route_table" { + vpc_id = aws_vpc.vpc_us_west_2.id +} + +resource "aws_route" "us_west_route" { + route_table_id = aws_route_table.us_west_route_table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.my_igw_west_2.id +} + +resource "aws_route_table_association" "us_west_subnet_1_association" { + subnet_id = var.us_west_subnet_1_id + route_table_id = aws_route_table.us_west_route_table.id +} + +resource "aws_route_table_association" "us_west_subnet_2_association" { + subnet_id = var.us_west_subnet_2_id + route_table_id = aws_route_table.us_west_route_table.id +} + +resource "aws_route_table_association" "us_west_subnet_3_association" { + subnet_id = var.us_west_subnet_3_id + route_table_id = aws_route_table.us_west_route_table.id +} + + + diff --git a/aws/aws_simple/readme.md b/aws/aws_asg/readme.md similarity index 100% rename from aws/aws_simple/readme.md rename to aws/aws_asg/readme.md diff --git a/aws/aws_asg/terraform.tfvars b/aws/aws_asg/terraform.tfvars new file mode 100644 index 0000000..7bfa3a2 --- /dev/null +++ b/aws/aws_asg/terraform.tfvars @@ -0,0 +1,3 @@ +aws_secret_key = "" +aws_access_key = "" +aws_region = "us-west-2" diff --git a/aws/aws_simple/variables.tf b/aws/aws_asg/variables.tf similarity index 100% rename from aws/aws_simple/variables.tf rename to aws/aws_asg/variables.tf diff --git a/aws/aws_simple/ec2/ec2.tf b/aws/aws_simple/ec2/ec2.tf deleted file mode 100644 index 1245e58..0000000 --- a/aws/aws_simple/ec2/ec2.tf +++ /dev/null @@ -1,96 +0,0 @@ -# Define the VPC and subnets data sources -data "aws_vpc" "vpc" { - id = data.aws_subnet.subnet1.vpc_id -} - -module "vpc_subnets" { - source = "../vpc/subnets" -} - -data "aws_subnet" "subnet1" { - id = module.vpc_subnets.subnet_ids[0] -} - -data "aws_subnet" "subnet2" { - id = module.vpc_subnets.subnet_ids[1] -} - -data "aws_subnet" "subnet3" { - id = module.vpc_subnets.subnet_ids[2] -} - -data "aws_subnet" "subnet4" { - id = module.vpc_subnets.subnet_ids[3] -} - -data "aws_subnet" "subnet5" { - id = module.vpc_subnets.subnet_ids[4] -} - -data "aws_subnet" "subnet6" { - id = module.vpc_subnets.subnet_ids[5] -} - -# Create a security group for the EC2 instance -resource "aws_security_group" "instance" { - name_prefix = "instance-" - vpc_id = data.aws_vpc.vpc.id - - ingress { - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - ingress { - from_port = 443 - to_port = 443 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - tags = { - Name = "instance-security-group" - } -} - -# Define the Launch Configuration -resource "aws_launch_configuration" "lc" { - name_prefix = "lc-" - image_id = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI - instance_type = "t3.small" - security_groups = [ - aws_security_group.instance.id - ] - user_data = file("${path.module}/user-data.sh") - root_block_device { - volume_size = 20 - } -} - -# Define the Auto Scaling Group -resource "aws_autoscaling_group" "asg" { - name_prefix = "asg-" - launch_configuration = aws_launch_configuration.lc.id - vpc_zone_identifier = [ - data.aws_subnet.subnet1.id, - data.aws_subnet.subnet2.id - ] - min_size = var.min_size - max_size = var.max_size - desired_capacity = var.min_size - health_check_grace_period = 300 - health_check_type = "EC2" - termination_policies = ["OldestInstance"] - tag { - key = "Name" - value = "asg-instance" - propagate_at_launch = true - } -} - -# Output the instance public IP address -output "public_ip" { - value = aws_autoscaling_group.asg.instances[0].public_ip -} diff --git a/aws/aws_simple/ec2/terraform.tfvars b/aws/aws_simple/ec2/terraform.tfvars deleted file mode 100644 index e591122..0000000 --- a/aws/aws_simple/ec2/terraform.tfvars +++ /dev/null @@ -1,2 +0,0 @@ -min_size = 1 -max_size = 10 \ No newline at end of file diff --git a/aws/aws_simple/ec2/variables.tf b/aws/aws_simple/ec2/variables.tf deleted file mode 100644 index ad092af..0000000 --- a/aws/aws_simple/ec2/variables.tf +++ /dev/null @@ -1,13 +0,0 @@ - -# Define variables -variable "min_size" { - type = number - description = "Minimum number of instances in the Auto Scaling Group" - default = 1 -} - -variable "max_size" { - type = number - description = "Maximum number of instances in the Auto Scaling Group" - default = 1 -} diff --git a/aws/aws_simple/elb/main.tf b/aws/aws_simple/elb/main.tf deleted file mode 100644 index e69de29..0000000 diff --git a/aws/aws_simple/main.tf b/aws/aws_simple/main.tf deleted file mode 100644 index 7c01d7a..0000000 --- a/aws/aws_simple/main.tf +++ /dev/null @@ -1,40 +0,0 @@ -# Define provider -provider "aws" { - region = var.aws_region - access_key = var.aws_access_key - secret_key = var.aws_secret_key -} - -# Define modules -module "vpc_us_west" { - source = "./modules/vpc" -} - -module "subnet_us_west" { - source = "./modules/subnet" - vpc_id = module.vpc_us_west.vpc_id - region = "us-west-2" -} - -module "vpc_us_east" { - source = "./modules/vpc" - region = "us-east-1" -} - -module "subnet_us_east" { - source = "./modules/subnet" - vpc_id = module.vpc_us_east.vpc_id - region = "us-east-1" -} - -module "ec2" { - source = "./modules/ec2" -} - -module "elb" { - source = "./modules/elb" -} - -module "efs" { - source = "./modules/efs" -} diff --git a/aws/aws_simple/terraform.tfvars b/aws/aws_simple/terraform.tfvars deleted file mode 100644 index 0c441f7..0000000 --- a/aws/aws_simple/terraform.tfvars +++ /dev/null @@ -1,3 +0,0 @@ -aws_secret_key = "" -aws_access_key = "" -aws_region = "us-west-2" \ No newline at end of file diff --git a/aws/aws_simple/vpc/variables.tf b/aws/aws_simple/vpc/variables.tf deleted file mode 100644 index f8b2145..0000000 --- a/aws/aws_simple/vpc/variables.tf +++ /dev/null @@ -1,4 +0,0 @@ -variable "vpc_cidr_block" { - default = "10.0.0.0/16" -} - diff --git a/aws/aws_simple/vpc/vpc.tf b/aws/aws_simple/vpc/vpc.tf deleted file mode 100644 index 7072b79..0000000 --- a/aws/aws_simple/vpc/vpc.tf +++ /dev/null @@ -1,65 +0,0 @@ -#Create aws vpc -resource "aws_vpc" "my_vpc" { - cidr_block = var.vpc_cidr_block - tags = { - Name = "production-vpc" - Environment = "production" - } -} -# Create aws internet gateway -resource "aws_internet_gateway" "my_igw" { - vpc_id = aws_vpc.my_vpc.id -} - -# Create route table entries for the west subnets -resource "aws_route_table" "us_west_route_table" { - vpc_id = aws_vpc.my_vpc.id -} - -# Create route table entries for the east subnets -resource "aws_route_table" "us_east_route_table" { - vpc_id = aws_vpc.my_vpc.id -} - -resource "aws_route" "us_west_route" { - route_table_id = aws_route_table.us_west_route_table.id - destination_cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.my_igw.id -} - -resource "aws_route" "us_east_route" { - route_table_id = aws_route_table.us_east_route_table.id - destination_cidr_block = "0.0.0.0/0" - gateway_id = aws_internet_gateway.my_igw.id -} - -resource "aws_route_table_association" "us_west_subnet_1_association" { - subnet_id = aws_subnet.us_west_subnet_1.id - route_table_id = aws_route_table.us_west_route_table.id -} - -resource "aws_route_table_association" "us_west_subnet_2_association" { - subnet_id = aws_subnet.us_west_subnet_2.id - route_table_id = aws_route_table.us_west_route_table.id -} - -resource "aws_route_table_association" "us_west_subnet_3_association" { - subnet_id = aws_subnet.us_west_subnet_3.id - route_table_id = aws_route_table.us_west_route_table.id -} - -resource "aws_route_table_association" "us_east_subnet_1_association" { - subnet_id = aws_subnet.us_east_subnet_1.id - route_table_id = aws_route_table.us_east_route_table.id -} - -resource "aws_route_table_association" "us_east_subnet_2_association" { - subnet_id = aws_subnet.us_east_subnet_2.id - route_table_id = aws_route_table.us_east_route_table.id -} - -resource "aws_route_table_association" "us_east_subnet_3_association" { - subnet_id = aws_subnet.us_east_subnet_3.id - route_table_id = aws_route_table.us_east_route_table.id -} - diff --git a/aws/aws_vpc_peering/main.tf b/aws/aws_vpc_peering/main.tf new file mode 100644 index 0000000..316de91 --- /dev/null +++ b/aws/aws_vpc_peering/main.tf @@ -0,0 +1,337 @@ +terraform { + backend "s3" { + bucket = "my-tf-bucket-ghndrx" + key = "aws_vpc_peering/terraform.tfstate" + region = "us-west-2" + } +} + +# Define AWS provider with aliases for us-west-1 and us-east-1 regions +provider "aws" { + alias = "us-west-1" + region = "us-west-1" +} + +provider "aws" { + alias = "us-east-1" + region = "us-east-1" +} + +# Create VPCs in us-west-1 and us-east-1 regions +resource "aws_vpc" "us-west-1" { + cidr_block = "10.0.0.0/16" + provider = aws.us-west-1 +} + +resource "aws_vpc" "us-east-1" { + cidr_block = "10.1.0.0/16" + provider = aws.us-east-1 +} + +# Create subnets in us-west-1 VPC +resource "aws_subnet" "us-west-1-subnet-1" { + vpc_id = aws_vpc.us-west-1.id + cidr_block = "10.0.1.0/24" + availability_zone = "us-west-1c" + provider = aws.us-west-1 +} + +resource "aws_subnet" "us-west-1-subnet-2" { + vpc_id = aws_vpc.us-west-1.id + cidr_block = "10.0.2.0/24" + availability_zone = "us-west-1b" + provider = aws.us-west-1 +} + +# Create subnets in us-east-1 VPC +resource "aws_subnet" "us-east-1-subnet-1" { + vpc_id = aws_vpc.us-east-1.id + cidr_block = "10.1.1.0/24" + availability_zone = "us-east-1c" + provider = aws.us-east-1 +} + + + +resource "aws_subnet" "us-east-1-subnet-2" { + vpc_id = aws_vpc.us-east-1.id + cidr_block = "10.1.2.0/24" + availability_zone = "us-east-1b" + provider = aws.us-east-1 +} + +# Create VPC peering connection between us-west-1 and us-east-1 VPCs +resource "aws_vpc_peering_connection" "peering_connection" { + vpc_id = aws_vpc.us-west-1.id + peer_vpc_id = aws_vpc.us-east-1.id + peer_region = "us-east-1" + auto_accept = false + provider = aws.us-west-1 +} + +# Create VPC peering connection accepter in us-east-1 region +resource "aws_vpc_peering_connection_accepter" "peering_accepter" { + vpc_peering_connection_id = aws_vpc_peering_connection.peering_connection.id + auto_accept = true + + provider = aws.us-east-1 +} + +resource "aws_route" "peer-route-us-west-1" { + route_table_id = aws_route_table.us-west-1-route-table.id + destination_cidr_block = aws_vpc.us-east-1.cidr_block + vpc_peering_connection_id = aws_vpc_peering_connection.peering_connection.id + provider = aws.us-west-1 +} + +resource "aws_route" "peer-route-us-east-1" { + route_table_id = aws_route_table.us-east-1-route-table.id + destination_cidr_block = aws_vpc.us-west-1.cidr_block + vpc_peering_connection_id = aws_vpc_peering_connection.peering_connection.id + provider = aws.us-east-1 +} + +# Create route tables for each VPC and associate them with the respective subnets +resource "aws_route_table" "us-west-1-route-table" { + vpc_id = aws_vpc.us-west-1.id + provider = aws.us-west-1 +} + +resource "aws_route_table_association" "us-west-1-subnet-1-association" { + subnet_id = aws_subnet.us-west-1-subnet-1.id + route_table_id = aws_route_table.us-west-1-route-table.id + provider = aws.us-west-1 +} + +resource "aws_route_table_association" "us-west-1-subnet-2-association" { + subnet_id = aws_subnet.us-west-1-subnet-2.id + route_table_id = aws_route_table.us-west-1-route-table.id + provider = aws.us-west-1 +} + +resource "aws_route_table" "us-east-1-route-table" { + vpc_id = aws_vpc.us-east-1.id + provider = aws.us-east-1 +} + +resource "aws_route_table_association" "us-east-1-subnet-1-association" { + subnet_id = aws_subnet.us-east-1-subnet-1.id + route_table_id = aws_route_table.us-east-1-route-table.id + provider = aws.us-east-1 +} + +resource "aws_route_table_association" "us-east-1-subnet-2-association" { + subnet_id = aws_subnet.us-east-1-subnet-2.id + route_table_id = aws_route_table.us-east-1-route-table.id + provider = aws.us-east-1 +} + + +# Create internet gateway for us-west-1 VPC +resource "aws_internet_gateway" "us-west-1-igw" { + vpc_id = aws_vpc.us-west-1.id + provider = aws.us-west-1 + + tags = { + Name = "us-west-1-igw" + } +} + +# Create internet gateway for us-east-1 VPC +resource "aws_internet_gateway" "us-east-1-igw" { + vpc_id = aws_vpc.us-east-1.id + provider = aws.us-east-1 + + tags = { + Name = "us-east-1-igw" + } +} + +# Attach internet gateway to the route table of each VPC +resource "aws_route" "us-west-1-igw-route" { + route_table_id = aws_route_table.us-west-1-route-table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.us-west-1-igw.id + provider = aws.us-west-1 +} + +resource "aws_route" "us-east-1-igw-route" { + route_table_id = aws_route_table.us-east-1-route-table.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.us-east-1-igw.id + provider = aws.us-east-1 +} + +# Create security groups for EC2 instances +resource "aws_security_group" "us-west-1-instance-sg" { + vpc_id = aws_vpc.us-west-1.id + provider = aws.us-west-1 + tags = { + Name = "instance-west-security-group" + } + + # Allow inbound SSH, HTTP, and HTTPS traffic from any source + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # Allow outbound traffic to all private subnets in the VPC + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["10.1.0.0/16", "0.0.0.0/0"] + } + ingress { + from_port = -1 + to_port = -1 + protocol = "icmp" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_security_group" "us-east-1-instance-sg" { + vpc_id = aws_vpc.us-east-1.id + provider = aws.us-east-1 + tags = { + Name = "instance-east-security-group" + } + + # Allow inbound SSH, HTTP, and HTTPS traffic from any source + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + # Allow outbound traffic to all private subnets in the VPC + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["10.1.0.0/16", "0.0.0.0/0"] + } + ingress { + from_port = -1 + to_port = -1 + protocol = "icmp" + cidr_blocks = ["0.0.0.0/0"] + } +} + +# Create EC2 instances in each subnet +resource "aws_instance" "us-west-1-instance-1" { + ami = "ami-0f3f6663da6750955" # Ubuntu 20.04 AMI + instance_type = "t3.small" # Add instance type + subnet_id = aws_subnet.us-west-1-subnet-1.id + vpc_security_group_ids = [aws_security_group.us-west-1-instance-sg.id] + associate_public_ip_address = true # Set ephemeral public IP address + user_data = base64encode(file("${path.module}/user-data.sh")) + # Other necessary configurations for the instance + provider = aws.us-west-1 + # ... + tags = { + Name = "us-west-1-instance-1" + SecurityGroup = "instance-west-security-group" + } +} + +resource "aws_instance" "us-west-1-instance-2" { + ami = "ami-0f3f6663da6750955" # Ubuntu 20.04 AMI + instance_type = "t3.small" # Add instance type + subnet_id = aws_subnet.us-west-1-subnet-2.id + vpc_security_group_ids = [aws_security_group.us-west-1-instance-sg.id] + associate_public_ip_address = true # Set ephemeral public IP address + user_data = base64encode(file("${path.module}/user-data.sh")) + # Other necessary configurations for the instance + provider = aws.us-west-1 + # ... + tags = { + Name = "us-west-1-instance-2" + SecurityGroup = "instance-west-security-group" + } +} + +resource "aws_instance" "us-east-1-instance-1" { + ami = "ami-04e369782a6d2125e" # Ubuntu 20.04 AMI + instance_type = "t3.small" # Add instance type + subnet_id = aws_subnet.us-east-1-subnet-1.id + vpc_security_group_ids = [aws_security_group.us-east-1-instance-sg.id] + associate_public_ip_address = true # Set ephemeral public IP address + user_data = base64encode(file("${path.module}/user-data.sh")) + # Other necessary configurations for the instance + provider = aws.us-east-1 + # ... + tags = { + Name = "us-east-1-instance-1" + SecurityGroup = "instance-east-security-group" + } +} + +resource "aws_instance" "us-east-1-instance-2" { + ami = "ami-04e369782a6d2125e" # Ubuntu 20.04 AMI + instance_type = "t3.small" # Add instance type + subnet_id = aws_subnet.us-east-1-subnet-2.id + vpc_security_group_ids = [aws_security_group.us-east-1-instance-sg.id] + associate_public_ip_address = true # Set ephemeral public IP address + user_data = base64encode(file("${path.module}/user-data.sh")) + # Other necessary configurations for the instance + provider = aws.us-east-1 + # ... + tags = { + Name = "us-east-1-instance-2" + SecurityGroup = "instance-east-security-group" + } +} + +# ... + +output "us-west-1-instance-1-public-ip" { + value = aws_instance.us-west-1-instance-1.public_ip +} + +output "us-west-1-instance-2-public-ip" { + value = aws_instance.us-west-1-instance-2.public_ip +} + +output "us-east-1-instance-1-public-ip" { + value = aws_instance.us-east-1-instance-1.public_ip +} + +output "us-east-1-instance-2-public-ip" { + value = aws_instance.us-east-1-instance-2.public_ip +} + + diff --git a/aws/aws_vpc_peering/user-data.sh b/aws/aws_vpc_peering/user-data.sh new file mode 100644 index 0000000..bbf36b4 --- /dev/null +++ b/aws/aws_vpc_peering/user-data.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Install necessary packages +sudo apt-get update +sudo apt-get install -y git amazon-efs-utils vim-nox neofetch htop tmux curl wget nginx + +# Create new user with sudo privileges +sudo useradd -m -s /bin/bash greg +sudo usermod -aG sudo greg + +# Add authorized keys for your public key +sudo mkdir -p /home/greg/.ssh +sudo touch /home/greg/.ssh/authorized_keys +sudo chmod 700 /home/greg/.ssh +sudo chmod 600 /home/greg/.ssh/authorized_keys +sudo chown -R greg:greg /home/greg/.ssh + +# Add your public key to authorized_keys +sudo echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCdOF80z0piQEnYzNCu2OGvOJdm7+3wfDuiC+Jzi8VbSC5VW4iJAQXOuDNGLzyqNi6uMjI77xpEL6Xzn29uJiQti6Y/LxhOZwNNIQiGUpFco1wkBYeBFbtgHQxsMLwumrxQGEj2fyCiSrACAPyy/l1fP4mlN7abBGD5aozBrYKxXPS/kfwO5nsWmw27RgTzfHJzie2dUU3ew/kd7td3wEdWrRXq8wNbu+yvAyiog54huUUWmYZwY3QVwXr6R1wsVudawM6BEl45QFq+hdB4t83azHG94XLy2NCAncohdU7zP40nsbvIDyh+4wIKeU90z6TLrXfHUYuBT6/ky7qOFm/Ym1QG4zCDz3jin8Qoa31PGaObzj/zoMJXgOXKcp16W0j9SZAenvnSfuWUEfBR1yBRR0T5Wg5v1vi7KGBTATaz8el802uliL+yZbGtMbNpAPGR5nK5C4yorf8yVYvIgo/LJaWCDND2O1e2mdut1WyRmvIwMnq7PFZT8zAsgGXfhDM= greg@ligma" >> /home/greg/.ssh/authorized_keys + +# Set hostname +INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) +AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) +HOSTNAME="$INSTANCE_ID-$AVAILABILITY_ZONE" +sudo hostnamectl set-hostname $HOSTNAME + +echo "hello world" >> /var/www/html/index.html +systemctm restart nginx + +# Run cloud-init.sh script +# sudo sh /path/to/cloud-init.sh diff --git a/aws/s3/main.tf b/aws/s3/main.tf new file mode 100644 index 0000000..a0735a5 --- /dev/null +++ b/aws/s3/main.tf @@ -0,0 +1,24 @@ +# Provider configuration +provider "aws" { + region = "us-west-2" + # Add your AWS access and secret keys here + +} + +resource "aws_s3_bucket" "my-tf-bucket-ghndrx" { + bucket = "my-tf-bucket-ghndrx" + + tags = { + Name = "tf-backend" + Environment = "production" + } +} + +# Output the bucket name +output "my-tf-bucket-ghndrx" { + value = aws_s3_bucket.my-tf-bucket-ghndrx.bucket +} + + + + diff --git a/aws/terraform-backend/main.tf b/aws/terraform-backend/main.tf new file mode 100644 index 0000000..e89474e --- /dev/null +++ b/aws/terraform-backend/main.tf @@ -0,0 +1,9 @@ +terraform { + backend "s3" { + bucket = "my-tf-bucket-ghndrx" + key = "terraform.tfstate" + region = "us-west-2" + } +} + +# Rest of your Terraform configuration goes here...