-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathec2.tf
More file actions
84 lines (74 loc) · 1.96 KB
/
Copy pathec2.tf
File metadata and controls
84 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//the basic initialization code
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
// the code for the provider
provider "aws" {
region = "ap-south-1"
access_key = "access-key"
secret_key = "secret-key"
# Configuration options
}
# RSA key of size 4096 bits
resource "tls_private_key" "rsa_1024" {
algorithm = "RSA"
rsa_bits = 1024
}
#keypair for the ec2 instance
resource "aws_key_pair" "key_pair" {
key_name = "deployer-key"
public_key = "${tls_private_key.rsa_1024.public_key_openssh}"
}
//saving resources
resource "local_file" "private_key" {
content = "${tls_private_key.rsa_1024.private_key_pem}"
filename = "private_key.pem"
}
//creating a instance with t2.micro
resource "aws_instance" "web" {
ami = "ami-03f4878755434977f"
instance_type = "t2.micro"
count = 1
key_name = aws_key_pair.key_pair.key_name
user_data = file("jenkins.sh")
vpc_security_group_ids = ["${aws_security_group.allow_tls.id}"]
tags = {
Name = "jenkins"
}
}
//creating a instance with t2.medium
# resource "aws_instance" "db" {
# ami = "ami-03f4878755434977f"
# instance_type = "t2.medium"
# count = 1
# key_name = aws_key_pair.key_pair.key_name
# user_data = file("kubernetes.sh")
# vpc_security_group_ids = ["${aws_security_group.allow_tls.id}"]
# tags = {
# Name = "kubernetes"
# }
# }
#security
resource "aws_security_group" "allow_tls" {
name = "allow_tls"
description = "Allow TLS inbound traffic"
ingress {
description = "TLS from VPC"
from_port = 0
to_port = 65535
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"]
}
}