1+ // Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+ // Licensed under the Mozilla Public License v2.0
3+
4+ variable "tenancy_ocid" {
5+
6+ }
7+
8+ variable "user_ocid" {
9+
10+ }
11+
12+ variable "fingerprint" {
13+
14+ }
15+
16+ variable "private_key_path" {
17+
18+ }
19+
20+ variable "region" {
21+
22+ }
23+
24+ variable "compartment_ocid" {
25+
26+ }
27+
28+ provider "oci" {
29+ tenancy_ocid = var. tenancy_ocid
30+ user_ocid = var. user_ocid
31+ fingerprint = var. fingerprint
32+ private_key_path = var. private_key_path
33+ region = var. region
34+ }
35+
36+ variable "num_instances" {
37+ default = " 1"
38+ }
39+
40+ variable "instance_shape" {
41+ default = " VM.Standard.E3.Flex"
42+ }
43+
44+ variable "instance_ocpus" {
45+ default = 1
46+ }
47+
48+ variable "instance_shape_config_memory_in_gbs" {
49+ default = 1
50+ }
51+
52+ variable "instance_image_ocid" {
53+ type = map (string )
54+
55+ default = {
56+ # See https://docs.us-phoenix-1.oraclecloud.com/images/
57+ # Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0"
58+ us-phoenix-1 = " ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa"
59+ us-ashburn-1 = " ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda"
60+ eu-frankfurt-1 = " ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma"
61+ uk-london-1 = " ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa"
62+ }
63+ }
64+
65+ variable "flex_instance_image_ocid" {
66+ type = map (string )
67+ default = {
68+ us-phoenix-1 = " ocid1.image.oc1.phx.aaaaaaaa6hooptnlbfwr5lwemqjbu3uqidntrlhnt45yihfj222zahe7p3wq"
69+ us-ashburn-1 = " ocid1.image.oc1.iad.aaaaaaaa6tp7lhyrcokdtf7vrbmxyp2pctgg4uxvt4jz4vc47qoc2ec4anha"
70+ eu-frankfurt-1 = " ocid1.image.oc1.eu-frankfurt-1.aaaaaaaadvi77prh3vjijhwe5xbd6kjg3n5ndxjcpod6om6qaiqeu3csof7a"
71+ uk-london-1 = " ocid1.image.oc1.uk-london-1.aaaaaaaaw5gvriwzjhzt2tnylrfnpanz5ndztyrv3zpwhlzxdbkqsjfkwxaq"
72+ }
73+ }
74+
75+ variable "db_size" {
76+ default = " 50" # size in GBs
77+ }
78+
79+
80+ resource "oci_core_instance" "test_instance" {
81+ count = var. num_instances
82+ availability_domain = data. oci_identity_availability_domain . ad . name
83+ compartment_id = var. compartment_ocid
84+ display_name = " TestInstance${ count . index } "
85+ shape = var. instance_shape
86+
87+ shape_config {
88+ ocpus = " ${ var . instance_ocpus } "
89+ memory_in_gbs = " ${ var . instance_shape_config_memory_in_gbs } "
90+ }
91+
92+ create_vnic_details {
93+ subnet_id = oci_core_subnet. test_subnet . id
94+ display_name = " Primaryvnic"
95+ assign_public_ip = true
96+ hostname_label = " tfexampleinstance${ count . index } "
97+ }
98+
99+ source_details {
100+ source_type = " image"
101+ source_id = var. flex_instance_image_ocid [var . region ]
102+ }
103+
104+ agent_config {
105+ are_all_plugins_disabled = false
106+ is_management_disabled = true
107+ is_monitoring_disabled = true
108+ plugins_config {
109+ name = " Compute Instance Monitoring"
110+ desired_state = " ENABLED"
111+ }
112+ }
113+ }
114+
115+ resource "oci_core_vcn" "test_vcn" {
116+ cidr_block = " 10.1.0.0/16"
117+ compartment_id = var. compartment_ocid
118+ display_name = " TestVcn"
119+ dns_label = " testvcn"
120+ }
121+
122+ resource "oci_core_internet_gateway" "test_internet_gateway" {
123+ compartment_id = var. compartment_ocid
124+ display_name = " TestInternetGateway"
125+ vcn_id = oci_core_vcn. test_vcn . id
126+ }
127+
128+ resource "oci_core_default_route_table" "default_route_table" {
129+ manage_default_resource_id = oci_core_vcn. test_vcn . default_route_table_id
130+ display_name = " DefaultRouteTable"
131+
132+ route_rules {
133+ destination = " 0.0.0.0/0"
134+ destination_type = " CIDR_BLOCK"
135+ network_entity_id = oci_core_internet_gateway. test_internet_gateway . id
136+ }
137+ }
138+
139+ resource "oci_core_subnet" "test_subnet" {
140+ availability_domain = data. oci_identity_availability_domain . ad . name
141+ cidr_block = " 10.1.20.0/24"
142+ display_name = " TestSubnet"
143+ dns_label = " testsubnet"
144+ security_list_ids = [oci_core_vcn . test_vcn . default_security_list_id ]
145+ compartment_id = var. compartment_ocid
146+ vcn_id = oci_core_vcn. test_vcn . id
147+ route_table_id = oci_core_vcn. test_vcn . default_route_table_id
148+ dhcp_options_id = oci_core_vcn. test_vcn . default_dhcp_options_id
149+ }
150+
151+ data "oci_identity_availability_domain" "ad" {
152+ compartment_id = var. tenancy_ocid
153+ ad_number = 1
154+ }
155+
156+ data "oci_computeinstanceagent_instance_agent_plugins" "test_instance_agent_plugins" {
157+ compartment_id = var. compartment_ocid
158+ instanceagent_id = oci_core_instance. test_instance . 0 . id
159+ }
160+
161+ output "agent_plugins" {
162+ value = [data . oci_computeinstanceagent_instance_agent_plugins . test_instance_agent_plugins ]
163+ }
164+
165+ variable "instance_available_plugin_os_name" {
166+ default = " Oracle Linux"
167+ }
168+
169+ variable "instance_available_plugin_os_version" {
170+ default = " 7.8"
171+ }
172+
173+
174+ data "oci_computeinstanceagent_instance_available_plugins" "test_instance_available_plugins" {
175+ # Required
176+ compartment_id = var. compartment_ocid
177+ os_name = var. instance_available_plugin_os_name
178+ os_version = var. instance_available_plugin_os_version
179+ }
180+
181+ output "available_plugins" {
182+ value = [data . oci_computeinstanceagent_instance_available_plugins . test_instance_available_plugins ]
183+ }
0 commit comments