Terraform is an open source infrastructure as code tool that allows users to manage their infrastructure easily and efficiently across different cloud platforms, such as VNG Cloud, AWS, Google Cloud and Azure. Terraform Server refers to the instance of the Terraform engine running on a specific server or machine. This is where infrastructure code is written and executed, allowing users to create, modify, and destroy resources on the cloud platform.
Terraform itself does not have a graphical user interface, instead users interact with it using a command line interface. Terraform requires a cloud provider account and key to be configured along with a Terraform configuration file to execute the infrastructure as code. Additionally, Terraform can operate in clustered environments where multiple users can collaborate on the same infrastructure codebase, making it a powerful and flexible tool for infrastructure management. cloud.
Implementation steps
To initialize a Kubernetes Cluster using Terraform, you need to perform the following steps:
Access the IAM Portal here , create a Service Account with Full Access authority . Specifically, at the IAM site, you can:
Select " Create a Service Account ", enter a name for the Service Account and click Next Step to assign permissions to the Service Account.
Find and select Policy: VKSFullAccess then click " Create a Service Account " to create a Service Account, Policy: VKSFullAccess is created by VNG Cloud, you cannot delete these policies.
After successful creation, you need to save the Client_ID and Secret_Key of the Service Account to perform the next step.
Access the VKS Portal here , Activate VKS service on the Overview tab. Please wait until we successfully create your VKS account.
Install Terraform:
Download and install Terraform for your operating system from .
Initialize Terraform configuration:
Create a file variable.tfand declare Service Account information in this file.
Create a file main.tfand define the Kubernetes Cluster resources you want to create.
For example:
The file variable.tf:you need to replace the Client ID and Client Secret created in step 1 in this file.
variable "client_id" {
type = string
default = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
variable "client_secret" {
type = string
default = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
On the main.tf file , you need to be able to add resources to create a Cluster/ Node Group:
Create independent Cluster my-vks-cluster and Node Group my-nodegroup:
We recommend that you create and manage Clusters and Node Groups as separate resources, as in the example below. This allows you to add or remove Node Groups without recreating the entire Cluster. If you declare Node Group Default directly in the vngcloud_vks_cluster resource, you cannot delete them without recreating the Cluster itself.
In the main.tf file, to successfully create a cluster with a node group, you must enter information in the following 4 fields: