forked from jonghall/ibmcloud-terraform-vpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.tf
105 lines (89 loc) · 3.81 KB
/
compute.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
99
100
101
102
103
104
105
#---------------------------------------------------------
# Create sshkey from file
#---------------------------------------------------------
resource "ibm_is_ssh_key" "sshkey" {
name = "wordpress-demo"
public_key = file(var.ssh_public_key)
}
#---------------------------------------------------------
# Create instances in each subnet in zone1
#---------------------------------------------------------
resource "ibm_is_instance" "webappserver-zone1" {
count = var.webappserver-count
name = "${format(var.webappserver-name, count.index + 1)}-${var.zone1}"
image = var.image
profile = var.profile-webappserver
resource_group = data.ibm_resource_group.group.id
primary_network_interface {
subnet = ibm_is_subnet.webapptier-subnet-zone1.id
security_groups = [ibm_is_security_group.webapptier-securitygroup.id]
}
vpc = ibm_is_vpc.vpc1.id
zone = var.zone1
keys = [ibm_is_ssh_key.sshkey.id]
user_data = data.template_cloudinit_config.cloud-init-webapptier.rendered
}
resource "ibm_is_instance" "dbserver-zone1" {
count = var.dbserver-count
name = "${format(var.dbserver-name, count.index + 1)}-${var.zone1}"
image = var.image
profile = var.profile-dbserver
resource_group = data.ibm_resource_group.group.id
primary_network_interface {
subnet = ibm_is_subnet.dbtier-subnet-zone1.id
security_groups = [ibm_is_security_group.dbtier-securitygroup.id]
}
vpc = ibm_is_vpc.vpc1.id
zone = var.zone1
keys = [ibm_is_ssh_key.sshkey.id]
user_data = data.template_cloudinit_config.cloud-init-dbtier.rendered
}
#---------------------------------------------------------
## Create instances in each subnet in zone2
#---------------------------------------------------------
resource "ibm_is_instance" "webappserver-zone2" {
count = var.webappserver-count
name = "${format(var.webappserver-name, count.index + 1)}-${var.zone2}"
image = var.image
profile = var.profile-webappserver
resource_group = data.ibm_resource_group.group.id
primary_network_interface {
subnet = ibm_is_subnet.webapptier-subnet-zone2.id
security_groups = [ibm_is_security_group.webapptier-securitygroup.id]
}
vpc = ibm_is_vpc.vpc1.id
zone = var.zone2
keys = [ibm_is_ssh_key.sshkey.id]
user_data = data.template_cloudinit_config.cloud-init-webapptier.rendered
}
resource "ibm_is_instance" "dbserver-zone2" {
count = var.dbserver-count
name = "${format(var.dbserver-name, count.index + 1)}-${var.zone2}"
image = var.image
profile = var.profile-dbserver
resource_group = data.ibm_resource_group.group.id
primary_network_interface {
subnet = ibm_is_subnet.dbtier-subnet-zone2.id
security_groups = [ibm_is_security_group.dbtier-securitygroup.id]
}
vpc = ibm_is_vpc.vpc1.id
zone = var.zone2
keys = [ibm_is_ssh_key.sshkey.id]
user_data = data.template_cloudinit_config.cloud-init-dbtier.rendered
}
#---------------------------------------------------------
# Assign floating IPs if needed
#---------------------------------------------------------
# Assign floating IP's to all instances of Web Servers
#resource "ibm_is_floating_ip" "webappserver-zone1-fip" {
# count = var.webappserver-count
# name = format("%s-%s-fip", format(var.webappserver-name, count.index + 1), var.zone1)
# target = element(ibm_is_instance.webappserver-zone1.*.primary_network_interface.0.id, count.index)
# resource_group = data.ibm_resource_group.group.id
#}
#resource "ibm_is_floating_ip" "webappserver-zone2-fip" {
# count = var.webappserver-count
# name = format("%s-%s-fip", format(var.webappserver-name, count.index + 1), var.zone2)
# target = element(ibm_is_instance.webappserver-zone2.*.primary_network_interface.0.id, count.index)
# resource_group = data.ibm_resource_group.group.id
#}