Compare commits
10 Commits
3350953946
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
ad8384404f
|
|||
|
7a8b8222fc
|
|||
|
d54ecd2323
|
|||
|
b73088c14d
|
|||
|
06a2480a09
|
|||
|
eb2a5fac14
|
|||
|
b5c5e36e56
|
|||
|
0e2f9e3b57
|
|||
|
6df047c387
|
|||
|
7310c7e1bc
|
@@ -0,0 +1,8 @@
|
|||||||
|
aws-cli-config.txt
|
||||||
|
*terraform.tfstate
|
||||||
|
*terraform.tfstate.backup
|
||||||
|
*terraform.tfvars
|
||||||
|
|
||||||
|
################
|
||||||
|
|
||||||
|
**/.terraform*
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
image: nginx:stable-perl
|
||||||
|
container_name: nginx
|
||||||
|
restart: no
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
environment:
|
||||||
|
- NGINX_PORT=80
|
||||||
|
networks:
|
||||||
|
- nginx
|
||||||
|
|
||||||
|
networks:
|
||||||
|
nginx:
|
||||||
|
driver: bridge
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
services:
|
||||||
|
jenkins:
|
||||||
|
image: jenkins/jenkins:lts-jdk17
|
||||||
|
container_name: jenkins
|
||||||
|
restart: no
|
||||||
|
user: "1000:1000"
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges=true
|
||||||
|
volumes:
|
||||||
|
- "jenkins_home:/var/jenkins_home"
|
||||||
|
ports:
|
||||||
|
- 8080:8080
|
||||||
|
- 50000:50000
|
||||||
|
networks:
|
||||||
|
- jenkins-ntwk
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
jenkins_home:
|
||||||
|
external: true
|
||||||
|
|
||||||
|
networks:
|
||||||
|
jenkins-ntwk:
|
||||||
|
driver: bridge
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
provider "aws" {
|
||||||
|
region = "ap-south-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# VPC
|
||||||
|
resource "aws_vpc" "TestVPC" { # Create a VPC
|
||||||
|
cidr_block = "172.16.0.0/16" # Specify CIDR block (IP range)
|
||||||
|
enable_dns_support = true # DNS support
|
||||||
|
enable_dns_hostnames = true # Hostname support
|
||||||
|
tags = {
|
||||||
|
Name = "TestVPC" # Name for VPC (on AWS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Subnet -> Associated w/ TestVPC
|
||||||
|
resource "aws_subnet" "TestSubnetOne" { # Create subnet
|
||||||
|
vpc_id = aws_vpc.TestVPC.id # Specify VPC under which subnet should be created
|
||||||
|
cidr_block = "172.16.1.0/24" # Specify segment of IP range (from VPC) for this subnet
|
||||||
|
availability_zone = "ap-south-1a" # Set availability zone
|
||||||
|
tags = {
|
||||||
|
Name = "TestSubnet1" # Name for subnet (on AWS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Internet gateway
|
||||||
|
# Route table
|
||||||
|
# |_ Route
|
||||||
|
# |_ Table association
|
||||||
|
|
||||||
|
# EC2 under TestVPC in TestSubnet1 IP
|
||||||
|
resource "aws_instance" "name" {
|
||||||
|
ami = "ami-0861f4e788f5069dd"
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
key_name = "kshitij-personal-ed25519"
|
||||||
|
subnet_id = aws_subnet.TestSubnetOne.id
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "EC2-TestSubnet1"
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
-15
@@ -5,31 +5,50 @@ provider "aws" {
|
|||||||
# EC2 instance
|
# EC2 instance
|
||||||
resource "aws_instance" "ec2_t2-micro" {
|
resource "aws_instance" "ec2_t2-micro" {
|
||||||
ami = "ami-0861f4e788f5069dd" # Amazon Linux
|
ami = "ami-0861f4e788f5069dd" # Amazon Linux
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro" # Instance type
|
||||||
key_name = "kshitij-personal-ed25519"
|
key_name = "kshitij-personal-ed25519" # SSH keys
|
||||||
subnet_id = "subnet-0f2515644bbe8e603"
|
subnet_id = "subnet-0f2515644bbe8e603" # VPC -> Subnet ID
|
||||||
associate_public_ip_address = true
|
associate_public_ip_address = true # Public IP for SSH
|
||||||
vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id]
|
vpc_security_group_ids = [aws_security_group.ec2_ssh_security.id] # VPC security group
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
Name = "Test-EC2"
|
Name = "Test-EC2" # Instance name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Security group (firewall) for allowing incoming SSH connections
|
# Security group (firewall) for allowing incoming SSH connections
|
||||||
resource "aws_security_group" "ec2_ssh_security" {
|
resource "aws_security_group" "ec2_ssh_security" {
|
||||||
name = "allow_ssh"
|
name = "allow_ssh" # Firewall rule name
|
||||||
|
|
||||||
ingress {
|
ingress {
|
||||||
from_port = 22
|
# Ingress rules (incoming)
|
||||||
to_port = 22
|
from_port = 22 # Starting port range
|
||||||
protocol = "tcp"
|
to_port = 22 # End port range
|
||||||
cidr_blocks = ["${var.ssh_ingress}"]
|
protocol = "tcp" # Allowed protocol
|
||||||
|
cidr_blocks = ["${var.ssh_ingress}"] # Allowed IP ranges
|
||||||
}
|
}
|
||||||
egress {
|
egress {
|
||||||
from_port = 0
|
from_port = 0 # Starting port range; 0 implies all ports
|
||||||
to_port = 0
|
to_port = 0 # End port range; 0 implies all ports
|
||||||
protocol = -1
|
protocol = -1 # Allowed protocol; -1 implies all protocols (in HCL)
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
cidr_blocks = ["0.0.0.0/0"] # Allowed IP ranges
|
||||||
}
|
}
|
||||||
|
# For each protocol, new block; eg. egress { from... to... protocol = "icmp" cidr...}
|
||||||
|
}
|
||||||
|
|
||||||
|
# DynamoDB Table
|
||||||
|
resource "aws_dynamodb_table" "dynamo-test" {
|
||||||
|
name = "testTable" # Table name
|
||||||
|
billing_mode = "PROVISIONED" # Specify billing type; PROVISIONED (provisioned billing mode) / PAY_PER_REQUEST (on-demand billing mode)
|
||||||
|
read_capacity = 1 # no. of reads per sec.
|
||||||
|
write_capacity = 1 # no. of writes per sec.
|
||||||
|
|
||||||
|
# Attribute
|
||||||
|
attribute {
|
||||||
|
name = "username" # Col. name
|
||||||
|
type = "S" # Col. type;
|
||||||
|
# S -> String, N -> Number, B -> Binary, BOOL -> Boolean, List -> L (ordered collection of values), Map ->M (key-value pairs), Null -> NULL
|
||||||
|
}
|
||||||
|
|
||||||
|
hash_key = "username" # Primary key
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
provider "aws" {
|
||||||
|
region = "ap-south-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "terra-ec2" {
|
||||||
|
ami = "ami-0861f4e788f5069dd"
|
||||||
|
instance_type = "t2.micro"
|
||||||
|
key_name = "kshitij-personal-ed25519"
|
||||||
|
subnet_id = "subnet-0f2515644bbe8e603"
|
||||||
|
associate_public_ip_address = true
|
||||||
|
vpc_security_group_ids = [aws_security_group.allow_ssh_terra-ec2.id]
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
name = "terra-ec2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_security_group" "allow_ssh_terra-ec2" {
|
||||||
|
name = "allow_ssh_terra-ec2"
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
from_port = 22
|
||||||
|
to_port = 22
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["${var.internal_ip}", "${var.personal_ip}"]
|
||||||
|
}
|
||||||
|
egress {
|
||||||
|
from_port = 0
|
||||||
|
to_port = 0
|
||||||
|
protocol = -1
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
variable "internal_ip" {
|
||||||
|
description = "Internal IP allowing SSH access to terra-ec2"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "personal_ip" {
|
||||||
|
description = "Personal IP allowing SSH access to terra-ec2"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import boto3
|
||||||
|
|
||||||
|
session = boto3.Session (region_name = "ap-south-1")
|
||||||
|
|
||||||
|
ec2_instances = session.resource('ec2').instances.all()
|
||||||
|
|
||||||
|
for instance in ec2_instances:
|
||||||
|
print(f"ID: {instance.id}, State: {instance.state['Name']}, Type: {instance.instance_type}, Public IP: {instance.public_ip_address}")
|
||||||
Reference in New Issue
Block a user