Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
25 changes: 25 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DBurse-Terraform
19 changes: 19 additions & 0 deletions Variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#--- root/variables.tf

variable "ami_id" {
description = "ec2 ami_id"
type = string
default = "ami-033cfb3e88287e319"
}

variable "instance" {
description = "instance type"
type = string
default = "t2.micro"
}

variable "region" {
description = "instance region"
type = string
default = "us-east-1"
}
24 changes: 0 additions & 24 deletions ec2.tf
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = "us-west-2"
}

resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"

tags = {
Name = "ExampleAppServerInstance"
}
}
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#---root/main.tf

resource "aws_instance" "db_server" {
ami = "ami-033cfb3e88287e319"
instance_type = "t2.micro"

tags = {
Name = "db_tag"
}
}
5 changes: 5 additions & 0 deletions module-ec2/child-Variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#---ChildModule/Variables.tf

variable "ami_id" {}
variable "instance" {}
variable "region" {}
5 changes: 5 additions & 0 deletions module-ec2/child-main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#---ChildModule/main.tf

module "terraformec2" {
source = "./module-ec2/terraformec2/"
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#---root/outputs.tf

output "public_ip" {
value = aws_instance.db_server.public_ip
}

output "ec2_tags" {
value = aws_instance.db_server.tags_all.Name
}
17 changes: 17 additions & 0 deletions provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#---root/provider.tf

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
profile = "default"
region = "us-east-1"
}
61 changes: 61 additions & 0 deletions resize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}

# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/region)

# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
--instance-id $INSTANCEID \
--query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
--output text \
--region $REGION)

# Resize the EBS volume.
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE

# Wait for the resize to finish.
while [ \
"$(aws ec2 describe-volumes-modifications \
--volume-id $VOLUMEID \
--filters Name=modification-state,Values="optimizing","completed" \
--query "length(VolumesModifications)"\
--output text)" != "1" ]; do
sleep 1
done

#Check if we're on an NVMe filesystem
if [[ -e "/dev/xvda" && $(readlink -f /dev/xvda) = "/dev/xvda" ]]
then
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/xvda 1

# Expand the size of the file system.
# Check if we're on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/xvda1
fi

else
# Rewrite the partition table so that the partition takes up all the space that it can.
sudo growpart /dev/nvme0n1 1

# Expand the size of the file system.
# Check if we're on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
then
sudo xfs_growfs -d /
else
sudo resize2fs /dev/nvme0n1p1
fi
fi