-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-vm-main.tf
59 lines (50 loc) · 1.72 KB
/
api-vm-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
############################
## Create VM Image - Main ##
############################
# Get List of Availability Domains
data "oci_identity_availability_domains" "ads" {
compartment_id = oci_identity_compartment.compartment.id
}
# Template Bootstrap File
data "template_file" "bootstrap" {
template = file("${path.module}/userdata/bootstrap.ps1")
}
# Cloudinit Config
data "template_cloudinit_config" "cloudinit_config" {
gzip = false
base64_encode = true
part {
filename = "bootstrap.ps1"
content_type = "text/x-shellscript"
content = data.template_file.bootstrap.rendered
}
}
# Create Virtual Machine Instance
resource "oci_core_instance" "api" {
display_name = "${var.app_name}-${var.environment}-vm"
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
compartment_id = oci_identity_compartment.compartment.id
shape = var.instance_shape
shape_config {
baseline_ocpu_utilization = ""
memory_in_gbs = var.instance_shape_mem
ocpus = var.instance_shape_cpu
}
create_vnic_details {
subnet_id = oci_core_subnet.public_subnet.id
display_name = "${var.app_name}-${var.environment}-vm-nic"
assign_public_ip = true
}
source_details {
source_type = "image"
source_id = data.oci_core_images.windows-2022.images.0.id
}
metadata = {
user_data = data.template_cloudinit_config.cloudinit_config.rendered
}
}
# Get Virtual Machine Instance Credentials
data "oci_core_instance_credentials" "api_credential" {
depends_on = [ oci_core_instance.api ]
instance_id = oci_core_instance.api.id
}