-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.tf
85 lines (73 loc) · 2.48 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
locals {
user = "opc"
ssh_key = ""
knock_ssh = join(",", [for x in concat(var.ssh_knock) : "${x.port}:${x.protocol}"])
knock_minecraft = join(",", [for x in concat(var.minecraft_knock) : "${x.port}:${x.protocol}"])
}
data "oci_core_images" "oraclelinux8_aarch64" {
compartment_id = data.oci_identity_compartment.root.id
operating_system = "Oracle Linux"
operating_system_version = "8"
# include Aarch64 specific images
filter {
name = "display_name"
values = ["^.*-aarch64-.*$"]
regex = true
}
}
resource "oci_core_instance" "ampere" {
# Required
availability_domain = "DThj:EU-FRANKFURT-1-AD-3"
compartment_id = data.oci_identity_compartment.root.id
shape = "VM.Standard.A1.Flex"
is_pv_encryption_in_transit_enabled = true
lifecycle {
ignore_changes = [
source_details
]
}
shape_config {
memory_in_gbs = 24
ocpus = 4
}
source_details {
source_id = data.oci_core_images.oraclelinux8_aarch64.images.0.id
source_type = "image"
boot_volume_size_in_gbs = 100
}
# Optional
display_name = "Ampere server"
create_vnic_details {
assign_public_ip = true
subnet_id = oci_core_subnet.server.id
}
metadata = {
ssh_authorized_keys = local.ssh_key
}
preserve_boot_volume = false
provisioner "remote-exec" {
script = "scripts/wait_for_instance.sh"
connection {
host = oci_core_instance.ampere.public_ip
user = local.user
}
}
provisioner "remote-exec" {
script = "scripts/install_python.sh"
connection {
host = oci_core_instance.ampere.public_ip
user = local.user
}
}
provisioner "local-exec" {
working_dir = "ansible"
command = "ansible-playbook --inventory '${oci_core_instance.ampere.public_ip},' --extra-vars 'skip_updates=true openssh_knock_ports=\"${local.knock_ssh}\" minecraft_knock_ports=\"${local.knock_minecraft}\" minecraft_backup_namespace=\"${oci_objectstorage_bucket.minecraft.namespace}\" minecraft_backup_bucket=\"${oci_objectstorage_bucket.minecraft.name}\"' --ssh-extra-args '-o StrictHostKeyChecking=no' -u ${local.user} minecraft.yml"
}
}
resource "oci_identity_dynamic_group" "root" {
#Required
compartment_id = data.oci_identity_compartment.root.id
description = "Arm server group"
matching_rule = "instance.id = '${oci_core_instance.ampere.id}'"
name = "main"
}