Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 5d49e88

Browse files
Magicloudketzacoatl
authored andcommitted
0.12 upgrading on examples vpc-scenario-3/remote-environment
The upgrading is done via 'terraform 0.12upgrade .` and reviewed by human.
1 parent b8adb88 commit 5d49e88

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

examples/vpc-scenario-3/remote-environment/main.tf

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,68 +50,67 @@ variable "openvpn_ami_owner_id" {
5050
}
5151

5252
provider "aws" {
53-
region = "${var.region}"
53+
region = var.region
5454
}
5555

56-
5756
module "vpc" {
5857
source = "../../../modules/vpc"
5958
name_prefix = "${var.name}-vpc"
60-
region = "${var.region}"
61-
cidr = "${var.vpc_cidr}"
59+
region = var.region
60+
cidr = var.vpc_cidr
6261
}
6362

6463
module "vpc-public-subnets" {
6564
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
6867
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
7170
}
7271

7372
module "vpc-sg" {
7473
source = "../../../modules/security-group-base"
7574
description = "Test project security group"
7675
name = "${var.name}-vpc-sg"
77-
vpc_id = "${module.vpc.vpc_id}"
76+
vpc_id = module.vpc.vpc_id
7877
}
7978

8079
module "vpc-open-ssh" {
8180
source = "../../../modules/ssh-sg"
8281

8382
# this is actually used as a name-prefix
84-
security_group_id = "${module.vpc-sg.id}"
83+
security_group_id = module.vpc-sg.id
8584
}
8685

8786
module "vpc-open-egress" {
8887
source = "../../../modules/open-egress-sg"
8988

9089
# this is actually used as a name-prefix
91-
security_group_id = "${module.vpc-sg.id}"
90+
security_group_id = module.vpc-sg.id
9291
}
9392

9493
module "openvpn-sg" {
9594
source = "../../../modules/security-group-base"
9695
description = "Openvpn security group"
9796
name = "${var.name}-openvpn-sg"
98-
vpc_id = "${module.vpc.vpc_id}"
97+
vpc_id = module.vpc.vpc_id
9998
}
10099

101100
module "https-rule" {
102101
source = "../../../modules/single-port-sg"
103102
port = 443
104103
description = "allow ingress, HTTPS (443)"
105104
cidr_blocks = ["0.0.0.0/0"]
106-
security_group_id = "${module.openvpn-sg.id}"
105+
security_group_id = module.openvpn-sg.id
107106
}
108107

109108
module "openvpn-web-rule" {
110109
source = "../../../modules/single-port-sg"
111110
port = 943
112111
description = "allow ingress, HTTP (943) openvpn server"
113112
cidr_blocks = ["0.0.0.0/0"]
114-
security_group_id = "${module.openvpn-sg.id}"
113+
security_group_id = module.openvpn-sg.id
115114
}
116115

117116
module "openvpn-rule" {
@@ -120,19 +119,20 @@ module "openvpn-rule" {
120119
protocol = "udp"
121120
description = "allow ingress, HTTP (943) openvpn server"
122121
cidr_blocks = ["0.0.0.0/0"]
123-
security_group_id = "${module.openvpn-sg.id}"
122+
security_group_id = module.openvpn-sg.id
124123
}
125124

126125
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
129128
}
129+
130130
module "vpc-public-gateway" {
131131
source = "../../../modules/route-public"
132-
vpc_id = "${module.vpc.vpc_id}"
132+
vpc_id = module.vpc.vpc_id
133133
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)]
136136
}
137137

138138
# EC2 Instances setup
@@ -154,52 +154,53 @@ data "aws_ami" "openvpn-ami" {
154154
values = ["hvm"]
155155
}
156156

157-
owners = ["${var.openvpn_ami_owner_id}"]
157+
owners = [var.openvpn_ami_owner_id]
158158
}
159159

160160
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)
163163
}
164164

165165
data "template_file" "openvpn-setup" {
166-
template = "${file("${path.module}/init-script.sh")}"
166+
template = file("${path.module}/init-script.sh")
167167
}
168168

169169
resource "aws_instance" "vpn-machine" {
170170
# setup openvpn ami
171-
ami = "${data.aws_ami.openvpn-ami.id}"
171+
ami = data.aws_ami.openvpn-ami.id
172172
count = "1"
173-
key_name = "${aws_key_pair.main.key_name}"
173+
key_name = aws_key_pair.main.key_name
174174
instance_type = "t2.nano"
175-
availability_zone = "${var.aws_availability_zones}"
175+
availability_zone = var.aws_availability_zones
176176

177177
root_block_device {
178178
volume_type = "gp2"
179179
volume_size = "8"
180180
}
181181

182182
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)
185185

186-
tags {
186+
tags = {
187187
Name = "${var.name}-vpn-server-${count.index}"
188188
}
189189

190-
user_data = "${data.template_file.openvpn-setup.rendered}"
190+
user_data = data.template_file.openvpn-setup.rendered
191191

192192
provisioner "remote-exec" {
193193
connection {
194+
host = coalesce(self.public_ip, self.private_ip)
194195
type = "ssh"
195196
user = "openvpnas"
196-
private_key = "${file(var.ssh_key)}"
197+
private_key = file(var.ssh_key)
197198
}
198199
}
199-
200200
}
201201

202202
output "openvpn-public-eip" {
203-
value = "${aws_instance.vpn-machine.public_ip}"
203+
value = aws_instance.vpn-machine[0].public_ip
204204
description = "OpenVPN Public IP"
205205
}
206+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)