Slide 1

Slide 1 text

LAOUC Community Tour 2024 2 a 23 de Agosto 2024 Terraform for DBAs Implement an Oracle Autonomous Database in minutes with OCI Resource Manager

Slide 2

Slide 2 text

Database Reliability Engineering MAA ⁘ RAC ⁘ RMAN Data Guard ⁘ Sharding ⁘ Partitioning Information Lifecycle Management Exadata & Engineered Systems Database Modernization Upgrades ⁘ Patching ⁘ Migrations Cloud ⁘ Hybrid Automation DevOps ⁘ IaC ⁘ Containers ⁘ Terraform Vagrant ⁘ Ansible Observability AHF ⁘ TFA ⁘ CHA ⁘ CHM

Slide 3

Slide 3 text

www.viscosityna.com @ViscosityNA Oracle on Docker Running Oracle Databases in Linux Containers Free sample chapter: https://oraclesean.com

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

km mi Mexico 3,584 2,227 Guatemala 1,056 656 Costa Rica 854 531 Panama 1,813 1,127 Chile 4,985 3,098 Brazil 2,617 1,626 Uruguay 1,567 974 Argentina 221 137 Paraguay 1,037 644 Home 9,753 6,061 ------ ------ 27,487 17,081 ¡Me gustan los aviones! ¡Me gustas tú! ¡Me gusta viajar! ¡Me gustas tú! ~ Manu Chao

Slide 6

Slide 6 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com Latin "terra" (Earth) English "form" (form) ter•ra•form verb Transform an alien environment to sustain life. www.viscosityna.com @ViscosityNA

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

An Infrastructure as Code (IaC) tool from Hashicorp. Terraform defines, provisions and tracks local and cloud infrastructure. @ViscosityNA www.viscosityna.com Ter•ra•form noun

Slide 14

Slide 14 text

www.viscosityna.com @ViscosityNA A roller coaster is a train with a pulse!

Slide 15

Slide 15 text

www.viscosityna.com @ViscosityNA But is this the experience you want at 2AM?

Slide 16

Slide 16 text

www.viscosityna.com @ViscosityNA Sometimes you just want a boring train ride from point A to point B

Slide 17

Slide 17 text

www.viscosityna.com @ViscosityNA Terraform is like the metro, not a roller coaster Without excitement Without surprises Without thrills

Slide 18

Slide 18 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com Terraform is a declarative language Imperative languages provide instruction Declarative languages define intention

Slide 19

Slide 19 text

@ViscosityNA www.viscosityna.com Building a 10-liter fish tank with imperative language • Get tank A, pump B, heater C... • Set them up... • Add exactly X liters of water... • Add exactly Y grams of salt... • Adjust the temperature to Z °C... • Add specific fish...

Slide 20

Slide 20 text

@ViscosityNA www.viscosityna.com Building a 10-liter fish tank with imperative language • Imperative languages scale poorly: • Changing tank size redefines all assets • Resources have dependencies

Slide 21

Slide 21 text

@ViscosityNA www.viscosityna.com Building a 10-liter fish tank with imperative language • Changes require deep domain experience • Does heater capacity change linearly with water volume? • Does a tall, skinny tank have different requirements than short and wide? • Does surface area affect salt concentration? • Should intermediate values round up or down? • Are salinity ratios fixed according to water volume?

Slide 22

Slide 22 text

@ViscosityNA www.viscosityna.com Building a 10-liter fish tank with declarative language "I want a 10-liter fish tank" @ViscosityNA www.viscosityna.com

Slide 23

Slide 23 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com The expert understands the differences between this:

Slide 24

Slide 24 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com ...and this:

Slide 25

Slide 25 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com In Terraform, that expert is called a provider @ViscosityNA www.viscosityna.com

Slide 26

Slide 26 text

@ViscosityNA www.viscosityna.com Providers are implementation experts • They understand dependencies • They interpret configurations • They build the declared infrastructure Terraform provider

Slide 27

Slide 27 text

@ViscosityNA www.viscosityna.com We tell the provider what we want The provider deploys resources for us Different providers for OCI, Azure, AWS, GCP, etc. Terraform provider

Slide 28

Slide 28 text

@ViscosityNA www.viscosityna.com • Infrastructure objects available to Terraform • Properties defined in the Terraform API • Created and managed by assigning values to properties • Configured via simple text files Terraform resource

Slide 29

Slide 29 text

@ViscosityNA www.viscosityna.com Resources can be: • Physical: compute, storage, network • Dependent: queries against the environment • Dynamic: functions, expressions, loops • Config: security lists, rules, operations • Code: scripts, payloads Terraform resource

Slide 30

Slide 30 text

@ViscosityNA www.viscosityna.com Terraform projects @ViscosityNA • A collection of files for defining infrastructure • Saved under a single directory • Usually managed through version control (GitHub, etc.)

Slide 31

Slide 31 text

@ViscosityNA www.viscosityna.com Start a new Terraform project Create a project directory and create files: • providers.tf • variables.tf • terraform.tfvars • main.tf • outputs.tf @ViscosityNA Project files: https://github.com/oraclesean/terraform-for-oracle-dbas

Slide 32

Slide 32 text

@ViscosityNA www.viscosityna.com @ViscosityNA Everything in one file • main.tf • Can be difficult to maintain Separate files for each resource • Modular and more portable code • compute.tf • storage.tf • variables.tf Terraform project styles

Slide 33

Slide 33 text

@ViscosityNA www.viscosityna.com providers.tf provider "oci" { tenancy_ocid = var.tenancy_ocid region = var.region user_ocid = var.user_ocid fingerprint = var.fingerprint private_key_path = var.private_key_path } Resource variables Value assignments Value assignments could go here

Slide 34

Slide 34 text

@ViscosityNA www.viscosityna.com variables.tf # Terraform tenancy variables variable "tenancy_ocid" {} variable "region" {} variable "user_ocid" {} variable "fingerprint" {} variable "private_key_path" {} Variable declarations Value assignments could go here

Slide 35

Slide 35 text

@ViscosityNA www.viscosityna.com terraform.tfvars # Terraform tenancy variable values tenancy_ocid = Your tenancy_ocid region = Your region identifier user_ocid = Your user_ocid fingerprint = Your fingerprint private_key_path = Your private_key_path The same variables defined in variables.tf Variable assignments go here Assigning variables in the terraform.tfvars means we only need to change a single file to scale the infrastructure, run the same configuration in a different environment, etc.!

Slide 36

Slide 36 text

@ViscosityNA www.viscosityna.com @ViscosityNA www.viscosityna.com variables.tf terraform.tfvars providers.tf etc. Declare Assign Read Understand properties and variable assignments

Slide 37

Slide 37 text

@ViscosityNA www.viscosityna.com Prepare the project • From the project directory, run: terraform init terraform plan terraform apply @ViscosityNA www.viscosityna.com

Slide 38

Slide 38 text

@ViscosityNA www.viscosityna.com terraform init > terraform init Initializing the backend... Initializing provider plugins... - Finding oracle/oci versions matching ">= 4.0.0"... - Installing oracle/oci v6.4.0... - Installed oracle/oci v6.4.0 (signed by a HashiCorp partner, key ID 1533A49284137CEB) Partner and community providers are signed by their developers. If you'd like to know more about provider signing, you can read about it here: https://www.terraform.io/docs/cli/plugins/signing.html Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Include this file in your version control repository so that Terraform can guarantee to make the same selections by default when you run "terraform init" in the future. Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.

Slide 39

Slide 39 text

@ViscosityNA www.viscosityna.com terraform plan > terraform plan No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Slide 40

Slide 40 text

@ViscosityNA www.viscosityna.com terraform apply > terraform apply No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Slide 41

Slide 41 text

@ViscosityNA www.viscosityna.com Add a resource for the Autonomous Database • Add the ADB resource in main.tf • Add the ADB variables to variables.tf • Assign values in terraform.tfvars • Add output variables to output.tf @ViscosityNA

Slide 42

Slide 42 text

@ViscosityNA www.viscosityna.com main.tf # Autonomous database resource resource "oci_database_autonomous_database" "autonomous_db" { compartment_id = var.tenancy_ocid db_name = var.db_name display_name = var.display_name db_version = var.db_version db_workload = var.db_workload cpu_core_count = var.cpu_core_count data_storage_size_in_tbs = var.data_storage_size_in_tbs is_free_tier = var.is_free_tier license_model = var.license_model admin_password = var.admin_password } Type of resource Name assigned to the resource ADB properties Values used to create the ADB

Slide 43

Slide 43 text

@ViscosityNA www.viscosityna.com Add DB variables to variables.tf # Autonomous DB variables variable "db_name" { type = string } variable "display_name" { type = string } variable "admin_password" { type = string } Variable declarations

Slide 44

Slide 44 text

@ViscosityNA www.viscosityna.com Add DB variables to variables.tf variable "db_version" { type = string default = "19c" # Option is 19c } variable "db_workload" { type = string default = "OLTP" # Options are: OLTP, DW, AJD, APEX } Variable declaration block Define the variable type Assign a default value

Slide 45

Slide 45 text

@ViscosityNA www.viscosityna.com Add DB variables to variables.tf variable "cpu_core_count" { type = number default = 1 } variable "data_storage_size_in_tbs" { type = number default = 1 }

Slide 46

Slide 46 text

@ViscosityNA www.viscosityna.com variable "is_free_tier" { type = string default = "true" # Must be false for AJD, APEX } variable "license_model" { type = string default = "LICENSE_INCLUDED" } Add DB variables to variables.tf

Slide 47

Slide 47 text

@ViscosityNA www.viscosityna.com Assign variable values in terraform.tfvars # Autonomous database variable values db_name = "ADB19C" display_name = "ADB19C" admin_password = "XXXXXXXXXXXXXXXXXXXXXX" # Default overrides #db_version = #db_workload = #cpu_core_count = #data_storage_size_in_tbs = #is_free_tier = #license_model = The values most likely to change every time we create a database To override default values uncomment the line and assign a value

Slide 48

Slide 48 text

@ViscosityNA www.viscosityna.com outputs.tf output "db_name" { value = oci_database_autonomous_database.autonomous_db.display_name } output "db_state" { value = oci_database_autonomous_database.autonomous_db.state } resource "oci_database_autonomous_database" "autonomous_db" { compartment_id = var.tenancy_ocid db_name = var.db_name display_name = var.display_name ... }

Slide 49

Slide 49 text

@ViscosityNA www.viscosityna.com Create a database! • Run: terraform plan terraform apply @ViscosityNA www.viscosityna.com

Slide 50

Slide 50 text

@ViscosityNA www.viscosityna.com terraform plan > terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # oci_database_autonomous_database.autonomous_db will be created + resource "oci_database_autonomous_database" "autonomous_db" { + actual_used_data_storage_size_in_tbs = (known after apply) + admin_password = (sensitive value) ...

Slide 51

Slide 51 text

@ViscosityNA www.viscosityna.com terraform plan (continued) ... Plan: 1 to add, 0 to change, 0 to destroy. Changes to Outputs: + db_name = "ADB19C" + db_state = (known after apply) ──────────────────────────────────────────────────────────────────────────── Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.

Slide 52

Slide 52 text

@ViscosityNA www.viscosityna.com terraform apply > terraform apply ... Plan: 1 to add, 0 to change, 0 to destroy. Changes to Outputs: + db_name = "ADB19C" + 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

Slide 53

Slide 53 text

@ViscosityNA www.viscosityna.com ... Enter a value: yes oci_database_autonomous_database.autonomous_db: Creating... oci_database_autonomous_database.autonomous_db: Still creating... [10s elapsed] ... oci_database_autonomous_database.autonomous_db: Creation complete after 1m31s Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: db_name = "ADB19C" db_state = "AVAILABLE" terraform apply (continued)

Slide 54

Slide 54 text

@ViscosityNA www.viscosityna.com How does Terraform help DBAs? @ViscosityNA • Simplifies and speeds database creation • Codifies and standardizes processes • Ensures consistency across environments • Reduces DBA workload • Reduces dependencies/waiting for DBA resources • Accelerates development and innovation

Slide 55

Slide 55 text

www.viscosityna.com @ViscosityNA Questions and contacting me [email protected] https://linktr.ee/oraclesean

Slide 56

Slide 56 text

No content