1
1
variable "ami" {
2
2
description = " Base machine image for running this server"
3
- default = " ami-bd8f33c5 "
3
+ default = " ami-e70db29f "
4
4
}
5
5
6
6
variable "num_webs" {
@@ -12,13 +12,8 @@ variable "identity" {
12
12
description = " A unique name for this server"
13
13
}
14
14
15
- resource "aws_key_pair" "training" {
16
- key_name = " ${ var . identity } -key"
17
- public_key = " ${ file (" ~/.ssh/id_rsa.pub" )} "
18
- }
19
-
20
- resource "aws_security_group" "instance" {
21
- name = " ${ var . identity } -terraform-example-instance"
15
+ resource "aws_security_group" "web" {
16
+ name = " ${ var . identity } -sg"
22
17
23
18
ingress {
24
19
from_port = 80
@@ -56,31 +51,13 @@ resource "aws_instance" "web" {
56
51
instance_type = " t2.medium"
57
52
count = " ${ var . num_webs } "
58
53
59
- vpc_security_group_ids = [" ${ aws_security_group . instance . id } " ]
60
-
61
- key_name = " ${ aws_key_pair . training . id } "
54
+ vpc_security_group_ids = [" ${ aws_security_group . web . id } " ]
62
55
63
56
tags {
64
57
" Name" = " ${ var . identity } web ${ count . index + 1 } /${ var . num_webs } "
65
58
" Identity" = " ${ var . identity } "
66
59
" Created-by" = " Terraform"
67
60
}
68
-
69
- connection {
70
- user = " ubuntu"
71
- private_key = " ${ file (" ~/.ssh/id_rsa" )} "
72
- }
73
-
74
- provisioner "file" {
75
- source = " assets"
76
- destination = " /tmp/"
77
- }
78
-
79
- provisioner "remote-exec" {
80
- inline = [
81
- " sudo sh /tmp/assets/setup-web.sh" ,
82
- ]
83
- }
84
61
}
85
62
86
63
output "public_ip" {
0 commit comments