Deploy the solution using Terraform
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is an open source tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
In this tutorial, you will use a sample configuration to provision a Kubernetes cluster, and, a Postgres database. Finish by deleting all of the resources created by the configuration.
Install Terraform and the IBM Cloud provider
Download and install Terraform for your system. https://learn.hashicorp.com/terraform/getting-started/install.html
Check Terraform installation by running terraform in your terminal or command prompt window. You should see a list of Common commands.
Download the appropriate IBM Cloud Provider plugin for your system and extract the archive. https://github.com/IBM-Cloud/terraform-provider-ibm/releases
To setup Terraform with IBM Cloud provider, refer to this link
Create a .terraformrc file in your home directory that points to the Terraform binary. In the following example, $HOME/.terraform.d/plugins is the route to the directory.
# ~/.terraformrc providers { ibm = "$HOME/.terraform.d/plugins/terraform-provider-ibm_v0.15.1" }
Note: Update the provider version according to the release you use.
Set Platform API key
Go to the terraform folder
cd terraform
Terraform must initialize the provider before it can be used.
terraform init
Verify the terraform provider is installed
terraform providers
Output:
. └── provider.ibm
Copy terraform/credentials.tfvars.tmpl to terraform/credentials.tfvars by running the below command
cp terraform/credentials.tfvars.tmpl terraform/credentials.tfvars
Edit terraform/credentials.tfvars and set the value for ibmcloud_api_key to the Platform API key you obtained.
To provision the cluster, the terraform needs your Infrastructure API. To do so, go to https://cloud.ibm.com/iam#/users
Select the User
Scroll down to API Keys
Select the Classic infrastructure API key - To see your classic infrastructure API key details, select Details in the Options menu.
Provision a Kubernetes cluster
Perform a dry run to show what infrastructure terraform intends to create
terraform plan
You can activate debug log by running: export TF_LOG=debug
Start provisioning
terraform apply terraform apply -target=ibm_container_cluster.cluster
Once provisioned, reads and outputs a Terraform state or plan file in a human-readable form.
terraform show
Clean up
terraform destroy
Resources
For additional resources pay close attention to the following: