-
Notifications
You must be signed in to change notification settings - Fork 1
/
awsconfig.tf
228 lines (179 loc) · 5 KB
/
awsconfig.tf
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
provider "aws" {
profile = "satyam"
region = "ap-south-1"
}
resource "aws_security_group" "my_security"{
name = "my_security"
description = "Configured for Instance AWS"
vpc_id = "vpc-d3b3aebb"
ingress {
description = "443 Port"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["172.31.0.0/16"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
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"]
}
tags = {
Name = "Allow port 80 and 22"
}
}
resource "aws_instance" "sattu_instance" {
ami = "ami-0447a12f28fddb066"
instance_type = "t2.micro"
key_name = "keybysatyam2"
security_groups = ["${aws_security_group.my_security.name}"]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("C:/Users/shailesh/Desktop/AWS/keybysatyam2.pem")
host = aws_instance.sattu_instance.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo yum install httpd php git -y",
"sudo systemctl restart httpd",
"sudo systemctl enable httpd",
]
}
tags = {
Name = "Satyam-Amazon-Linux2-AMI"
}
}
resource "aws_ebs_volume" "ebs1" {
availability_zone = aws_instance.sattu_instance.availability_zone
size = 1
tags = {
Name = "EBS Volume Size 1 GiB"
}
}
resource "aws_volume_attachment" "volume_one" {
device_name = "/dev/sdh"
volume_id = "${aws_ebs_volume.ebs1.id}"
instance_id = "${aws_instance.sattu_instance.id}"
force_detach = true
}
output "os_ip" {
value = aws_instance.sattu_instance.public_ip
}
resource "null_resource" "null_rsrc" {
depends_on = [
aws_volume_attachment.volume_one,
]
connection {
type = "ssh"
user = "ec2-user"
private_key = file("C:/Users/shailesh/Desktop/AWS/keybysatyam2.pem")
host = aws_instance.sattu_instance.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo mkfs.ext4 /dev/xvdh",
"sudo mount /dev/xvdh /var/www/html",
"sudo rm -rf /var/www/html/*",
"sudo git clone https://github.com/satyam9090/TestingAWSgitCloneHTML.git /var/www/html",
]
}
}
resource "null_resource" "nulllocal2" {
provisioner "local-exec" {
command = "echo ${aws_instance.sattu_instance.public_ip} > publicip.txt"
}
}
resource "aws_s3_bucket" "s3bucketsattu" {
depends_on=[
null_resource.null_rsrc,
]
bucket="s3bucketsattu"
acl ="public-read"
provisioner "local-exec" {
command = "git clone https://github.com/satyam9090/BlackpinkImage.git Desktop/Image/Sattu9090"
}
}
resource "aws_s3_bucket_object" "vg-object" {
bucket = aws_s3_bucket.s3bucketsattu.bucket
key = "blackpink.jpg"
acl="public-read"
source = "Desktop/Image/Sattu9090/blackpink.jpg"
}
resource "aws_cloudfront_distribution" "awscloudfrontsattu" {
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "${aws_s3_bucket.s3bucketsattu.bucket}"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "allow-all"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
}
is_ipv6_enabled = true
origin {
domain_name = "${aws_s3_bucket.s3bucketsattu.bucket_regional_domain_name}"
origin_id = "${aws_s3_bucket.s3bucketsattu.bucket}"
custom_origin_config {
http_port = 80
https_port = 80
origin_protocol_policy = "match-viewer"
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
}
}
default_root_object = "index.html"
enabled = true
custom_error_response {
error_caching_min_ttl = 3000
error_code = 404
response_code = 200
response_page_path = "/index.html"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
tags = {
Environment = "production"
}
viewer_certificate {
cloudfront_default_certificate = true
}
connection {
type="ssh"
user ="ec2-user"
port=22
private_key=file("C:/Users/shailesh/Desktop/AWS/keybysatyam2.pem")
host=aws_instance.sattu_instance.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo -i << EOF",
"echo \"<img src='http://${self.domain_name}/${aws_s3_bucket_object.vg-object.key}' width='500' height='500'>\" >> /var/www/html/index.html",
"EOF",
]
}
}
output "cloudfront_ip_addr" {
value = aws_cloudfront_distribution.awscloudfrontsattu.domain_name
}