|
| 1 | +// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + |
| 3 | +variable "tenancy_ocid" {} |
| 4 | +variable "user_ocid" {} |
| 5 | +variable "fingerprint" {} |
| 6 | +variable "private_key_path" {} |
| 7 | +variable "region" {} |
| 8 | +variable "compartment_ocid" {} |
| 9 | + |
| 10 | +variable "instance_image_ocid" { |
| 11 | + type = "map" |
| 12 | + |
| 13 | + default = { |
| 14 | + # See https://docs.us-phoenix-1.oraclecloud.com/images/ |
| 15 | + # Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0" |
| 16 | + us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa" |
| 17 | + |
| 18 | + us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda" |
| 19 | + eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma" |
| 20 | + uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa" |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +provider "oci" { |
| 25 | + tenancy_ocid = "${var.tenancy_ocid}" |
| 26 | + user_ocid = "${var.user_ocid}" |
| 27 | + fingerprint = "${var.fingerprint}" |
| 28 | + private_key_path = "${var.private_key_path}" |
| 29 | + region = "${var.region}" |
| 30 | +} |
| 31 | + |
| 32 | +data "oci_identity_availability_domain" "ad" { |
| 33 | + compartment_id = "${var.tenancy_ocid}" |
| 34 | + ad_number = 1 |
| 35 | +} |
| 36 | + |
| 37 | +resource "oci_core_dedicated_vm_host" "test_dedicated_vm_host" { |
| 38 | + #Required |
| 39 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 40 | + compartment_id = "${var.compartment_ocid}" |
| 41 | + dedicated_vm_host_shape = "DVH.Standard2.52" |
| 42 | + |
| 43 | + #Optional |
| 44 | + #defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.dedicated_vm_host_defined_tags_value}")}" |
| 45 | + #freeform_tags = "${var.dedicated_vm_host_freeform_tags}" |
| 46 | + display_name = "TestDedicatedVmHost" |
| 47 | +} |
| 48 | + |
| 49 | +# instance using dedicated vm host |
| 50 | +resource "oci_core_instance" "test_instance" { |
| 51 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 52 | + compartment_id = "${var.compartment_ocid}" |
| 53 | + display_name = "TestInstance" |
| 54 | + shape = "VM.Standard2.1" |
| 55 | + |
| 56 | + create_vnic_details { |
| 57 | + subnet_id = "${oci_core_subnet.test_subnet.id}" |
| 58 | + display_name = "Primaryvnic" |
| 59 | + assign_public_ip = true |
| 60 | + hostname_label = "TestInstanceLabel" |
| 61 | + } |
| 62 | + |
| 63 | + dedicated_vm_host_id = "${oci_core_dedicated_vm_host.test_dedicated_vm_host.id}" |
| 64 | + |
| 65 | + source_details { |
| 66 | + source_type = "image" |
| 67 | + source_id = "${var.instance_image_ocid[var.region]}" |
| 68 | + |
| 69 | + # Apply this to set the size of the boot volume that's created for this instance. |
| 70 | + # Otherwise, the default boot volume size of the image is used. |
| 71 | + # This should only be specified when source_type is set to "image". |
| 72 | + #boot_volume_size_in_gbs = "60" |
| 73 | + } |
| 74 | + |
| 75 | + timeouts { |
| 76 | + create = "60m" |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +resource "oci_core_vcn" "test_vcn" { |
| 81 | + cidr_block = "10.1.0.0/16" |
| 82 | + compartment_id = "${var.compartment_ocid}" |
| 83 | + display_name = "TestVcn" |
| 84 | + dns_label = "testvcn" |
| 85 | +} |
| 86 | + |
| 87 | +resource "oci_core_subnet" "test_subnet" { |
| 88 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 89 | + cidr_block = "10.1.20.0/24" |
| 90 | + display_name = "TestSubnet" |
| 91 | + dns_label = "testsubnet" |
| 92 | + security_list_ids = ["${oci_core_vcn.test_vcn.default_security_list_id}"] |
| 93 | + compartment_id = "${var.compartment_ocid}" |
| 94 | + vcn_id = "${oci_core_vcn.test_vcn.id}" |
| 95 | + route_table_id = "${oci_core_vcn.test_vcn.default_route_table_id}" |
| 96 | + dhcp_options_id = "${oci_core_vcn.test_vcn.default_dhcp_options_id}" |
| 97 | +} |
| 98 | + |
| 99 | +data "oci_core_dedicated_vm_hosts" "test_dedicated_vm_hosts" { |
| 100 | + #Required |
| 101 | + compartment_id = "${var.compartment_ocid}" |
| 102 | + |
| 103 | + #Optional |
| 104 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 105 | + display_name = "TestDedicatedVmHost" |
| 106 | + instance_shape_name = "VM.Standard2.1" |
| 107 | + state = "ACTIVE" |
| 108 | +} |
| 109 | + |
| 110 | +data "oci_core_dedicated_vm_host_instance_shapes" "test_dedicated_vm_host_instance_shapes" { |
| 111 | + #Required |
| 112 | + compartment_id = "${var.compartment_ocid}" |
| 113 | + |
| 114 | + #Optional |
| 115 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 116 | + dedicated_vm_host_shape = "DVH.Standard2.52" |
| 117 | +} |
| 118 | + |
| 119 | +data "oci_core_dedicated_vm_host_shapes" "test_dedicated_vm_host_shapes" { |
| 120 | + #Required |
| 121 | + compartment_id = "${var.compartment_ocid}" |
| 122 | + |
| 123 | + #Optional |
| 124 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 125 | + instance_shape_name = "VM.Standard2.1" |
| 126 | +} |
| 127 | + |
| 128 | +data "oci_core_dedicated_vm_hosts_instances" "test_dedicated_vm_hosts_instances" { |
| 129 | + #Required |
| 130 | + compartment_id = "${var.compartment_ocid}" |
| 131 | + dedicated_vm_host_id = "${oci_core_dedicated_vm_host.test_dedicated_vm_host.id}" |
| 132 | + |
| 133 | + #Optional |
| 134 | + availability_domain = "${data.oci_identity_availability_domain.ad.name}" |
| 135 | + depends_on = ["oci_core_instance.test_instance"] |
| 136 | +} |
| 137 | + |
| 138 | +#output the dedidcated vm host ids |
| 139 | +output "dedicated_hos_idst" { |
| 140 | + value = ["${data.oci_core_dedicated_vm_hosts.test_dedicated_vm_hosts.id}"] |
| 141 | +} |
| 142 | + |
| 143 | +#output the dedidcated vm host ids |
| 144 | +output "dedicated_host_shapes" { |
| 145 | + value = ["${data.oci_core_dedicated_vm_host_shapes.test_dedicated_vm_host_shapes.dedicated_vm_host_shapes}"] |
| 146 | +} |
| 147 | + |
| 148 | +output "dedicated_vm_host_instances" { |
| 149 | + value = ["${data.oci_core_dedicated_vm_hosts_instances.test_dedicated_vm_hosts_instances.dedicated_vm_host_instances}"] |
| 150 | +} |
| 151 | + |
| 152 | +output "dedicated_vm_host_instance_shapes" { |
| 153 | + value = ["${data.oci_core_dedicated_vm_host_instance_shapes.test_dedicated_vm_host_instance_shapes.dedicated_vm_host_instance_shapes}"] |
| 154 | +} |
0 commit comments