Focus sentinelFocus sentinel
Something went wrong
Focus sentinelFocus sentinel
IBM Cloud Databases Terraform
Let's get your IBM Cloud Databases Terraform up and running
Prerequisite
Terraform CLI installed
If you don't have it installed yet, follow the steps at the Terraform installation tutorial
1
Create or retrieve an IBM Cloud API key
The API key is used to authenticate with the IBM Cloud platform and to determine your permissions for IBM Cloud services.
2
Create a new folder with a Terraform file
You can use the terminal, Visual Studio Code or any equivalent tool to:
- Create a new directory on your machine called:
- Create a new Terraform file in this directory called:
Automate provisioning by setting up your configuration file
1
Edit Terraform configuration file
Add the following snippet into theAPI keywith the one previously created.
configuration file you just created. Replace theterraform {
required_providers {
ibm = {
version = ">= 1.12.0"
source = "IBM-Cloud/ibm"
}
}
}
# Configure the IBM Provider
provider "ibm" {
region = "us-south"
ibmcloud_api_key = "<YOUR API KEY>"
}
# Configure the resource group
data "ibm_resource_group" "db_default" {
is_default = true
}
# Create database
resource "ibm_database" "postgresql_db" {
resource_group_id = data.ibm_resource_group.db_default.id
name = "test-postgresql"
service = "databases-for-postgresql"
plan = "standard"
location = "us-south"
service_endpoints = "public"
group {
group_id = "member"
host_flavor {
id = "multitenant"
}
cpu {
allocation_count = 0
}
memory {
allocation_mb = 4096
}
disk {
allocation_mb = 5120
}
}
}
2
Get Terraform ready and create your database
Open your local terminal and navigate to the recently created
directory that has the file in it.Launch Terraform
$ terraform init
Get a list of actions what is going to be deployed
$ terraform plan
Run this command to provision the database
$ terraform apply
It might take some time to provision your instance, you will see a success message once it is done.