DBA Hub

📋Steps in this guide1/4

Terraform : Oracle Cloud Infrastructure (OCI) General Information

This article describes how to display some commonly used information from Oracle Cloud Infrastructure (OCI), needed when using Terraform.

oracle miscconfigurationintermediate
by OracleDba
15 views
1

Create Working Directory

Create a new working directory and switch to that directory. In a previous article ( here ) we discussed the creation of an OCI provider. Copy the OCI provider information into this new working directory.

Code/Command (click line numbers to comment):

1
2
3
4
5
mkdir \git\oraclebase\terraform\oci\oci_general_info
cd \git\oraclebase\terraform\oci\oci_general_info

copy \git\oraclebase\terraform\oci\oci_provider\*.tf .
copy \git\oraclebase\terraform\oci\oci_provider\*.tfvars .
2

oci_general_info.tf

Create a file called "oci_compute.tf" with the following contents. The file begins with variable definitions. We could set default values for these variables, or use literal values directly in the provider definition, but we don't want sensitive information checked into version control, so it makes sense to separate out variable values from the script. Many of the parameters are defaulted. The resources section defines availability domains, images and shapes using the input variables. The outputs section allows us to see information about the availability domains, images and shapes. The variables, resources and outputs sections can be split into separate files if you find that organisation easier. It may help for more complex definitions. The full list of parameters and outputs available can be found here. - oci_identity_availability_domains - oci_core_images - oci_core_shapes

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Variables
variable "compartment_id" { type = string }

variable "operating_system" { 
  type    = string
  default = "Oracle Linux"
}

variable "operating_system_version" { 
  type    = string
  default = "8"
}

variable "shape" { 
  type    = string
  default = "VM.Standard.E2.1.Micro"
}


# Resources
data "oci_identity_availability_domains" "ads" {
  compartment_id = var.compartment_id
}

data "oci_core_images" "tf_images" {
  compartment_id           = var.compartment_id
  operating_system         = var.operating_system
  operating_system_version = var.operating_system_version
  shape                    = var.shape
}

data "oci_core_shapes" "tf_shapes" {
  compartment_id      = var.compartment_id
  image_id            = data.oci_core_images.tf_images.images.0.id
}


# Outputs
output "first_availability_domain_name" {
  value = data.oci_identity_availability_domains.ads.availability_domains[0].name
}

output "availability_domain_names" {
  value = data.oci_identity_availability_domains.ads.availability_domains[*].name
}

output "latest_image_id" {
  value = data.oci_core_images.tf_images.images[0].id
}

output "shape_names" {
  value = data.oci_core_shapes.tf_shapes.shapes[*].name
}
3

oci_general_info_variables.auto.tfvars

There are a number of ways to supply values for input variables ( see here ). In this example we'll use a ".auto.tfvars" file. We won't check this script into version control as it contains sensitive information. Create a file called "oci_general_info_variables.auto.tfvars". The is the OCID of the compartment that will house the resources you are planning to build. You must adjust it with a valid value from your Oracle Cloud account. You would not normally use the root compartment for this. You can get the ID of a compartment from your Oracle Cloud account as follows. - Top-Left Hamburger > Identity > Compartments - Click on the compartment of interest. - Click the "Copy" link next to "OCID".

Code/Command (click line numbers to comment):

1
2
3
4
5
# Amend with your details.
compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
operating_system         = "Oracle Linux"
operating_system_version = "8"
shape                    = "VM.Standard.E2.1.Micro"
4

Display the OCI General Information

Initialize the working directory using the command. Use the command to display the general information. The output shows the availability domains for the compartment, latest image for the specified operating system in the compartment, and the shapes available for the operating system in the compartment. For more information see: - oci_identity_availability_domains - oci_core_images - oci_core_shapes - Terraform : All Articles Hope this helps. Regards Tim...

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
terraform init

terraform plan
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + availability_domain_names      = [
      + "oVQK:UK-LONDON-1-AD-1",
      + "oVQK:UK-LONDON-1-AD-2",
      + "oVQK:UK-LONDON-1-AD-3",
    ]
  + first_availability_domain_name = "oVQK:UK-LONDON-1-AD-1"
  + latest_image_id                = "ocid1.image.oc1.uk-london-1.aaaaaaaa..."
  + shape_names                    = [
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard.E2.1.Micro",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
      + "BM.Standard2.52",
      + "BM.Standard.E3.128",
      + "BM.Standard.E2.64",
      + "BM.Standard1.36",
      + "VM.Standard.E3.Flex",
      + "VM.Standard2.1",
      + "VM.Standard2.2",
      + "VM.Standard2.4",
      + "VM.Standard2.8",
      + "VM.Standard2.16",
      + "VM.Standard2.24",
      + "VM.Standard.E2.1",
      + "VM.Standard.E2.2",
      + "VM.Standard.E2.4",
      + "VM.Standard.E2.8",
      + "VM.Standard1.1",
      + "VM.Standard1.2",
      + "VM.Standard1.4",
      + "VM.Standard1.8",
      + "VM.Standard1.16",
    ]

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Comments (0)

Please to add comments

No comments yet. Be the first to comment!