Skip to content

Commit a09f2a5

Browse files
committed
Add oci_compute.
1 parent e989d1a commit a09f2a5

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

oci/oci_compute/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Terraform : Oracle Cloud Infrastructure (OCI) Compute Instance
2+
3+
Usage description.
4+
5+
* [Terraform : Oracle Cloud Infrastructure (OCI) Compute Instance](https://oracle-base.com/articles/misc/terraform-oci-compute-instance).
6+
7+
Related articles.
8+
9+
* [Terraform : All Articles](https://oracle-base.com/articles/misc/articles-misc#terraform)

oci/oci_compute/oci_compute.tf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Variables
2+
variable "compartment_id" { type = string }
3+
variable "compute_name" { type = string }
4+
variable "compute_subnet_id" { type = string }
5+
variable "compute_image_id" { type = string }
6+
variable "compute_ssh_authorized_keys" { type = string }
7+
8+
variable "compute_shape" {
9+
type = string
10+
default = "VM.Standard.E2.1.Micro"
11+
}
12+
13+
variable "compute_cpus" {
14+
type = string
15+
default = "1"
16+
}
17+
18+
variable "compute_memory_in_gbs" {
19+
type = string
20+
default = "1"
21+
}
22+
23+
24+
# Resources
25+
data "oci_identity_availability_domains" "ads" {
26+
compartment_id = var.compartment_id
27+
}
28+
29+
resource "oci_core_instance" "tf_compute" {
30+
# Required
31+
availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
32+
compartment_id = var.compartment_id
33+
shape = var.compute_shape
34+
35+
source_details {
36+
source_id = var.compute_image_id
37+
source_type = "image"
38+
}
39+
40+
# Optional
41+
display_name = var.compute_name
42+
43+
shape_config {
44+
ocpus = var.compute_cpus
45+
memory_in_gbs = var.compute_memory_in_gbs
46+
}
47+
48+
create_vnic_details {
49+
subnet_id = var.compute_subnet_id
50+
assign_public_ip = true
51+
}
52+
53+
metadata = {
54+
ssh_authorized_keys = file(var.compute_ssh_authorized_keys)
55+
}
56+
57+
preserve_boot_volume = false
58+
}
59+
60+
61+
# Outputs
62+
output "compute_id" {
63+
value = oci_core_instance.tf_compute.id
64+
}
65+
66+
output "db_state" {
67+
value = oci_core_instance.tf_compute.state
68+
}
69+
70+
output "compute_public_ip" {
71+
value = oci_core_instance.tf_compute.public_ip
72+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
2+
compute_shape = "VM.Standard.E2.1.Micro"
3+
compute_name = "obvm1"
4+
compute_subnet_id = "ocid1.subnet.oc1.uk-london-1.aaaaaaaa..."
5+
compute_image_id = "ocid1.image.oc1.uk-london-1.aaaaaaaa..."
6+
compute_ssh_authorized_keys = "./myOracleCloudKey.pub"

oci/oci_compute/oci_provider.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Variables.
2+
variable "tenancy_ocid" { type = string }
3+
variable "user_ocid" { type = string }
4+
variable "private_key_path" { type = string }
5+
variable "fingerprint" { type = string }
6+
variable "region" { type = string }
7+
variable "root_compartment_id" { type = string }
8+
9+
10+
# Resources
11+
provider "oci" {
12+
tenancy_ocid = var.tenancy_ocid
13+
user_ocid = var.user_ocid
14+
private_key_path = var.private_key_path
15+
fingerprint = var.fingerprint
16+
region = var.region
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Amend with your details.
2+
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa..."
3+
user_ocid = "ocid1.user.oc1..aaaaaaaa..."
4+
private_key_path = "/path-to-my/.oci/my-oci-key.pem"
5+
fingerprint = "a5:68:0f:46:6d:06:43:5a:38:98:74:??:??:??:??:??"
6+
region = "uk-london-1"
7+
root_compartment_id = "ocid1.tenancy.oc1..aaaaaaaa..."

0 commit comments

Comments
 (0)