mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-26 01:15:50 +00:00
terraform added
This commit is contained in:
parent
471030e976
commit
ddc636a943
8 changed files with 289 additions and 0 deletions
20
spring-petclinic.service
Normal file
20
spring-petclinic.service
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
[Unit]
|
||||||
|
Description=springpetclinic java application
|
||||||
|
[Service]
|
||||||
|
User=ansible
|
||||||
|
# The configuration file application.properties should be here:
|
||||||
|
|
||||||
|
#change this to your workspace
|
||||||
|
WorkingDirectory=/home/ansible/
|
||||||
|
|
||||||
|
#path to executable.
|
||||||
|
#executable is a bash script which calls jar file
|
||||||
|
ExecStart=/usr/bin/java -jar spring-petclinic-2.7.3.jar
|
||||||
|
|
||||||
|
SuccessExitStatus=143
|
||||||
|
TimeoutStopSec=10
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
10
terraforminfra/data.tf
Normal file
10
terraforminfra/data.tf
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
data "aws_key_pair" "mykey" {
|
||||||
|
filter {
|
||||||
|
name = "key-name"
|
||||||
|
values = ["newkey"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
12
terraforminfra/dev.tfvars
Normal file
12
terraforminfra/dev.tfvars
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
myregion = "ap-south-1"
|
||||||
|
my_vpc = "192.168.0.0/16"
|
||||||
|
myvpctag = "myvpctag"
|
||||||
|
mypubsubnet = "192.168.0.0/24"
|
||||||
|
publicsubnettag = "publicsubnettag"
|
||||||
|
myintgwtag = "myintgwtag"
|
||||||
|
mycidr_block = "0.0.0.0/0"
|
||||||
|
instance_type = "t2.large"
|
||||||
|
ami_id = "ami-0f8ca728008ff5af4"
|
||||||
|
|
||||||
|
|
||||||
|
|
91
terraforminfra/instance.tf
Normal file
91
terraforminfra/instance.tf
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
resource "aws_instance" "jenkin" {
|
||||||
|
ami = var.ami_id
|
||||||
|
associate_public_ip_address = true
|
||||||
|
instance_type = var.instance_type
|
||||||
|
key_name = data.aws_key_pair.mykey.key_name
|
||||||
|
vpc_security_group_ids = [aws_security_group.myrsgroup.id]
|
||||||
|
subnet_id = aws_subnet.my_subnet.id
|
||||||
|
availability_zone = "ap-south-1a"
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
"Name" = "jenkins"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resource "null_resource" "jenkinnull" {
|
||||||
|
triggers = {
|
||||||
|
cluster_instance_ids = 1.2
|
||||||
|
}
|
||||||
|
connection {
|
||||||
|
type = "ssh"
|
||||||
|
user = "ubuntu"
|
||||||
|
host = aws_instance.jenkin.public_ip
|
||||||
|
private_key = file("~/.ssh/id_rsa")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
provisioner "remote-exec" {
|
||||||
|
|
||||||
|
inline = [
|
||||||
|
"sudo apt-get update",
|
||||||
|
"sudo apt-get install openjdk-11-jdk -y",
|
||||||
|
"sudo apt-get install git -y",
|
||||||
|
"sudo apt-get install wget -y",
|
||||||
|
"sudo apt install curl -y",
|
||||||
|
"sleep 2m",
|
||||||
|
"curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null",
|
||||||
|
"echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null",
|
||||||
|
"sudo apt install jenkins -y",
|
||||||
|
"sudo apt-get update",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
resource "aws_instance" "node1" {
|
||||||
|
ami = var.ami_id
|
||||||
|
associate_public_ip_address = true
|
||||||
|
instance_type = var.instance_type
|
||||||
|
key_name = data.aws_key_pair.mykey.key_name
|
||||||
|
vpc_security_group_ids = [aws_security_group.myrsgroup.id]
|
||||||
|
subnet_id = aws_subnet.my_subnet.id
|
||||||
|
availability_zone = "ap-south-1a"
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
"Name" = "node1"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
resource "null_resource" "node1null" {
|
||||||
|
triggers = {
|
||||||
|
cluster_instance_ids = 1.2
|
||||||
|
}
|
||||||
|
connection {
|
||||||
|
type = "ssh"
|
||||||
|
user = "ubuntu"
|
||||||
|
host = aws_instance.node1.public_ip
|
||||||
|
private_key = file("~/.ssh/id_rsa")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
provisioner "remote-exec" {
|
||||||
|
|
||||||
|
inline = [
|
||||||
|
"sudo apt-get update",
|
||||||
|
"sudo apt-get install openjdk-11-jdk -y",
|
||||||
|
"sudo apt-get install git -y",
|
||||||
|
"sudo apt-get install wget -y",
|
||||||
|
"sudo apt install curl -y",
|
||||||
|
"sudo apt install maven -y",
|
||||||
|
"sudo apt install software-properties-common -y",
|
||||||
|
"sudo add-apt-repository --yes --update ppa:ansible/ansible",
|
||||||
|
"sudo apt install ansible -y",
|
||||||
|
"sudo apt-get update",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
58
terraforminfra/network.tf
Normal file
58
terraforminfra/network.tf
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
resource "aws_vpc" "myvpc" {
|
||||||
|
cidr_block = var.my_vpc
|
||||||
|
instance_tenancy = "default"
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = var.myvpctag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_subnet" "my_subnet" {
|
||||||
|
vpc_id = aws_vpc.myvpc.id
|
||||||
|
cidr_block = var.mypubsubnet
|
||||||
|
availability_zone = "ap-south-1a"
|
||||||
|
tags = {
|
||||||
|
Name = var.publicsubnettag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_internet_gateway" "myintgw" {
|
||||||
|
vpc_id = aws_vpc.myvpc.id
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = var.myintgwtag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route_table" "mypubroute" {
|
||||||
|
vpc_id = aws_vpc.myvpc.id
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = var.mycidr_block
|
||||||
|
gateway_id = aws_internet_gateway.myintgw.id
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "pubroutetag"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route_table_association" "pubassociation" {
|
||||||
|
subnet_id = aws_subnet.my_subnet.id
|
||||||
|
route_table_id = aws_route_table.mypubroute.id
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_network_interface" "mynetworkinterface" {
|
||||||
|
subnet_id = aws_subnet.my_subnet.id
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "public_network_interface"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
13
terraforminfra/provider.tf
Normal file
13
terraforminfra/provider.tf
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
aws = {
|
||||||
|
source = "hashicorp/aws"
|
||||||
|
version = "~> 4.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Configure the AWS Provider
|
||||||
|
provider "aws" {
|
||||||
|
region = var.myregion
|
||||||
|
}
|
42
terraforminfra/securitygroup.tf
Normal file
42
terraforminfra/securitygroup.tf
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
resource "aws_security_group" "myrsgroup" {
|
||||||
|
name = "myresourcegroup"
|
||||||
|
vpc_id = aws_vpc.myvpc.id
|
||||||
|
|
||||||
|
ingress {
|
||||||
|
description = "myVPC"
|
||||||
|
from_port = 80
|
||||||
|
to_port = 80
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
|
||||||
|
}
|
||||||
|
ingress {
|
||||||
|
description = "myVPC"
|
||||||
|
from_port = 8080
|
||||||
|
to_port = 8080
|
||||||
|
protocol = "tcp"
|
||||||
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
|
||||||
|
}
|
||||||
|
ingress {
|
||||||
|
description = "myVPC"
|
||||||
|
from_port = 22
|
||||||
|
to_port = 22
|
||||||
|
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"]
|
||||||
|
ipv6_cidr_blocks = ["::/0"]
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "myresourcegrouptag"
|
||||||
|
}
|
||||||
|
}
|
43
terraforminfra/variable.tf
Normal file
43
terraforminfra/variable.tf
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
variable "myregion" {
|
||||||
|
type = string
|
||||||
|
default = "ap-south-1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "my_vpc" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "myvpctag" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mypubsubnet" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "publicsubnettag" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "myintgwtag" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mycidr_block" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_version" {
|
||||||
|
type = string
|
||||||
|
default = "1.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
variable "instance_type" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ami_id" {
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue