@@ -50,68 +50,67 @@ variable "openvpn_ami_owner_id" {
50
50
}
51
51
52
52
provider "aws" {
53
- region = " ${ var . region } "
53
+ region = var. region
54
54
}
55
55
56
-
57
56
module "vpc" {
58
57
source = " ../../../modules/vpc"
59
58
name_prefix = " ${ var . name } -vpc"
60
- region = " ${ var . region } "
61
- cidr = " ${ var . vpc_cidr } "
59
+ region = var. region
60
+ cidr = var. vpc_cidr
62
61
}
63
62
64
63
module "vpc-public-subnets" {
65
64
source = " ../../../modules/subnets"
66
- azs = [" ${ var . aws_availability_zones } " ]
67
- vpc_id = " ${ module . vpc . vpc_id } "
65
+ azs = [var . aws_availability_zones ]
66
+ vpc_id = module. vpc . vpc_id
68
67
name_prefix = " ${ var . name } -vpc-public"
69
- cidr_blocks = " ${ var . vpc_public_subnet_cidrs } "
70
- extra_tags = " ${ var . extra_tags } "
68
+ cidr_blocks = var. vpc_public_subnet_cidrs
69
+ extra_tags = var. extra_tags
71
70
}
72
71
73
72
module "vpc-sg" {
74
73
source = " ../../../modules/security-group-base"
75
74
description = " Test project security group"
76
75
name = " ${ var . name } -vpc-sg"
77
- vpc_id = " ${ module . vpc . vpc_id } "
76
+ vpc_id = module. vpc . vpc_id
78
77
}
79
78
80
79
module "vpc-open-ssh" {
81
80
source = " ../../../modules/ssh-sg"
82
81
83
82
# this is actually used as a name-prefix
84
- security_group_id = " ${ module . vpc-sg . id } "
83
+ security_group_id = module. vpc-sg . id
85
84
}
86
85
87
86
module "vpc-open-egress" {
88
87
source = " ../../../modules/open-egress-sg"
89
88
90
89
# this is actually used as a name-prefix
91
- security_group_id = " ${ module . vpc-sg . id } "
90
+ security_group_id = module. vpc-sg . id
92
91
}
93
92
94
93
module "openvpn-sg" {
95
94
source = " ../../../modules/security-group-base"
96
95
description = " Openvpn security group"
97
96
name = " ${ var . name } -openvpn-sg"
98
- vpc_id = " ${ module . vpc . vpc_id } "
97
+ vpc_id = module. vpc . vpc_id
99
98
}
100
99
101
100
module "https-rule" {
102
101
source = " ../../../modules/single-port-sg"
103
102
port = 443
104
103
description = " allow ingress, HTTPS (443)"
105
104
cidr_blocks = [" 0.0.0.0/0" ]
106
- security_group_id = " ${ module . openvpn-sg . id } "
105
+ security_group_id = module. openvpn-sg . id
107
106
}
108
107
109
108
module "openvpn-web-rule" {
110
109
source = " ../../../modules/single-port-sg"
111
110
port = 943
112
111
description = " allow ingress, HTTP (943) openvpn server"
113
112
cidr_blocks = [" 0.0.0.0/0" ]
114
- security_group_id = " ${ module . openvpn-sg . id } "
113
+ security_group_id = module. openvpn-sg . id
115
114
}
116
115
117
116
module "openvpn-rule" {
@@ -120,19 +119,20 @@ module "openvpn-rule" {
120
119
protocol = " udp"
121
120
description = " allow ingress, HTTP (943) openvpn server"
122
121
cidr_blocks = [" 0.0.0.0/0" ]
123
- security_group_id = " ${ module . openvpn-sg . id } "
122
+ security_group_id = module. openvpn-sg . id
124
123
}
125
124
126
125
module "openvpn-egress" {
127
- source = " ../../../modules/open-egress-sg"
128
- security_group_id = " ${ module . openvpn-sg . id } "
126
+ source = " ../../../modules/open-egress-sg"
127
+ security_group_id = module. openvpn-sg . id
129
128
}
129
+
130
130
module "vpc-public-gateway" {
131
131
source = " ../../../modules/route-public"
132
- vpc_id = " ${ module . vpc . vpc_id } "
132
+ vpc_id = module. vpc . vpc_id
133
133
name_prefix = " ${ var . name } -vpc-public"
134
- extra_tags = " ${ var . extra_tags } "
135
- public_subnet_ids = [" ${ concat (module. vpc-public-subnets . ids )} " ]
134
+ extra_tags = var. extra_tags
135
+ public_subnet_ids = [concat (module. vpc-public-subnets . ids )]
136
136
}
137
137
138
138
# EC2 Instances setup
@@ -154,52 +154,53 @@ data "aws_ami" "openvpn-ami" {
154
154
values = [" hvm" ]
155
155
}
156
156
157
- owners = [" ${ var . openvpn_ami_owner_id } " ]
157
+ owners = [var . openvpn_ami_owner_id ]
158
158
}
159
159
160
160
resource "aws_key_pair" "main" {
161
- key_name = " ${ var . name } "
162
- public_key = " ${ file (var. ssh_pubkey )} "
161
+ key_name = var. name
162
+ public_key = file (var. ssh_pubkey )
163
163
}
164
164
165
165
data "template_file" "openvpn-setup" {
166
- template = " ${ file (" ${ path . module } /init-script.sh" )} "
166
+ template = file (" ${ path . module } /init-script.sh" )
167
167
}
168
168
169
169
resource "aws_instance" "vpn-machine" {
170
170
# setup openvpn ami
171
- ami = " ${ data . aws_ami . openvpn-ami . id } "
171
+ ami = data. aws_ami . openvpn-ami . id
172
172
count = " 1"
173
- key_name = " ${ aws_key_pair . main . key_name } "
173
+ key_name = aws_key_pair. main . key_name
174
174
instance_type = " t2.nano"
175
- availability_zone = " ${ var . aws_availability_zones } "
175
+ availability_zone = var. aws_availability_zones
176
176
177
177
root_block_device {
178
178
volume_type = " gp2"
179
179
volume_size = " 8"
180
180
}
181
181
182
182
associate_public_ip_address = " true"
183
- vpc_security_group_ids = [" ${ module . vpc-sg . id } " , " ${ module . openvpn-sg . id } " ]
184
- subnet_id = " ${ element (module. vpc-public-subnets . ids , count. index )} "
183
+ vpc_security_group_ids = [module . vpc-sg . id , module . openvpn-sg . id ]
184
+ subnet_id = element (module. vpc-public-subnets . ids , count. index )
185
185
186
- tags {
186
+ tags = {
187
187
Name = " ${ var . name } -vpn-server-${ count . index } "
188
188
}
189
189
190
- user_data = " ${ data . template_file . openvpn-setup . rendered } "
190
+ user_data = data. template_file . openvpn-setup . rendered
191
191
192
192
provisioner "remote-exec" {
193
193
connection {
194
+ host = coalesce (self. public_ip , self. private_ip )
194
195
type = " ssh"
195
196
user = " openvpnas"
196
- private_key = " ${ file (var. ssh_key )} "
197
+ private_key = file (var. ssh_key )
197
198
}
198
199
}
199
-
200
200
}
201
201
202
202
output "openvpn-public-eip" {
203
- value = " ${ aws_instance . vpn-machine . public_ip } "
203
+ value = aws_instance. vpn-machine [ 0 ] . public_ip
204
204
description = " OpenVPN Public IP"
205
205
}
206
+
0 commit comments