-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapache.tf
57 lines (49 loc) · 1.74 KB
/
apache.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
##############################################################################
# This steps deploys an Apache Server on the 3 VSIs in the workload VPC
# This terraform connects through a publically exposed VSI in the management VPC
# using the remote-exec provisioner
##############################################################################
# Instruction: make a copy of this file to the 'custom-slz' folder
# Get all VSIs in the workload vpc
data "ibm_is_instances" "insts" {
vpc = [for vpc in module.landing_zone.vpc_data : vpc.vpc_id if endswith(vpc.vpc_name, "workload-vpc")][0]
}
# Prepare the list of of ips for all workload VSIs
locals {
workload_ip_list = flatten([for ins in data.ibm_is_instances.insts.instances :
[ins.primary_network_interface[0].primary_ipv4_address]
])
}
resource "null_resource" "application-install" {
count = 3
connection {
type = "ssh"
user = "root"
bastion_host = module.landing_zone.fip_vsi[0].floating_ip # IP of the management VSI
host = local.workload_ip_list[count.index]
private_key = var.ssh_private_key
agent = false
timeout = "15m"
}
provisioner "remote-exec" {
inline = [
"apt-get update",
"apt-get install apache2 -y"
]
}
provisioner "file" {
content = <<EOT
<html>
<img src="https://raw.githubusercontent.com/IBM/infra-to-app-with-landing-zone/main/docs/header.jpg">
<h1> You did it!! </h1>
</html>
EOT
destination = "/var/www/html/index.html"
}
}
# Extra variable required to allow to connect to the workload vsis through the management vsi
variable "ssh_private_key" {
description = "Private SSH key (RSA format) that is paired with the public ssh key."
type = string
sensitive = true
}