mirror of
https://github.com/ghndrx/terraform.git
synced 2026-02-10 06:45:01 +00:00
TODO: fix efs later. s3 backend created
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -4,3 +4,11 @@ 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
|
||||
aws/aws_simple/.terraform.tfstate.lock.info
|
||||
aws/backend/terraform.tfstate
|
||||
aws/s3/.terraform.lock.hcl
|
||||
aws/s3/terraform.tfstate
|
||||
aws/s3/terraform.tfstate.backup
|
||||
aws/s3/.terraform/providers/registry.terraform.io/hashicorp/aws/5.26.0/linux_amd64/terraform-provider-aws_v5.26.0_x5
|
||||
aws/aws_simple/.terraform/providers/registry.terraform.io/hashicorp/template/2.2.0/linux_amd64/terraform-provider-template_v2.2.0_x4
|
||||
aws/aws_simple/.terraform/providers/registry.terraform.io/hashicorp/aws/5.26.0/linux_amd64/terraform-provider-aws_v5.26.0_x5
|
||||
aws/aws_simple/.terraform/terraform.tfstate
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "my-tf-bucket-ghndrx"
|
||||
key = "terraform.tfstate"
|
||||
region = "us-west-2"
|
||||
}
|
||||
}
|
||||
# Define provider
|
||||
provider "aws" {
|
||||
region = var.aws_region
|
||||
@@ -31,9 +38,11 @@ module "subnets_us_east" {
|
||||
vpc_id_east_1 = module.vpc-east.vpc_id_east_1
|
||||
}
|
||||
|
||||
module "ec2" {
|
||||
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
|
||||
@@ -44,6 +53,8 @@ module "ec2" {
|
||||
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
|
||||
@@ -58,4 +69,12 @@ module "elb" {
|
||||
|
||||
module "efs" {
|
||||
source = "./modules/efs"
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
resource "aws_efs_file_system" "efs" {
|
||||
creation_token = "efs-asg-west-east"
|
||||
encrypted = true
|
||||
performance_mode = "generalPurpose"
|
||||
throughput_mode = "bursting"
|
||||
}
|
||||
|
||||
|
||||
|
||||
resource "aws_efs_mount_target" "us_west_subnet_1" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_west_subnet_1_id
|
||||
depends_on = [var.us_west_subnet_1_id]
|
||||
}
|
||||
|
||||
resource "aws_efs_mount_target" "us_west_subnet_2" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_west_subnet_2_id
|
||||
depends_on = [var.us_west_subnet_2_id]
|
||||
}
|
||||
|
||||
resource "aws_efs_mount_target" "us_west_subnet_3" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_west_subnet_3_id
|
||||
depends_on = [var.us_west_subnet_3_id]
|
||||
}
|
||||
|
||||
data "template_file" "mount_script" {
|
||||
template = <<EOF
|
||||
#!/bin/bash
|
||||
yum install -y amazon-efs-utils
|
||||
mkdir -p /mnt/efs
|
||||
echo "${aws_efs_file_system.efs.dns_name}:/ /mnt/efs efs defaults,_netdev 0 0" >> /etc/fstab
|
||||
mount -a -t efs,nfs4 defaults
|
||||
EOF
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = "us-east-1"
|
||||
|
||||
|
||||
}
|
||||
|
||||
resource "aws_efs_mount_target" "us_east_subnet_1" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_east_subnet_1_id
|
||||
depends_on = [var.us_east_subnet_1_id]
|
||||
}
|
||||
|
||||
resource "aws_efs_mount_target" "us_east_subnet_2" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_east_subnet_2_id
|
||||
depends_on = [var.us_east_subnet_2_id]
|
||||
}
|
||||
|
||||
resource "aws_efs_mount_target" "us_east_subnet_3" {
|
||||
file_system_id = aws_efs_file_system.efs.id
|
||||
subnet_id = var.us_east_subnet_3_id
|
||||
depends_on = [var.us_east_subnet_3_id]
|
||||
}
|
||||
0
aws/aws_simple/modules/efs/outputs.tf
Normal file
0
aws/aws_simple/modules/efs/outputs.tf
Normal file
31
aws/aws_simple/modules/efs/variables.tf
Normal file
31
aws/aws_simple/modules/efs/variables.tf
Normal file
@@ -0,0 +1,31 @@
|
||||
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 East subnet"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "us_west_subnet_2_id" {
|
||||
description = "The ID of the second US East subnet"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "us_west_subnet_3_id" {
|
||||
description = "The ID of the third US East subnet"
|
||||
type = string
|
||||
}
|
||||
|
||||
|
||||
9
aws/backend/main.tf
Normal file
9
aws/backend/main.tf
Normal file
@@ -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...
|
||||
24
aws/s3/main.tf
Normal file
24
aws/s3/main.tf
Normal file
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user