SlideShare a Scribd company logo
Mastering Terraform and
the OCI provider
#OracleCode AND @gregoryguillou
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
@gregoryguillou
gregoryguillou
Ops with an angle
#OracleCode AND @gregoryguillou
Mastering Terraform and the Provider for OCI
● Self-service and Chatops
● Elasticity: Training, dev, test
● International deployment
● Ability to invest to add value
● Time to Market
● Impact on all our teams
● Number of environments
● Mission critical “Ops”
Why Ops also live for the code?
● We need monitoring, CI/CD, AB testing, DRP
● We need to move faster and faster
● People should not need us!
● Let’s stop building from the ground
● Focus on products and businesses, not infrastructure
● Ops are deadly alive!
#OracleCode AND @gregoryguillou
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
Mastering Terraform and the Provider for OCI
Terraform Key concepts - https://terraform.io
● Infrastructure as Code
● A go application
● HCL/JSON with an inference syntax
● Immutable Infrastructure
● State management
● Dozens of providers, including OCI
● GIT and Registry
● Open-source and enterprise versions
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
gregoryguillou/oci-workshop
Should I explain
OCI ?
Installing Terraform for OCI (master)
● Download the software from terraform.io
● Install terraform OCI provider
● Install the OCI Command Line Interface
● Create a RSA key and register it in your API Keys
● Defines your OCI CLI configuration
● Create a provider.tf file and set the associated variables
● Initialize the project with the `init` command
● Define resources and `apply` them
OCI Terraform resource overview
● Core: Images, Instances, Volumes, VCN, Security List,
Subnets...
● Database
● DNS: Records, Zones
● File Storage
● Identity: Keys, Groups, Policies, Users
● Load Balancer
● Object Storage Checkout the documentation
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
A few coding good practices
● Create a specific compartment (master)
● Manage your state on a bucket (02-demo)
● Variables, inferences and dependencies (03-demo)
● Modules (04-demo)
● Packer (05-demo)
● dynamicgroups and OCI_CLI_AUTH (06-demo)
● Use other providers (07-demo)
● An easy (and bad) way to manage secrets (08-demo)
Create a specific compartment (master)
● Use OCI CLI to create a compartment
● Add it to the .env file and with variables Checkout 01-install.md
oci iam compartment create 
--compartment-id="${TF_VAR_tenancy}" 
--name="DevTeam" 
--description="A compartiment to be used by developers" 
--wait-for-state=ACTIVE 
--max-wait-seconds=300 
--wait-interval-seconds 5
Manage your state on a bucket (02-demo)
● Create a bucket
● Upload the current state as an object in that bucket
● Create a pre-authenticated request for that object
● Test you can access the file from the request
● Add a backend.tf file that reference the preauth request
● Re-initialize terraform with the backend
● Verify you can access the remote state
Checkout 02-remote-state.md
Variables, inferences and dependencies (03-demo)
● Add access to the `compartment` variable
● Create a variable with a default value
● Infer variable value from another variable with `lookup`
● Create a VCN, DCHP Options and an Internet Gateway
● Create multiple resource and inferences with `count`
Checkout 03-inferences.md
Modules (04-demo)
● Create a directory to move the resource for your module
● Remove the resource from your original stack
● Create variable and output to encapsulate your logic
● Use `terraform init` to reference the new module
Checkout 04-modules.md
module "livecode" {
tenancy = "${var.tenancy}"
compartment = "${var.compartment}"
source = "github.com/gregoryguillou/oci-workshop?ref=04-demo//modules/public-network"
}
Packer (05-demo)
● Installing Packer
● Finding the latest Oracle Linux Image
● Subnet and Compartment
● Building an OCI image with Packer
Checkout 05-packer.md
packer build -var "subnet=$SUBNET" 
-var "compartment=$TF_VAR_compartment" 
template.json
dynamicgroups and OCI_CLI_AUTH (06-demo)
● Deploy a dynamic group and its policy
● Access the remote instance from SSH
● Use the metadata API to figure out the compartment
● Use the OCI CLI without any credentials
Checkout 06-dynamicgroups.md
export OCI_CLI_AUTH=instance_principal
oci os bucket list --compartment-id=$COMPARTMENT 
--query='data[].{bucket: name}' --output=table
Use other providers (07-demo)
● There are a lot of useful providers, including random, null,
http, external, template or terraform_remote, for instance:
● You can use many more: kubernetes, consul, vault...
Checkout 07-other-providers.md
data "external" "version" {
program = ["${path.module}/version.sh"]
query = {
workspace = "${terraform.workspace}"
}
}
output "oci-workshop" {
value = "${lookup(data.external.version.result, "oci-workshop")}"
}
#OracleCode AND @gregoryguillou
An easy and bad way to manage secrets (08-demo)
● Rely on Hashicorp Vault for a best configuration:
○ Automatic password rotation
○ Access token expiration
○ Emergency process
● An easy way to manage secrets is to store them in a
bucket:
○ Easy to push/pull new values
○ Dynamic Groups make it easy to get back from an instance
Checkout 08-secrets.md
Destroy your stack (08-demo)
Checkout 08-secrets.md
oci os object delete 
--bucket-name=ftclnpb3wrytejru.resetlogs.com 
--name=/configuration/secret/secret.json 
--force
terraform destroy
…
● Destroy the stack as part of the last part:
Random thoughts
● KISS and DRY
○ Use as few external tools as possible
○ Avoid provisioners and null_resource
● Add +1 to tag support for Terraform OCI provider #400
● Add +1 to support the container registry and OKE
● Don’t use terraform for Windows
● Rely on LetsEncrypt/DNS to generate SSL certificates
● Use Kubernetes (OKE) and a CI/CD for your application
● Implement Chatops and self-service
Agenda
Mastering Terraform with OCI
● Introduction
● Terraform fundamentals
● Terraform OCI provider
● Coding and good practices
● Summary
Summary
● Terraform is easy to use, quick to learn and popular
● OCI is a powerful and fast infrastructure
● The terraform-provider-oci leverage both OCI and TF
● The workshop explores many aspects: configuration,
compartment, state, inference, modules, templates,
dynamic groups, providers…
● Try the oci-workshop, provide feedback and open issues
● OCI gets more advanced tools like DCS, OKE
gregoryguillou/terraform-api
gregoryguillou/hubot-terraform
Another demo: terraform from slack...
Thank you !!!
We are hiring...

More Related Content

PDF
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
PDF
Terraform with OCI
PPTX
Oracle OCI APIs and SDK
PPTX
Cloud Foundry Deployment Tools: BOSH vs Juju Charms
PDF
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
PDF
Extending TripleO for OpenStack Management
PDF
Configuration Management Tools on NX-OS
PPTX
Terraform day 1
Terraform 0.12 Deep Dive: HCL 2.0 for Infrastructure as Code, Remote Plan & A...
Terraform with OCI
Oracle OCI APIs and SDK
Cloud Foundry Deployment Tools: BOSH vs Juju Charms
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
Extending TripleO for OpenStack Management
Configuration Management Tools on NX-OS
Terraform day 1

What's hot (20)

PPTX
Galera on kubernetes_no_video
PPTX
Core os dna_oscon
PDF
CoreOS automated MySQL Cluster Failover using Galera Cluster
PDF
Red Hat OpenShift Operators - Operators ABC
PDF
Fuel, Puppet and OpenStack
PDF
Git ops & Continuous Infrastructure with terra*
PDF
[OpenStack Day in Korea 2015] Track 1 - Triple O를 이용한 빠르고 쉬운 OpenStack 설치
PDF
Red Hat Forum Benelux 2015
PDF
Terraform -- Infrastructure as Code
PDF
Terraform 101
PDF
Oracle on kubernetes 101 - Dec/2021
PDF
CAPS: What's best for deploying and managing OpenStack? Chef vs. Ansible vs. ...
ODP
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
PPTX
OpenStack Heat
PPTX
Core os dna_automacon
PDF
[Alibaba Cloud Singapore Community Meetup Webinar, 3 Sep 2020] Automate Your ...
PDF
Run your Java apps on Cloud Foundry
PDF
OpenStack + Cloud Foundry for the OpenStack Boston Meetup
PDF
Deploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
PDF
Containers - Portable, repeatable user-oriented application delivery. Build, ...
Galera on kubernetes_no_video
Core os dna_oscon
CoreOS automated MySQL Cluster Failover using Galera Cluster
Red Hat OpenShift Operators - Operators ABC
Fuel, Puppet and OpenStack
Git ops & Continuous Infrastructure with terra*
[OpenStack Day in Korea 2015] Track 1 - Triple O를 이용한 빠르고 쉬운 OpenStack 설치
Red Hat Forum Benelux 2015
Terraform -- Infrastructure as Code
Terraform 101
Oracle on kubernetes 101 - Dec/2021
CAPS: What's best for deploying and managing OpenStack? Chef vs. Ansible vs. ...
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
OpenStack Heat
Core os dna_automacon
[Alibaba Cloud Singapore Community Meetup Webinar, 3 Sep 2020] Automate Your ...
Run your Java apps on Cloud Foundry
OpenStack + Cloud Foundry for the OpenStack Boston Meetup
Deploy Prometheus - Grafana and EFK stack on Kubic k8s Clusters
Containers - Portable, repeatable user-oriented application delivery. Build, ...
Ad

Similar to Mastering Terraform and the Provider for OCI (20)

PDF
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
PDF
Oracle Cloud deployment with Terraform
PPTX
Terraform & Oracle Cloud Infrastructure
PDF
OracleBeer_Terraform_soe.pdf
PDF
Getting Started with Terraform
PDF
Better Practices when Using Terraform to Manage Oracle Cloud Infrastructure
PPTX
Terraform: Taming the Machines Through Continuous Integration
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
PDF
Terraform-2.pdf
PPTX
Terraform Abstractions for Safety and Power
PPTX
Terraform
PDF
Infrastructure as Code with Terraform
PDF
Instant download Terraform in Depth (MEAP V01) Robert Hafner pdf all chapter
PPTX
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
PPTX
Part 5 of the REAL Webinars on Oracle Cloud Native Application Development - ...
PDF
Best Practices of Infrastructure as Code with Terraform
PDF
Terraform Interview Questions By Scholarhat.pdf
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
PDF
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
PDF
Terraform introduction
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
Oracle Cloud deployment with Terraform
Terraform & Oracle Cloud Infrastructure
OracleBeer_Terraform_soe.pdf
Getting Started with Terraform
Better Practices when Using Terraform to Manage Oracle Cloud Infrastructure
Terraform: Taming the Machines Through Continuous Integration
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Terraform-2.pdf
Terraform Abstractions for Safety and Power
Terraform
Infrastructure as Code with Terraform
Instant download Terraform in Depth (MEAP V01) Robert Hafner pdf all chapter
Infrastructure-as-Code (IaC) Using Terraform (Intermediate Edition)
Part 5 of the REAL Webinars on Oracle Cloud Native Application Development - ...
Best Practices of Infrastructure as Code with Terraform
Terraform Interview Questions By Scholarhat.pdf
"Continuously delivering infrastructure using Terraform and Packer" training ...
GDG Cloud Southlake #8 Steve Cravens: Infrastructure as-Code (IaC) in 2022: ...
Terraform introduction
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Mushroom cultivation and it's methods.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
cloud_computing_Infrastucture_as_cloud_p
A comparative analysis of optical character recognition models for extracting...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Group 1 Presentation -Planning and Decision Making .pptx
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
SOPHOS-XG Firewall Administrator PPT.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
OMC Textile Division Presentation 2021.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Mushroom cultivation and it's methods.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf

Mastering Terraform and the Provider for OCI

  • 1. Mastering Terraform and the OCI provider #OracleCode AND @gregoryguillou
  • 2. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 3. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 4. @gregoryguillou gregoryguillou Ops with an angle #OracleCode AND @gregoryguillou
  • 6. ● Self-service and Chatops ● Elasticity: Training, dev, test ● International deployment ● Ability to invest to add value ● Time to Market ● Impact on all our teams ● Number of environments ● Mission critical “Ops”
  • 7. Why Ops also live for the code? ● We need monitoring, CI/CD, AB testing, DRP ● We need to move faster and faster ● People should not need us! ● Let’s stop building from the ground ● Focus on products and businesses, not infrastructure ● Ops are deadly alive! #OracleCode AND @gregoryguillou
  • 8. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 10. Terraform Key concepts - https://terraform.io ● Infrastructure as Code ● A go application ● HCL/JSON with an inference syntax ● Immutable Infrastructure ● State management ● Dozens of providers, including OCI ● GIT and Registry ● Open-source and enterprise versions
  • 11. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 14. Installing Terraform for OCI (master) ● Download the software from terraform.io ● Install terraform OCI provider ● Install the OCI Command Line Interface ● Create a RSA key and register it in your API Keys ● Defines your OCI CLI configuration ● Create a provider.tf file and set the associated variables ● Initialize the project with the `init` command ● Define resources and `apply` them
  • 15. OCI Terraform resource overview ● Core: Images, Instances, Volumes, VCN, Security List, Subnets... ● Database ● DNS: Records, Zones ● File Storage ● Identity: Keys, Groups, Policies, Users ● Load Balancer ● Object Storage Checkout the documentation
  • 16. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 17. A few coding good practices ● Create a specific compartment (master) ● Manage your state on a bucket (02-demo) ● Variables, inferences and dependencies (03-demo) ● Modules (04-demo) ● Packer (05-demo) ● dynamicgroups and OCI_CLI_AUTH (06-demo) ● Use other providers (07-demo) ● An easy (and bad) way to manage secrets (08-demo)
  • 18. Create a specific compartment (master) ● Use OCI CLI to create a compartment ● Add it to the .env file and with variables Checkout 01-install.md oci iam compartment create --compartment-id="${TF_VAR_tenancy}" --name="DevTeam" --description="A compartiment to be used by developers" --wait-for-state=ACTIVE --max-wait-seconds=300 --wait-interval-seconds 5
  • 19. Manage your state on a bucket (02-demo) ● Create a bucket ● Upload the current state as an object in that bucket ● Create a pre-authenticated request for that object ● Test you can access the file from the request ● Add a backend.tf file that reference the preauth request ● Re-initialize terraform with the backend ● Verify you can access the remote state Checkout 02-remote-state.md
  • 20. Variables, inferences and dependencies (03-demo) ● Add access to the `compartment` variable ● Create a variable with a default value ● Infer variable value from another variable with `lookup` ● Create a VCN, DCHP Options and an Internet Gateway ● Create multiple resource and inferences with `count` Checkout 03-inferences.md
  • 21. Modules (04-demo) ● Create a directory to move the resource for your module ● Remove the resource from your original stack ● Create variable and output to encapsulate your logic ● Use `terraform init` to reference the new module Checkout 04-modules.md module "livecode" { tenancy = "${var.tenancy}" compartment = "${var.compartment}" source = "github.com/gregoryguillou/oci-workshop?ref=04-demo//modules/public-network" }
  • 22. Packer (05-demo) ● Installing Packer ● Finding the latest Oracle Linux Image ● Subnet and Compartment ● Building an OCI image with Packer Checkout 05-packer.md packer build -var "subnet=$SUBNET" -var "compartment=$TF_VAR_compartment" template.json
  • 23. dynamicgroups and OCI_CLI_AUTH (06-demo) ● Deploy a dynamic group and its policy ● Access the remote instance from SSH ● Use the metadata API to figure out the compartment ● Use the OCI CLI without any credentials Checkout 06-dynamicgroups.md export OCI_CLI_AUTH=instance_principal oci os bucket list --compartment-id=$COMPARTMENT --query='data[].{bucket: name}' --output=table
  • 24. Use other providers (07-demo) ● There are a lot of useful providers, including random, null, http, external, template or terraform_remote, for instance: ● You can use many more: kubernetes, consul, vault... Checkout 07-other-providers.md data "external" "version" { program = ["${path.module}/version.sh"] query = { workspace = "${terraform.workspace}" } } output "oci-workshop" { value = "${lookup(data.external.version.result, "oci-workshop")}" } #OracleCode AND @gregoryguillou
  • 25. An easy and bad way to manage secrets (08-demo) ● Rely on Hashicorp Vault for a best configuration: ○ Automatic password rotation ○ Access token expiration ○ Emergency process ● An easy way to manage secrets is to store them in a bucket: ○ Easy to push/pull new values ○ Dynamic Groups make it easy to get back from an instance Checkout 08-secrets.md
  • 26. Destroy your stack (08-demo) Checkout 08-secrets.md oci os object delete --bucket-name=ftclnpb3wrytejru.resetlogs.com --name=/configuration/secret/secret.json --force terraform destroy … ● Destroy the stack as part of the last part:
  • 27. Random thoughts ● KISS and DRY ○ Use as few external tools as possible ○ Avoid provisioners and null_resource ● Add +1 to tag support for Terraform OCI provider #400 ● Add +1 to support the container registry and OKE ● Don’t use terraform for Windows ● Rely on LetsEncrypt/DNS to generate SSL certificates ● Use Kubernetes (OKE) and a CI/CD for your application ● Implement Chatops and self-service
  • 28. Agenda Mastering Terraform with OCI ● Introduction ● Terraform fundamentals ● Terraform OCI provider ● Coding and good practices ● Summary
  • 29. Summary ● Terraform is easy to use, quick to learn and popular ● OCI is a powerful and fast infrastructure ● The terraform-provider-oci leverage both OCI and TF ● The workshop explores many aspects: configuration, compartment, state, inference, modules, templates, dynamic groups, providers… ● Try the oci-workshop, provide feedback and open issues ● OCI gets more advanced tools like DCS, OKE
  • 31. Thank you !!! We are hiring...