mirror of
https://github.com/ghndrx/terraform.git
synced 2026-02-10 06:45:01 +00:00
add updates to all in aws_simple
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
aws/aws_simple/.terraform.lock.hcl
|
||||||
|
aws/aws_simple/.terraform/modules/modules.json
|
||||||
|
aws/aws_simple/terraform.tfstate.backup
|
||||||
|
aws/aws_simple/terraform.tfstate
|
||||||
|
aws/aws_simple/.terraform/providers/registry.terraform.io/hashicorp/aws/5.25.0/linux_amd64/terraform-provider-aws_v5.25.0_x5
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,43 @@
|
|||||||
# Define provider
|
# Define provider
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = var.aws_region
|
region = var.aws_region
|
||||||
access_key = var.aws_access_key
|
|
||||||
secret_key = var.aws_secret_key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define modules
|
# Define modules
|
||||||
module "vpc_us_west" {
|
module "vpc_us" {
|
||||||
source = "./modules/vpc"
|
source = "./modules/vpc"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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 "subnet_us_west" {
|
module "subnets_us_west" {
|
||||||
source = "./modules/subnet"
|
source = "./modules/vpc/subnets/us-west"
|
||||||
vpc_id = module.vpc_us_west.vpc_id
|
vpc_id = module.vpc_us.vpc_id
|
||||||
region = "us-west-2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module "vpc_us_east" {
|
module "subnets_us_east" {
|
||||||
source = "./modules/vpc"
|
source = "./modules/vpc/subnets/us-east"
|
||||||
region = "us-east-1"
|
vpc_id = module.vpc_us.vpc_id
|
||||||
}
|
|
||||||
|
|
||||||
module "subnet_us_east" {
|
|
||||||
source = "./modules/subnet"
|
|
||||||
vpc_id = module.vpc_us_east.vpc_id
|
|
||||||
region = "us-east-1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module "ec2" {
|
module "ec2" {
|
||||||
source = "./modules/ec2"
|
source = "./modules/ec2"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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 = module.vpc_us.vpc_id
|
||||||
}
|
}
|
||||||
|
|
||||||
module "elb" {
|
module "elb" {
|
||||||
|
|||||||
@@ -1,40 +1,36 @@
|
|||||||
# Define the VPC and subnets data sources
|
# Define the VPC and subnets data sources
|
||||||
data "aws_vpc" "vpc" {
|
data "aws_vpc" "vpc" {
|
||||||
id = data.aws_subnet.subnet1.vpc_id
|
id = var.vpc_id
|
||||||
}
|
|
||||||
|
|
||||||
module "vpc_subnets" {
|
|
||||||
source = "../vpc/subnets"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet1" {
|
data "aws_subnet" "subnet1" {
|
||||||
id = module.vpc_subnets.subnet_ids[0]
|
id = var.us_east_subnet_1_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet2" {
|
data "aws_subnet" "subnet2" {
|
||||||
id = module.vpc_subnets.subnet_ids[1]
|
id = var.us_east_subnet_2_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet3" {
|
data "aws_subnet" "subnet3" {
|
||||||
id = module.vpc_subnets.subnet_ids[2]
|
id = var.us_east_subnet_3_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet4" {
|
data "aws_subnet" "subnet4" {
|
||||||
id = module.vpc_subnets.subnet_ids[3]
|
id = var.us_west_subnet_1_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet5" {
|
data "aws_subnet" "subnet5" {
|
||||||
id = module.vpc_subnets.subnet_ids[4]
|
id = var.us_west_subnet_2_id
|
||||||
}
|
}
|
||||||
|
|
||||||
data "aws_subnet" "subnet6" {
|
data "aws_subnet" "subnet6" {
|
||||||
id = module.vpc_subnets.subnet_ids[5]
|
id = var.us_west_subnet_3_id
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a security group for the EC2 instance
|
# Create a security group for the EC2 instance
|
||||||
resource "aws_security_group" "instance" {
|
resource "aws_security_group" "instance" {
|
||||||
name_prefix = "instance-"
|
name_prefix = "instance-"
|
||||||
vpc_id = data.aws_vpc.vpc.id
|
vpc_id = var.vpc_id
|
||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
from_port = 80
|
from_port = 80
|
||||||
@@ -73,9 +69,23 @@ resource "aws_launch_configuration" "lc" {
|
|||||||
resource "aws_autoscaling_group" "asg" {
|
resource "aws_autoscaling_group" "asg" {
|
||||||
name_prefix = "asg-"
|
name_prefix = "asg-"
|
||||||
launch_configuration = aws_launch_configuration.lc.id
|
launch_configuration = aws_launch_configuration.lc.id
|
||||||
|
depends_on = [
|
||||||
|
var.vpc_id,
|
||||||
|
aws_launch_configuration.lc,
|
||||||
|
data.aws_subnet.subnet1,
|
||||||
|
data.aws_subnet.subnet2,
|
||||||
|
data.aws_subnet.subnet3,
|
||||||
|
data.aws_subnet.subnet4,
|
||||||
|
data.aws_subnet.subnet5,
|
||||||
|
data.aws_subnet.subnet6
|
||||||
|
]
|
||||||
vpc_zone_identifier = [
|
vpc_zone_identifier = [
|
||||||
data.aws_subnet.subnet1.id,
|
data.aws_subnet.subnet1.id,
|
||||||
data.aws_subnet.subnet2.id
|
data.aws_subnet.subnet2.id,
|
||||||
|
data.aws_subnet.subnet3.id,
|
||||||
|
data.aws_subnet.subnet4.id,
|
||||||
|
data.aws_subnet.subnet5.id,
|
||||||
|
data.aws_subnet.subnet6.id
|
||||||
]
|
]
|
||||||
min_size = var.min_size
|
min_size = var.min_size
|
||||||
max_size = var.max_size
|
max_size = var.max_size
|
||||||
@@ -90,7 +100,8 @@ resource "aws_autoscaling_group" "asg" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Output the instance public IP address
|
data "aws_instances" "asg_instances" {
|
||||||
output "public_ip" {
|
instance_tags = {
|
||||||
value = aws_autoscaling_group.asg.instances[0].public_ip
|
"aws:autoscaling:groupName" = aws_autoscaling_group.asg.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
4
aws/aws_simple/modules/ec2/outputs.tf
Normal file
4
aws/aws_simple/modules/ec2/outputs.tf
Normal file
@@ -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]
|
||||||
|
# }
|
||||||
@@ -16,7 +16,8 @@ sudo chmod 600 /home/greg/.ssh/authorized_keys
|
|||||||
sudo chown -R greg:greg /home/greg/.ssh
|
sudo chown -R greg:greg /home/greg/.ssh
|
||||||
|
|
||||||
# Add your public key to authorized_keys
|
# Add your public key to authorized_keys
|
||||||
sudo echo "YOUR_PUBLIC_KEY" >> /home/greg/.ssh/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
|
# Set hostname
|
||||||
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
|
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
|
||||||
@@ -25,4 +26,4 @@ HOSTNAME="$INSTANCE_ID-$AVAILABILITY_ZONE"
|
|||||||
sudo hostnamectl set-hostname $HOSTNAME
|
sudo hostnamectl set-hostname $HOSTNAME
|
||||||
|
|
||||||
# Run cloud-init.sh script
|
# Run cloud-init.sh script
|
||||||
sudo sh /path/to/cloud-init.sh
|
# sudo sh /path/to/cloud-init.sh
|
||||||
49
aws/aws_simple/modules/ec2/variables.tf
Normal file
49
aws/aws_simple/modules/ec2/variables.tf
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 "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" {
|
||||||
|
description = "The ID of the VPC"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
3
aws/aws_simple/modules/vpc/outputs.tf
Normal file
3
aws/aws_simple/modules/vpc/outputs.tf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
output "vpc_id" {
|
||||||
|
value = aws_vpc.vpc_us.id
|
||||||
|
}
|
||||||
16
aws/aws_simple/modules/vpc/subnets/us-east/outputs.tf
Normal file
16
aws/aws_simple/modules/vpc/subnets/us-east/outputs.tf
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,31 +1,36 @@
|
|||||||
|
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-east-1"
|
region = var.region
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "us_east_subnet_1" {
|
resource "aws_subnet" "us_east_subnet_1" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_east_subnet_1_cidr_block
|
cidr_block = var.us_east_subnet_1_cidr_block
|
||||||
availability_zone = var.us_east_subnet_1_az
|
availability_zone = var.us_east_subnet_1_az
|
||||||
tags = {
|
tags = {
|
||||||
Name = "${var.region}_${var.us_east_subnet_1_az}_subnet"
|
Name = "${var.region}_${var.us_east_subnet_1_az}_subnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depends_on = [var.vpc_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "us_east_subnet_2" {
|
resource "aws_subnet" "us_east_subnet_2" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_east_subnet_2_cidr_block
|
cidr_block = var.us_east_subnet_2_cidr_block
|
||||||
availability_zone = var.us_east_subnet_2_az
|
availability_zone = var.us_east_subnet_2_az
|
||||||
tags = {
|
tags = {
|
||||||
Name = "${var.region}_${var.us_east_subnet_2_az}_subnet"
|
Name = "${var.region}_${var.us_east_subnet_2_az}_subnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depends_on = [var.vpc_id]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "us_east_subnet_3" {
|
resource "aws_subnet" "us_east_subnet_3" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_east_subnet_3_cidr_block
|
cidr_block = var.us_east_subnet_3_cidr_block
|
||||||
availability_zone = var.us_east_subnet_3_az
|
availability_zone = var.us_east_subnet_3_az
|
||||||
tags = {
|
tags = {
|
||||||
Name = "${var.region}_${var.us_east_subnet_3_az}_subnet"
|
Name = "${var.region}_${var.us_east_subnet_3_az}_subnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depends_on = [var.vpc_id]
|
||||||
}
|
}
|
||||||
@@ -25,4 +25,9 @@ variable "us_east_subnet_2_cidr_block" {
|
|||||||
|
|
||||||
variable "us_east_subnet_3_cidr_block" {
|
variable "us_east_subnet_3_cidr_block" {
|
||||||
default = "10.0.6.0/24"
|
default = "10.0.6.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vpc_id" {
|
||||||
|
description = "The ID of the VPC"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
16
aws/aws_simple/modules/vpc/subnets/us-west/outputs.tf
Normal file
16
aws/aws_simple/modules/vpc/subnets/us-west/outputs.tf
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
resource "aws_subnet" "us_west_subnet_1" {
|
resource "aws_subnet" "us_west_subnet_1" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_west_subnet_1_cidr_block
|
cidr_block = var.us_west_subnet_1_cidr_block
|
||||||
availability_zone = var.us_west_subnet_1_az
|
availability_zone = var.us_west_subnet_1_az
|
||||||
tags = {
|
tags = {
|
||||||
@@ -9,7 +8,7 @@ resource "aws_subnet" "us_west_subnet_1" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "us_west_subnet_2" {
|
resource "aws_subnet" "us_west_subnet_2" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_west_subnet_2_cidr_block
|
cidr_block = var.us_west_subnet_2_cidr_block
|
||||||
availability_zone = var.us_west_subnet_2_az
|
availability_zone = var.us_west_subnet_2_az
|
||||||
tags = {
|
tags = {
|
||||||
@@ -18,7 +17,7 @@ resource "aws_subnet" "us_west_subnet_2" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_subnet" "us_west_subnet_3" {
|
resource "aws_subnet" "us_west_subnet_3" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = var.vpc_id
|
||||||
cidr_block = var.us_west_subnet_3_cidr_block
|
cidr_block = var.us_west_subnet_3_cidr_block
|
||||||
availability_zone = var.us_west_subnet_3_az
|
availability_zone = var.us_west_subnet_3_az
|
||||||
tags = {
|
tags = {
|
||||||
@@ -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_cidr_block = "10.0.3.0/24"
|
||||||
us_west_subnet_3_az = "us-west-2c"
|
us_west_subnet_3_az = "us-west-2c"
|
||||||
|
|
||||||
@@ -25,4 +25,9 @@ variable "us_west_subnet_3_az" {
|
|||||||
|
|
||||||
variable "region" {
|
variable "region" {
|
||||||
default = "us-west-2"
|
default = "us-west-2"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vpc_id" {
|
||||||
|
description = "The ID of the VPC"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
8
aws/aws_simple/modules/vpc/terraform.tfvars
Normal file
8
aws/aws_simple/modules/vpc/terraform.tfvars
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
vpc_cidr_block = "10.0.0.0/16"
|
||||||
|
|
||||||
|
us_east_subnet_1_id = ""
|
||||||
|
us_east_subnet_2_id = ""
|
||||||
|
us_east_subnet_3_id = ""
|
||||||
|
us_west_subnet_1_id = ""
|
||||||
|
us_west_subnet_2_id = ""
|
||||||
|
us_west_subnet_3_id = ""
|
||||||
33
aws/aws_simple/modules/vpc/variables.tf
Normal file
33
aws/aws_simple/modules/vpc/variables.tf
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
variable "vpc_cidr_block" {
|
||||||
|
default = "10.0.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 "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
|
||||||
|
}
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
#Create aws vpc
|
#Create aws vpc
|
||||||
resource "aws_vpc" "my_vpc" {
|
resource "aws_vpc" "vpc_us" {
|
||||||
cidr_block = var.vpc_cidr_block
|
cidr_block = var.vpc_cidr_block
|
||||||
tags = {
|
tags = {
|
||||||
Name = "production-vpc"
|
Name = "vpc_us"
|
||||||
Environment = "production"
|
Environment = "production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Create aws internet gateway
|
# Create aws internet gateway
|
||||||
resource "aws_internet_gateway" "my_igw" {
|
resource "aws_internet_gateway" "my_igw" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = aws_vpc.vpc_us.id
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create route table entries for the west subnets
|
# Create route table entries for the west subnets
|
||||||
resource "aws_route_table" "us_west_route_table" {
|
resource "aws_route_table" "us_west_route_table" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = aws_vpc.vpc_us.id
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create route table entries for the east subnets
|
# Create route table entries for the east subnets
|
||||||
resource "aws_route_table" "us_east_route_table" {
|
resource "aws_route_table" "us_east_route_table" {
|
||||||
vpc_id = aws_vpc.my_vpc.id
|
vpc_id = aws_vpc.vpc_us.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route" "us_west_route" {
|
resource "aws_route" "us_west_route" {
|
||||||
@@ -34,32 +34,32 @@ resource "aws_route" "us_east_route" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_west_subnet_1_association" {
|
resource "aws_route_table_association" "us_west_subnet_1_association" {
|
||||||
subnet_id = aws_subnet.us_west_subnet_1.id
|
subnet_id = var.us_west_subnet_1_id
|
||||||
route_table_id = aws_route_table.us_west_route_table.id
|
route_table_id = aws_route_table.us_west_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_west_subnet_2_association" {
|
resource "aws_route_table_association" "us_west_subnet_2_association" {
|
||||||
subnet_id = aws_subnet.us_west_subnet_2.id
|
subnet_id = var.us_west_subnet_2_id
|
||||||
route_table_id = aws_route_table.us_west_route_table.id
|
route_table_id = aws_route_table.us_west_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_west_subnet_3_association" {
|
resource "aws_route_table_association" "us_west_subnet_3_association" {
|
||||||
subnet_id = aws_subnet.us_west_subnet_3.id
|
subnet_id = var.us_west_subnet_3_id
|
||||||
route_table_id = aws_route_table.us_west_route_table.id
|
route_table_id = aws_route_table.us_west_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_east_subnet_1_association" {
|
resource "aws_route_table_association" "us_east_subnet_1_association" {
|
||||||
subnet_id = aws_subnet.us_east_subnet_1.id
|
subnet_id = var.us_east_subnet_1_id
|
||||||
route_table_id = aws_route_table.us_east_route_table.id
|
route_table_id = aws_route_table.us_east_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_east_subnet_2_association" {
|
resource "aws_route_table_association" "us_east_subnet_2_association" {
|
||||||
subnet_id = aws_subnet.us_east_subnet_2.id
|
subnet_id = var.us_east_subnet_2_id
|
||||||
route_table_id = aws_route_table.us_east_route_table.id
|
route_table_id = aws_route_table.us_east_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_route_table_association" "us_east_subnet_3_association" {
|
resource "aws_route_table_association" "us_east_subnet_3_association" {
|
||||||
subnet_id = aws_subnet.us_east_subnet_3.id
|
subnet_id = var.us_east_subnet_3_id
|
||||||
route_table_id = aws_route_table.us_east_route_table.id
|
route_table_id = aws_route_table.us_east_route_table.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
aws_secret_key = ""
|
aws_secret_key = ""
|
||||||
aws_access_key = ""
|
aws_access_key = ""
|
||||||
aws_region = "us-west-2"
|
aws_region = "us-west-2"
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
vpc_cidr_block = "10.0.0.0/16"
|
|
||||||
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
variable "vpc_cidr_block" {
|
|
||||||
default = "10.0.0.0/16"
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user