DBA Hub

📋Steps in this guide1/4

Terraform : Oracle Cloud Infrastructure (OCI) Autonomous Database (ADW, ATP, AJD, APX)

This article describes how to create an autonomous database (ADW, ATP, AJD, APX) on Oracle Cloud Infrastructure (OCI) using Terraform.

oracle miscconfigurationintermediate
by OracleDba
12 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_adb
cd \git\oraclebase\terraform\oci\oci_adb

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

oci_adb.tf

Create a file called "oci_adb.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. The CPUs and storage parameters are defaulted. The resources section defines the autonomous database using the input variables. The outputs section allows us to see information about the autonomous database that's been created, including the name and state. 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 .

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
# Variables
variable "compartment_id" { type = string }
variable "db_name"        { type = string }
variable "admin_password" { type = string }
variable "db_version"     { type = string }
# OLTP, DW, AJD, APEX
variable "db_workload"    { type = string }
# Must be false for AJD and APEX
variable "is_free_tier"   { type = string }
# BRING_YOUR_OWN_LICENSE or LICENSE_INCLUDED
variable "license_model"  { type = string }

variable "cpu_core_count" {
  type    = number
  default = 1
}

variable "data_storage_size_in_tbs" {
  type    = number
  default = 1
}


# Resources
resource "oci_database_autonomous_database" "tf_adb" {
  compartment_id           = var.compartment_id
  cpu_core_count           = var.cpu_core_count
  data_storage_size_in_tbs = var.data_storage_size_in_tbs
  db_name                  = var.db_name
  admin_password           = var.admin_password
  db_version               = var.db_version
  db_workload              = var.db_workload
  display_name             = var.db_name
  is_free_tier             = var.is_free_tier
  license_model            = var.license_model
}


# Outputs
output "db_name" {
  value = oci_database_autonomous_database.tf_adb.display_name
}

output "db_state" {
  value = oci_database_autonomous_database.tf_adb.state
}
3

oci_adb_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_adb_variables.auto.tfvars". The contents will vary depending on the type autonomous database you want to provision. For an autonomous data warehouse (ADW) service you would use something like this. For an autonomous transaction processing (ATP) service you would use something like this. For an autonomous JSON database (AJD) service you would use something like this. For an APEX Developer Instance (APX) service you would use something like this. The is the OCID of the compartment that will house the autonomous database. 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
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
compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
db_name        = "obadw2"
admin_password = "MyStrongPassword123"
db_version     = "21c"
# OLTP, DW, AJD, APEX
db_workload    = "DW"
# Must be false for AJD and APEX
is_free_tier   = "true"
license_model  = "LICENSE_INCLUDED"

compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
db_name        = "obatp2"
admin_password = "MyStrongPassword123"
db_version     = "21c"
# OLTP, DW, AJD, APEX
db_workload    = "OLTP"
# Must be false for AJD and APEX
is_free_tier   = "true"
license_model  = "LICENSE_INCLUDED"

compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
db_name        = "obajd2"
admin_password = "MyStrongPassword123"
db_version     = "19c"
# OLTP, DW, AJD, APEX
db_workload    = "AJD"
# Must be false for AJD and APEX
is_free_tier   = "false"
license_model  = "LICENSE_INCLUDED"

compartment_id = "ocid1.compartment.oc1..aaaaaaaa..."
db_name        = "obapx2"
admin_password = "MyStrongPassword123"
db_version     = "19c"
# OLTP, DW, AJD, APEX
db_workload    = "APEX"
# Must be false for AJD and APEX
is_free_tier   = "false"
license_model  = "LICENSE_INCLUDED"
4

Build the OCI Autonomous Database

Initialize the working directory using the command. Use the command to test the execution plan. Use the command to create the OCI autonomous database. Check the Oracle Cloud account to see the new autonomous database in the compartment you chose. For more information see: - oci_database_autonomous_database - 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
terraform init

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

Terraform will perform the following actions:

  # oci_database_autonomous_database.tf_adb will be created
  + resource "oci_database_autonomous_database" "tf_adb" {
      + admin_password                                 = (sensitive value)
      + apex_details                                   = (known after apply)
      + are_primary_whitelisted_ips_used               = (known after apply)
      + autonomous_container_database_id               = (known after apply)
      + autonomous_database_backup_id                  = (known after apply)
      + autonomous_database_id                         = (known after apply)
      + available_upgrade_versions                     = (known after apply)
      + backup_config                                  = (known after apply)
      + clone_type                                     = (known after apply)
      + compartment_id                                 = "ocid1.compartment.oc1..aaaaaaaa..."
      + connection_strings                             = (known after apply)
      + connection_urls                                = (known after apply)
      + cpu_core_count                                 = 1
      + data_safe_status                               = (known after apply)
      + data_storage_size_in_gb                        = (known after apply)
      + data_storage_size_in_tbs                       = 1
      + db_name                                        = "obadw2"
      + db_version                                     = "21c"
      + db_workload                                    = "DW"
      + defined_tags                                   = (known after apply)
      + display_name                                   = "obadw2"
      + failed_data_recovery_in_seconds                = (known after apply)
      + freeform_tags                                  = (known after apply)
      + id                                             = (known after apply)
      + infrastructure_type                            = (known after apply)
      + is_access_control_enabled                      = (known after apply)
      + is_auto_scaling_enabled                        = (known after apply)
      + is_data_guard_enabled                          = (known after apply)
      + is_dedicated                                   = (known after apply)
      + is_free_tier                                   = true
      + is_preview                                     = (known after apply)
      + is_preview_version_with_service_terms_accepted = (known after apply)
      + is_refreshable_clone                           = (known after apply)
      + key_store_id                                   = (known after apply)
      + key_store_wallet_name                          = (known after apply)
      + license_model                                  = "LICENSE_INCLUDED"
      + lifecycle_details                              = (known after apply)
      + nsg_ids                                        = (known after apply)
      + open_mode                                      = (known after apply)
      + operations_insights_status                     = (known after apply)
      + permission_level                               = (known after apply)
      + private_endpoint                               = (known after apply)
      + private_endpoint_ip                            = (known after apply)
      + private_endpoint_label                         = (known after apply)
      + refreshable_mode                               = (known after apply)
      + refreshable_status                             = (known after apply)
      + role                                           = (known after apply)
      + service_console_url                            = (known after apply)
      + source                                         = (known after apply)
      + source_id                                      = (known after apply)
      + standby_db                                     = (known after apply)
      + standby_whitelisted_ips                        = (known after apply)
      + state                                          = (known after apply)
      + subnet_id                                      = (known after apply)
      + system_tags                                    = (known after apply)
      + time_created                                   = (known after apply)
      + time_deletion_of_free_autonomous_database      = (known after apply)
      + time_maintenance_begin                         = (known after apply)
      + time_maintenance_end                           = (known after apply)
      + time_of_last_failover                          = (known after apply)
      + time_of_last_refresh                           = (known after apply)
      + time_of_last_refresh_point                     = (known after apply)
      + time_of_last_switchover                        = (known after apply)
      + time_of_next_refresh                           = (known after apply)
      + time_reclamation_of_free_autonomous_database   = (known after apply)
      + timestamp                                      = (known after apply)
      + used_data_storage_size_in_tbs                  = (known after apply)
    }

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

Changes to Outputs:
  + db_name  = "obadw2"
  + db_state = (known after apply)

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

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.

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

Terraform will perform the following actions:

  # oci_database_autonomous_database.tf_adb will be created
  + resource "oci_database_autonomous_database" "tf_adb" {
      + admin_password                                 = (sensitive value)
      + apex_details                                   = (known after apply)
      + are_primary_whitelisted_ips_used               = (known after apply)
      + autonomous_container_database_id               = (known after apply)
      + autonomous_database_backup_id                  = (known after apply)
      + autonomous_database_id                         = (known after apply)
      + available_upgrade_versions                     = (known after apply)
      + backup_config                                  = (known after apply)
      + clone_type                                     = (known after apply)
      + compartment_id                                 = "ocid1.compartment.oc1..aaaaaaaa..."
      + connection_strings                             = (known after apply)
      + connection_urls                                = (known after apply)
      + cpu_core_count                                 = 1
      + data_safe_status                               = (known after apply)
      + data_storage_size_in_gb                        = (known after apply)
      + data_storage_size_in_tbs                       = 1
      + db_name                                        = "obadw2"
      + db_version                                     = "21c"
      + db_workload                                    = "DW"
      + defined_tags                                   = (known after apply)
      + display_name                                   = "obadw2"
      + failed_data_recovery_in_seconds                = (known after apply)
      + freeform_tags                                  = (known after apply)
      + id                                             = (known after apply)
      + infrastructure_type                            = (known after apply)
      + is_access_control_enabled                      = (known after apply)
      + is_auto_scaling_enabled                        = (known after apply)
      + is_data_guard_enabled                          = (known after apply)
      + is_dedicated                                   = (known after apply)
      + is_free_tier                                   = true
      + is_preview                                     = (known after apply)
      + is_preview_version_with_service_terms_accepted = (known after apply)
      + is_refreshable_clone                           = (known after apply)
      + key_store_id                                   = (known after apply)
      + key_store_wallet_name                          = (known after apply)
      + license_model                                  = "LICENSE_INCLUDED"
      + lifecycle_details                              = (known after apply)
      + nsg_ids                                        = (known after apply)
      + open_mode                                      = (known after apply)
      + operations_insights_status                     = (known after apply)
      + permission_level                               = (known after apply)
      + private_endpoint                               = (known after apply)
      + private_endpoint_ip                            = (known after apply)
      + private_endpoint_label                         = (known after apply)
      + refreshable_mode                               = (known after apply)
      + refreshable_status                             = (known after apply)
      + role                                           = (known after apply)
      + service_console_url                            = (known after apply)
      + source                                         = (known after apply)
      + source_id                                      = (known after apply)
      + standby_db                                     = (known after apply)
      + standby_whitelisted_ips                        = (known after apply)
      + state                                          = (known after apply)
      + subnet_id                                      = (known after apply)
      + system_tags                                    = (known after apply)
      + time_created                                   = (known after apply)
      + time_deletion_of_free_autonomous_database      = (known after apply)
      + time_maintenance_begin                         = (known after apply)
      + time_maintenance_end                           = (known after apply)
      + time_of_last_failover                          = (known after apply)
      + time_of_last_refresh                           = (known after apply)
      + time_of_last_refresh_point                     = (known after apply)
      + time_of_last_switchover                        = (known after apply)
      + time_of_next_refresh                           = (known after apply)
      + time_reclamation_of_free_autonomous_database   = (known after apply)
      + timestamp                                      = (known after apply)
      + used_data_storage_size_in_tbs                  = (known after apply)
    }

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

Changes to Outputs:
  + db_name  = "obadw2"
  + db_state = (known after apply)

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

oci_database_autonomous_database.tf_adb: Creating...
oci_database_autonomous_database.tf_adb: Still creating... [10s elapsed]
oci_database_autonomous_database.tf_adb: Still creating... [20s elapsed]
oci_database_autonomous_database.tf_adb: Still creating... [30s elapsed]
oci_database_autonomous_database.tf_adb: Still creating... [40s elapsed]
oci_database_autonomous_database.tf_adb: Still creating... [50s elapsed]
oci_database_autonomous_database.tf_adb: Still creating... [1m0s elapsed]
oci_database_autonomous_database.tf_adb: Creation complete after 1m8s [id=ocid1.autonomousdatabase.oc1.uk-london-1....]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

db_name = "obadw2"
db_state = "AVAILABLE"

Comments (0)

Please to add comments

No comments yet. Be the first to comment!