-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
96 lines (78 loc) · 3.81 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
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
data "template_file" "unifi-init" {
template = "${file("./cloud-init/unifi-init.yaml")}"
}
resource "oci_identity_compartment" "unificontroller_compartment" {
compartment_id = "${var.compartment_ocid}"
description = "Unifi Controller Compartment"
name = "${var.project_name}"
}
resource "oci_core_instance" "unificontroller_instance" {
availability_domain = "${data.oci_identity_availability_domain.unificontroller-ad.name}"
compartment_id = "${oci_identity_compartment.unificontroller_compartment.id}"
shape = "${var.instance_shape}"
display_name = "${var.project_name}-${random_id.unificontroller_id.dec}"
shape_config {
#Optional
# baseline_ocpu_utilization = var.instance_shape_config_baseline_ocpu_utilization
memory_in_gbs = var.instance_shape_config_memory_in_gbs
ocpus = var.instance_shape_config_ocpus
}
create_vnic_details {
subnet_id = "${oci_core_subnet.unificontrollerSubnet.id}"
nsg_ids = ["${oci_core_network_security_group.unificontroller_network_security_group.id}"]
}
source_details {
source_type = "image"
source_id = "${lookup(data.oci_core_images.supported_shape_images.images[0], "id")}"
}
metadata = {
ssh_authorized_keys = "${var.ssh_public_key}"
user_data = "${base64encode(data.template_file.unifi-init.rendered)}"
ddns_url = "${var.ddns_url}"
email = "${var.email}"
timezone = "${var.timezone}"
dns_name = "${var.dns_name}"
bucket_url = "https://objectstorage.${var.region}.oraclecloud.com${oci_objectstorage_preauthrequest.unifi_backup_preauthenticated_request.access_uri}"
bucket_name = "${var.bucket_name}"
bucket_namespace = "${var.bucket_namespace}"
customer_secret_key = "${var.customer_secret_key}"
customer_access_key = "${var.customer_access_key}"
region = "${var.region}"
}
}
data "oci_identity_availability_domain" "unificontroller-ad" {
#Required
compartment_id = "${var.compartment_ocid}"
#Optional
ad_number = "${var.availability_domain}"
}
# Gets a list of images within a tenancy with the specified criteria
data "oci_core_images" "supported_shape_images" {
compartment_id = "${var.compartment_ocid}"
# Uncomment below to filter images that support a specific instance shape
shape = "${var.instance_shape}"
operating_system = "${var.operating_system}"
operating_system_version = "${var.operating_system_version}"
sort_by = "TIMECREATED"
# Default sort order for TIMECREATED is descending (DESC)
#sort_order = "ASC"
state = "AVAILABLE"
# Uncomment below to sort images by display name, display name sort order is case-sensitive
#sort_by = "DISPLAYNAME"
# Default sort order for DISPLAYNAME is ascending (ASC)
#sort_order = "DESC"
}
# Hints to getting the list of available images to always get the most recent
# https://github.com/terraform-providers/terraform-provider-oci/blob/master/examples/compute/image/image.tf
# https://www.exitas.be/blog/assigning-reserved-public-ips-to-guests-with-oracle-cloud-and-terraform/
# Great guide to creating and assigning a Reserved public IP but destroys it when destroying everything else
#data "oci_core_private_ips" "unificontroller_private_ips" {
# ip_address = oci_core_instance.unificontroller-instance.private_ip
# subnet_id = oci_core_subnet.unificontrollerSubnet.id
#}
#resource "oci_core_public_ip" "unificontroller_public_ip" {
# compartment_id = "${oci_identity_compartment.unificontroller_compartment.id}"
# display_name = "Unifi Controller Public IP"
# lifetime = "RESERVED"
# private_ip_id = data.oci_core_private_ips.unificontroller_private_ips.private_ips[0]["id"]
#}