forked from jonghall/ibmcloud-terraform-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpn.tf
70 lines (63 loc) · 2.48 KB
/
vpn.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
#---------------------------------------------------------
# Create Subnets for VPNaaS instances
#---------------------------------------------------------
resource "ibm_is_subnet" "vpn-subnet-zone-1" {
name = "${var.vpc-name}-${var.zone1}-vpn"
vpc = ibm_is_vpc.vpc1.id
zone = var.zone1
ipv4_cidr_block = var.vpn-subnet-zone-1
network_acl = ibm_is_network_acl.vpn_acl.id
public_gateway = ibm_is_public_gateway.pubgw-zone1.id
resource_group = data.ibm_resource_group.group.id
provisioner "local-exec" {
command = "sleep 300"
when = destroy
}
}
resource "ibm_is_subnet" "vpn-subnet-zone-2" {
name = "${var.vpc-name}-${var.zone2}-vpn"
vpc = ibm_is_vpc.vpc1.id
zone = var.zone2
ipv4_cidr_block = var.vpn-subnet-zone-2
network_acl = ibm_is_network_acl.vpn_acl.id
public_gateway = ibm_is_public_gateway.pubgw-zone2.id
resource_group = data.ibm_resource_group.group.id
provisioner "local-exec" {
command = "sleep 300"
when = destroy
}
}
#---------------------------------------------------------
# create VPNGateway for Zone 1
#---------------------------------------------------------
resource "ibm_is_vpn_gateway" "VPNGateway1" {
name = "${var.vpc-name}-${var.zone1}-vpn"
resource_group = data.ibm_resource_group.group.id
subnet = ibm_is_subnet.vpn-subnet-zone-1.id
}
resource "ibm_is_vpn_gateway_connection" "VPNGatewayConnection1-zone1" {
name = "${var.vpc-name}-${var.zone1}-connection"
vpn_gateway = ibm_is_vpn_gateway.VPNGateway1.id
peer_address = var.onprem_vpn_ip_address
preshared_key = var.vpn-preshared-key
local_cidrs = [var.address-prefix-1]
peer_cidrs = [var.onprem_cidr]
admin_state_up = true
}
#---------------------------------------------------------
# Create VPNGateway for Zone2
#---------------------------------------------------------
resource "ibm_is_vpn_gateway" "VPNGateway2" {
name = "${var.vpc-name}-${var.zone2}-vpn"
resource_group = data.ibm_resource_group.group.id
subnet = ibm_is_subnet.vpn-subnet-zone-2.id
}
resource "ibm_is_vpn_gateway_connection" "VPNGatewayConnection1-zone2" {
name = "${var.vpc-name}-${var.zone1}-connection"
vpn_gateway = ibm_is_vpn_gateway.VPNGateway2.id
peer_address = var.onprem_vpn_ip_address
preshared_key = var.vpn-preshared-key
local_cidrs = [var.address-prefix-2]
peer_cidrs = [var.onprem_cidr]
admin_state_up = true
}