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