/
main.tf
47 lines (41 loc) · 1.24 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
provider "ibm" {
ibmcloud_api_key = "${var.ibmcloud_api_key}"
iaas_classic_username = "${var.softlayer_username}"
iaas_classic_api_key = "${var.softlayer_api_key}"
region = "${var.region}"
}
resource "ibm_compute_ssh_key" "key" {
label = "${var.prefix}-vm-to-migrate"
public_key = "${file("${var.ssh_public_key_file}")}"
}
resource "ibm_compute_vm_instance" "vm" {
hostname = "${var.prefix}-classic-vm"
domain = "howto.cloud"
ssh_key_ids = ["${ibm_compute_ssh_key.key.id}"]
os_reference_code = "CENTOS_7_64"
datacenter = "${var.classic_datacenter}"
cores = 1
memory = 1024
provisioner "remote-exec" {
connection {
type = "ssh"
user = "root"
private_key = "${file("${var.ssh_private_key_file}")}"
agent = false
}
# install nginx on the server
inline = [
"touch this_file_was_created_in_classic",
"yum install -y epel-release",
"yum install -y nginx",
"systemctl start nginx",
"chkconfig nginx on",
]
}
}
output "CLASSIC_ID" {
value = "${ibm_compute_vm_instance.vm.id}"
}
output "CLASSIC_IP_ADDRESS" {
value = "${ibm_compute_vm_instance.vm.ipv4_address}"
}