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
70 changes: 70 additions & 0 deletions EIP_association/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
region = "us-east-1" # Change the region as needed
}

# Data source to get the default VPC
data "aws_vpc" "default" {
default = true
}

# Data source to get the default subnet in the default VPC
data "aws_subnet" "default" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}

filter {
name = "default-for-az"
values = ["true"]
}

availability_zone = "us-east-1a" # Change the availability zone as needed
}

# Data source to get the default security group in the default VPC
data "aws_security_group" "default" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}

filter {
name = "group-name"
values = ["default"]
}
}

# Create an EC2 instance in the default VPC and subnet
resource "aws_instance" "web" {
ami = "ami-0ba9883b710b05ac6" # Replace with a valid AMI ID for your region
instance_type = "t2.micro"
subnet_id = data.aws_subnet.default.id
vpc_security_group_ids = [data.aws_security_group.default.id]

tags = {
Name = "WebServer"
}
}

# Allocate an Elastic IP
resource "aws_eip" "web" {
vpc = true
}

# Associate the Elastic IP with the instance
resource "aws_eip_association" "web" {
instance_id = aws_instance.web.id
allocation_id = aws_eip.web.id
}
18 changes: 18 additions & 0 deletions ElasticIP/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Initialize Terraform
echo "Initializing Terraform..."
terraform init

# Plan the Terraform deployment
echo "Planning Terraform deployment..."
terraform plan

# Apply the Terraform configuration with auto-accept
echo "Applying Terraform configuration..."
terraform apply -auto-approve

echo "Terraform deployment complete."
24 changes: 24 additions & 0 deletions ElasticIP/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
region = "us-east-1" # Change the region as needed
}

# Allocate an Elastic IP
resource "aws_eip" "example" {
# No additional configuration is needed for a basic Elastic IP
}

# Optionally, you can output the allocated Elastic IP address
output "elastic_ip" {
value = aws_eip.example.public_ip
}
1 change: 1 addition & 0 deletions Security Group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# terraformcode
11 changes: 11 additions & 0 deletions Security Group/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.region}"
}

module "s3" {
source = "<path-to-S3-folder>"
#bucket name should be unique
bucket_name = "<Bucket-name>"
}
72 changes: 72 additions & 0 deletions rds/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

provider "aws" {
region = "us-east-1" # Change the region as needed
}

# Create a VPC
resource "aws_vpc" "main" {
cidr_block = "192.0.0.0/16"
}

# Create the first subnet
resource "aws_subnet" "subnet_a" {
vpc_id = aws_vpc.main.id
cidr_block = "192.0.1.0/24"
availability_zone = "us-east-1a" # Change the availability zone as needed
}

# Create the second subnet
resource "aws_subnet" "subnet_b" {
vpc_id = aws_vpc.main.id
cidr_block = "192.0.2.0/24"
availability_zone = "us-east-1b" # Change the availability zone as needed
}

# Create a security group for the RDS instance
resource "aws_security_group" "rds_sg" {
vpc_id = aws_vpc.main.id

ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

# Create a DB subnet group
resource "aws_db_subnet_group" "main" {
name = "main"
subnet_ids = [aws_subnet.subnet_a.id, aws_subnet.subnet_b.id]
}

# Create an RDS instance
resource "aws_db_instance" "default" {
allocated_storage = 20
engine = "mysql"
engine_version = "8.0"
instance_class = "db.t3.micro"
name = "exampledb"
username = "admin"
password = "password" # Change the password as needed
db_subnet_group_name = aws_db_subnet_group.main.name
vpc_security_group_ids = [aws_security_group.rds_sg.id]
skip_final_snapshot = true
}
61 changes: 61 additions & 0 deletions rout53/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

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

# Create a Route 53 hosted zone
resource "aws_route53_zone" "main" {
name = "example.com"
}

resource "aws_route53_zone" "dev" {
name = "dev.example.com"

tags = {
Environment = "dev"
}
}
resource "aws_route53_record" "dev-ns" {
zone_id = aws_route53_zone.main.zone_id
name = "dev.example.com"
type = "NS"
ttl = "30"
records = aws_route53_zone.dev.name_servers
}


# Create an A record in the hosted zone
resource "aws_route53_record" "www" {
zone_id = aws_route53_zone.primary.id
name = "www.example.com"
type = "A"
ttl = 300
#records = [aws_eip.lb.public_ip]

records = [
"192.0.2.1"
]
}

# Create a CNAME record in the hosted zone
resource "aws_route53_record" "cname_record" {
zone_id = aws_route53_zone.primary.id
name = "blog.example.com"
type = "CNAME"
ttl = 300

records = [
"www.ipexample.com"
]
}
68 changes: 34 additions & 34 deletions vpc/main.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}

required_version = ">= 0.14.9"
}

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

module "vpc" {
source = "terraform-aws-modules/vpc/aws"

name = "my-vpc"
cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

enable_nat_gateway = true
enable_vpn_gateway = true

tags = {
Terraform = "true"
Environment = "dev"
}
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.46.0"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default"
region = "us-west-2"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
enable_vpn_gateway = true
tags = {
Terraform = "true"
Environment = "dev"
}
}