|
| 1 | +resource "oci_core_instance" "TFInstance" { |
| 2 | + availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}" |
| 3 | + compartment_id = "${var.compartment_ocid}" |
| 4 | + display_name = "TFInstanceForInstancePool" |
| 5 | + shape = "${var.instance_shape}" |
| 6 | + |
| 7 | + create_vnic_details { |
| 8 | + subnet_id = "${oci_core_subnet.ExampleSubnet.id}" |
| 9 | + display_name = "primaryvnic" |
| 10 | + assign_public_ip = true |
| 11 | + hostname_label = "tfexampleinstance${count.index}" |
| 12 | + } |
| 13 | + |
| 14 | + source_details { |
| 15 | + source_type = "image" |
| 16 | + source_id = "${var.instance_image_ocid[var.region]}" |
| 17 | + } |
| 18 | + |
| 19 | + timeouts { |
| 20 | + create = "60m" |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +resource "oci_core_instance_configuration" "TFInstanceConfiguration" { |
| 25 | + compartment_id = "${var.compartment_ocid}" |
| 26 | + display_name = "TFExampleInstanceConfiguration" |
| 27 | + |
| 28 | + instance_details { |
| 29 | + instance_type = "compute" |
| 30 | + |
| 31 | + launch_details { |
| 32 | + compartment_id = "${var.compartment_ocid}" |
| 33 | + ipxe_script = "ipxeScript" |
| 34 | + shape = "${var.instance_shape}" |
| 35 | + display_name = "TFExampleInstanceConfigurationLaunchDetails" |
| 36 | + |
| 37 | + create_vnic_details { |
| 38 | + assign_public_ip = true |
| 39 | + display_name = "TFExampleInstanceConfigurationVNIC" |
| 40 | + skip_source_dest_check = false |
| 41 | + } |
| 42 | + |
| 43 | + extended_metadata = { |
| 44 | + some_string = "stringA" |
| 45 | + nested_object = "{\"some_string\": \"stringB\", \"object\": {\"some_string\": \"stringC\"}}" |
| 46 | + } |
| 47 | + |
| 48 | + source_details = { |
| 49 | + source_type = "image" |
| 50 | + image_id = "${var.instance_image_ocid[var.region]}" |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +resource "oci_core_instance_pool" "TFInstancePool" { |
| 57 | + compartment_id = "${var.compartment_ocid}" |
| 58 | + instance_configuration_id = "${oci_core_instance_configuration.TFInstanceConfiguration.id}" |
| 59 | + size = 2 |
| 60 | + state = "RUNNING" |
| 61 | + display_name = "TFInstancePool" |
| 62 | + |
| 63 | + placement_configurations { |
| 64 | + availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}" |
| 65 | + primary_subnet_id = "${oci_core_subnet.ExampleSubnet.id}" |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +resource "oci_auto_scaling_auto_scaling_configuration" "TFAutoScalingConfiguration" { |
| 70 | + compartment_id = "${var.compartment_ocid}" |
| 71 | + cool_down_in_seconds = "300" |
| 72 | + display_name = "TFAutoScalingConfiguration" |
| 73 | + is_enabled = "true" |
| 74 | + |
| 75 | + policies { |
| 76 | + capacity { |
| 77 | + initial = "4" |
| 78 | + max = "4" |
| 79 | + min = "2" |
| 80 | + } |
| 81 | + |
| 82 | + display_name = "TFPolicy" |
| 83 | + policy_type = "threshold" |
| 84 | + |
| 85 | + rules { |
| 86 | + action { |
| 87 | + type = "CHANGE_COUNT_BY" |
| 88 | + value = "1" |
| 89 | + } |
| 90 | + |
| 91 | + display_name = "TFScaleOutRule" |
| 92 | + |
| 93 | + metric { |
| 94 | + metric_type = "CPU_UTILIZATION" |
| 95 | + |
| 96 | + threshold { |
| 97 | + operator = "GT" |
| 98 | + value = "1" |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + rules { |
| 104 | + action { |
| 105 | + type = "CHANGE_COUNT_BY" |
| 106 | + value = "-1" |
| 107 | + } |
| 108 | + |
| 109 | + display_name = "TFScaleInRule" |
| 110 | + |
| 111 | + metric { |
| 112 | + metric_type = "CPU_UTILIZATION" |
| 113 | + |
| 114 | + threshold { |
| 115 | + operator = "LT" |
| 116 | + value = "1" |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + auto_scaling_resources { |
| 123 | + id = "${oci_core_instance_pool.TFInstancePool.id}" |
| 124 | + type = "instancePool" |
| 125 | + } |
| 126 | +} |
0 commit comments