-
Notifications
You must be signed in to change notification settings - Fork 44
/
main.tf
98 lines (85 loc) · 2.67 KB
/
main.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
data "ibm_is_ssh_key" "sshkey1" {
name = "${var.ssh_key_name}"
}
resource "ibm_is_vpc" "vpc1" {
name = "${var.vpc_name}"
address_prefix_management = "auto"
}
resource "ibm_is_vpc_address_prefix" "vpc-ap1" {
name = "vpc-ap1"
zone = "${var.zone1}"
vpc = "${ibm_is_vpc.vpc1.id}"
cidr = "${var.zone1_cidr}"
}
resource "ibm_is_vpc_address_prefix" "vpc-ap2" {
name = "vpc-ap2"
zone = "${var.zone2}"
vpc = "${ibm_is_vpc.vpc1.id}"
cidr = "${var.zone2_cidr}"
}
resource "ibm_is_subnet" "subnet1" {
name = "subnet1"
vpc = "${ibm_is_vpc.vpc1.id}"
zone = "${var.zone1}"
ipv4_cidr_block = "${var.zone1_cidr}"
depends_on = ["ibm_is_vpc_address_prefix.vpc-ap1"]
}
resource "ibm_is_subnet" "subnet2" {
name = "subnet2"
vpc = "${ibm_is_vpc.vpc1.id}"
zone = "${var.zone2}"
ipv4_cidr_block = "${var.zone2_cidr}"
depends_on = ["ibm_is_vpc_address_prefix.vpc-ap2"]
}
resource "ibm_is_instance" "instance1" {
name = "instance1"
image = "${var.image}"
profile = "${var.profile}"
primary_network_interface = {
subnet = "${ibm_is_subnet.subnet1.id}"
}
vpc = "${ibm_is_vpc.vpc1.id}"
zone = "${var.zone1}"
keys = ["${data.ibm_is_ssh_key.sshkey1.id}"]
user_data = "${data.template_cloudinit_config.cloud-init-apptier.rendered}"
}
resource "ibm_is_instance" "instance2" {
name = "instance2"
image = "${var.image}"
profile = "${var.profile}"
primary_network_interface = {
subnet = "${ibm_is_subnet.subnet2.id}"
}
vpc = "${ibm_is_vpc.vpc1.id}"
zone = "${var.zone2}"
keys = ["${data.ibm_is_ssh_key.sshkey1.id}"]
user_data = "${data.template_cloudinit_config.cloud-init-apptier.rendered}"
}
resource "ibm_is_floating_ip" "floatingip1" {
name = "fip1"
target = "${ibm_is_instance.instance1.primary_network_interface.0.id}"
}
resource "ibm_is_floating_ip" "floatingip2" {
name = "fip2"
target = "${ibm_is_instance.instance2.primary_network_interface.0.id}"
}
resource "ibm_is_security_group_rule" "sg1_tcp_rule_22" {
depends_on = ["ibm_is_floating_ip.floatingip1", "ibm_is_floating_ip.floatingip2"]
group = "${ibm_is_vpc.vpc1.default_security_group}"
direction = "inbound"
remote = "0.0.0.0/0"
tcp = {
port_min = "22"
port_max = "22"
}
}
resource "ibm_is_security_group_rule" "sg1_tcp_rule_80" {
depends_on = ["ibm_is_floating_ip.floatingip1", "ibm_is_floating_ip.floatingip2"]
group = "${ibm_is_vpc.vpc1.default_security_group}"
direction = "inbound"
remote = "0.0.0.0/0"
tcp = {
port_min = "80"
port_max = "80"
}
}