11// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
22// Licensed under the Mozilla Public License v2.0
33
4- variable "tenancy_ocid" {
5- }
4+ variable "tenancy_ocid" {}
65
7- variable "user_ocid" {
8- }
6+ variable "user_ocid" {}
97
10- variable "fingerprint" {
11- }
8+ variable "fingerprint" {}
129
13- variable "private_key_path" {
14- }
10+ variable "private_key_path" {}
1511
16- variable "region" {
17- }
12+ variable "region" {}
1813
19- variable "compartment_ocid" {
20- }
14+ variable "compartment_ocid" {}
2115
22- variable "customer_bare_metal_host_id" {
23- }
16+ variable subnet_id {}
2417
2518variable "instance_image_ocid" {
2619 type = map (string )
@@ -31,13 +24,36 @@ variable "instance_image_ocid" {
3124 }
3225}
3326
27+ locals {
28+ # For resource "oci_core_dedicated_vm_host" "test_dedicated_vm_host"
29+ dvh_shape = " DVH.DenseIO.E4.128"
30+ dvh_display_name = " TestDedicatedVmHost"
31+
32+ # For resource "oci_core_instance" "test_instance"
33+ vmi_display_name = " TestInstance"
34+ vmi_shape = " VM.DenseIO.E4.Flex"
35+ instance_shape_config_memory_in_gbs = " 128"
36+ instance_shape_config_ocpus = " 8"
37+ instance_shape_config_nvmes = " 1"
38+
39+ # For data "oci_core_dedicated_vm_hosts" "test_dedicated_vm_hosts"
40+ dvh_lifecycle_state = " ACTIVE"
41+ remaining_memory_in_gbs_greater_than_or_equal_to = " 512.0"
42+ remaining_ocpus_greater_than_or_equal_to = " 32.0"
43+
44+ # For data "oci_core_subnet" "test_subnet"
45+ subnet_id = var. subnet_id
46+ }
47+
3448provider "oci" {
35- tenancy_ocid = var. tenancy_ocid
36- user_ocid = var. user_ocid
37- fingerprint = var. fingerprint
38- private_key_path = var. private_key_path
39- region = var. region
40- # version = "7.1.0"
49+ auth = " SecurityToken"
50+ config_file_profile = " "
51+ tenancy_ocid = var. tenancy_ocid
52+ user_ocid = var. user_ocid
53+ fingerprint = var. fingerprint
54+ private_key_path = var. private_key_path
55+ region = var. region
56+ # version = "7.1.0"
4157}
4258
4359data "oci_identity_availability_domain" "ad" {
@@ -49,83 +65,76 @@ resource "oci_core_dedicated_vm_host" "test_dedicated_vm_host" {
4965 # Required
5066 availability_domain = data. oci_identity_availability_domain . ad . name
5167 compartment_id = var. compartment_ocid
52- dedicated_vm_host_shape = " DVH.DenseIO.E4.128 "
68+ dedicated_vm_host_shape = local . dvh_shape
5369
5470 # Optional
55- # defined_tags = {
56- # "${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}" = "value"
57- # }
58- # freeform_tags = var.dedicated_vm_host_freeform_tags
59- display_name = " TestDedicatedVmHost"
60-
61- placement_constraint_details {
62- type = " COMPUTE_BARE_METAL_HOST"
63- compute_bare_metal_host_id = var. customer_bare_metal_host_id
64- }
71+ display_name = local. dvh_display_name
72+
6573 timeouts {
6674 create = " 60m"
6775 }
68-
6976}
7077
7178# instance using dedicated vm host
7279resource "oci_core_instance" "test_instance" {
80+ # Required
7381 availability_domain = data. oci_identity_availability_domain . ad . name
7482 compartment_id = var. compartment_ocid
75- display_name = " TestInstance"
76- shape = " VM.Standard2.1"
83+ shape = local. vmi_shape
84+
85+ # Optional but required for DVH Testing
86+ dedicated_vm_host_id = oci_core_dedicated_vm_host. test_dedicated_vm_host . id
87+
88+ # Optional
89+ display_name = local. vmi_display_name
90+ shape_config {
91+ memory_in_gbs = local. instance_shape_config_memory_in_gbs
92+ ocpus = local. instance_shape_config_ocpus
93+ nvmes = local. instance_shape_config_nvmes
94+ }
95+ instance_options {
96+ are_legacy_imds_endpoints_disabled = true
97+ }
98+ availability_config {
99+ recovery_action = " RESTORE_INSTANCE"
100+ }
77101
78102 create_vnic_details {
79- subnet_id = oci_core_subnet. test_subnet . id
103+ subnet_id = data . oci_core_subnet . test_subnet . id
80104 display_name = " Primaryvnic"
81105 assign_public_ip = true
82106 hostname_label = " TestInstanceLabel"
83107 }
84108
85- dedicated_vm_host_id = oci_core_dedicated_vm_host. test_dedicated_vm_host . id
86-
87109 source_details {
88110 source_type = " image"
89111 source_id = var. instance_image_ocid [var . region ]
90112 # Apply this to set the size of the boot volume that's created for this instance.
91113 # Otherwise, the default boot volume size of the image is used.
92114 # This should only be specified when source_type is set to "image".
93- # boot_volume_size_in_gbs = "60"
115+ # boot_volume_size_in_gbs = "60"
94116 }
95117
96118 timeouts {
97119 create = " 60m"
98120 }
99121}
100122
101- resource "oci_core_vcn" "test_vcn" {
102- cidr_block = " 10.1.0.0/16"
103- compartment_id = var. compartment_ocid
104- display_name = " TestVcn"
105- dns_label = " testvcn"
106- }
107-
108- resource "oci_core_subnet" "test_subnet" {
109- availability_domain = data. oci_identity_availability_domain . ad . name
110- cidr_block = " 10.1.20.0/24"
111- display_name = " TestSubnet"
112- dns_label = " testsubnet"
113- security_list_ids = [oci_core_vcn . test_vcn . default_security_list_id ]
114- compartment_id = var. compartment_ocid
115- vcn_id = oci_core_vcn. test_vcn . id
116- route_table_id = oci_core_vcn. test_vcn . default_route_table_id
117- dhcp_options_id = oci_core_vcn. test_vcn . default_dhcp_options_id
123+ data "oci_core_subnet" "test_subnet" {
124+ subnet_id = local. subnet_id
118125}
119126
120127data "oci_core_dedicated_vm_hosts" "test_dedicated_vm_hosts" {
121128 # Required
122129 compartment_id = var. compartment_ocid
123130
124131 # Optional
125- availability_domain = data. oci_identity_availability_domain . ad . name
126- display_name = " TestDedicatedVmHost"
127- instance_shape_name = " VM.Standard2.1"
128- state = " ACTIVE"
132+ availability_domain = data. oci_identity_availability_domain . ad . name
133+ display_name = local. dvh_display_name
134+ instance_shape_name = local. vmi_shape
135+ remaining_memory_in_gbs_greater_than_or_equal_to = local. remaining_memory_in_gbs_greater_than_or_equal_to
136+ remaining_ocpus_greater_than_or_equal_to = local. remaining_ocpus_greater_than_or_equal_to
137+ state = local. dvh_lifecycle_state
129138}
130139
131140data "oci_core_dedicated_vm_host_instance_shapes" "test_dedicated_vm_host_instance_shapes" {
@@ -134,7 +143,7 @@ data "oci_core_dedicated_vm_host_instance_shapes" "test_dedicated_vm_host_instan
134143
135144 # Optional
136145 availability_domain = data. oci_identity_availability_domain . ad . name
137- dedicated_vm_host_shape = " DVH.Standard2.52 "
146+ dedicated_vm_host_shape = local . dvh_shape
138147}
139148
140149data "oci_core_dedicated_vm_host_shapes" "test_dedicated_vm_host_shapes" {
@@ -143,45 +152,27 @@ data "oci_core_dedicated_vm_host_shapes" "test_dedicated_vm_host_shapes" {
143152
144153 # Optional
145154 availability_domain = data. oci_identity_availability_domain . ad . name
146- instance_shape_name = " VM.Standard2.1"
147- }
148-
149- data "oci_core_dedicated_vm_hosts_instances" "test_dedicated_vm_hosts_instances" {
150- # Required
151- compartment_id = var. compartment_ocid
152- dedicated_vm_host_id = oci_core_dedicated_vm_host. test_dedicated_vm_host . id
153-
154- # Optional
155- availability_domain = data. oci_identity_availability_domain . ad . name
156- depends_on = [oci_core_instance . test_instance ]
155+ instance_shape_name = local. vmi_shape
157156}
158157
159158data "oci_core_dedicated_vm_host" "test_oci_core_dedicated_vm_host" {
160159 dedicated_vm_host_id = oci_core_dedicated_vm_host. test_dedicated_vm_host . id
161160}
162161
163- # output the dedidcated vm host ids
164- output "dedicated_hos_idst " {
162+ # output the dedicated vm host ids
163+ output "dedicated_host_ids " {
165164 value = [data . oci_core_dedicated_vm_hosts . test_dedicated_vm_hosts . id ]
166165}
167166
168- # output the dedidcated vm host ids
167+ # output the dedicated vm host ids
169168output "dedicated_host_shapes" {
170169 value = [data . oci_core_dedicated_vm_host_shapes . test_dedicated_vm_host_shapes . dedicated_vm_host_shapes ]
171170}
172171
173- output "dedicated_vm_host_instances" {
174- value = [data . oci_core_dedicated_vm_hosts_instances . test_dedicated_vm_hosts_instances . dedicated_vm_host_instances ]
175- }
176-
177172output "dedicated_vm_host_instance_shapes" {
178173 value = [data . oci_core_dedicated_vm_host_instance_shapes . test_dedicated_vm_host_instance_shapes . dedicated_vm_host_instance_shapes ]
179174}
180175
181- output "dedicated_vm_host" {
182- value = [oci_core_dedicated_vm_host . test_dedicated_vm_host . * ]
183- }
184-
185176output "dedicated_vm_host_data" {
186177 value = [data . oci_core_dedicated_vm_host . test_oci_core_dedicated_vm_host . * ]
187178}
0 commit comments