Manage vContainer with Terraform
Last updated
Last updated
Step 1: Install Terraform CLI as instructed
Step 2: To be able to manage vServer with Terraform, you need to create a Service account from the Root account on the IAM homepage (see instructions on how to create a Service account and use ), in this case you want to create a Server with Terraform requires the following (Policy) permissions:
CreateCluster
GetCluster (specify by all resources)
ListClusterSecGroupDefault (specify by all resources)
GetClusterConfig (specify by all resources)
or you can grant vServerFullAccess permission (should have vServerReadOnlyAccess permission to get resource information after creation). For more information on how to assign permissions to each Resource, the corresponding Action at .
Note: Each different resource management action will require different permissions, so it's essential to set up a reasonable set of permissions that fit your business needs.
Step 3: Create a folder containing the terraform file and download the example from the VNG Cloud repo at .
After downloading the Example folder to the computer, the user opens the file (under the path terraform-provider-vngcloud/examples/), then changes the necessary information as follows:
Client_id: Get at IAM homepage/ Service account - Service account Detail - Tab Security credentials
Client_secret: Obtained when initializing Service account at IAM homepage or can be reset at IAM homepage/ Service account - Service account Detail - Tab Security credentials
module "vserver" {source = "./modules/vng-cloud-vserver" }
module "vlb" { source = "./modules/vng-cloud-vlb" }
just keep:
module "k8s" { source = "./modules/vng-cloud-k8s" }
root_disk_size: specify the size of the root disk drive, for example: 20
data_disk_size: specify the root disk volume, for example: 50
Step 7: Launch the terraform command
The system will return the following results:
Then, to see what changes will be applied to the resources that terraform is managing, you can run:
terraform plan
Finally you choose to run the command line:
terraform apply
and select YES to perform vServer initialization via Terraform
Step 8: You can go to the Portal to see the Server being initialized from Terraform:
Step 4: Check the file information again (follow the path examples/ ), in this case you need to delete the lines below:
Step 5: Then go to the directory vng-cloud-vserver/ examples/ modules/ vng-cloud-k8s/, and open the file:
project_id: your project information, you can get it at on vServer Portal, For example: pro-462803f3-6858-466f-bf05-df2b33faa360:
image_id: operating system to initialize vServer eg: img-b5bf635e-0456-4765-b493-31d5fcfc05aa (1_Ubuntu-22.04x64) ... you can see Id list when creating vServer on Portal/
flavor_id: vServer configuration that you will initialize for example: flav-e2028a81-cc75-47e4-8af1-9eef2f857f84 (s-general-2x4) ,... you can see the list when creating vServer on Portal/ .
volume_type_name: specify IOPS for root disk and data disk, for example: SSD-3000, you can see Volume Type list on vServer Portal/ .
network_id: specify the network id that the vServer will be created on, you can get it from the , if you haven't initialized any network you can see the instructions :
subnet_id: specify the subnet id that vServer will be created on, you can get it from , if you haven't initialized any subnet you can see the instructions at :
ssh_key_id: specify the ssh key that will be injected into the vServer, you can get it at , if you haven't initialized any ssh key you can see it at :
security_group_id_list: specify a list of security group ids that need to be attached to vServer, you can get it at , if you need to create more security groups you can see it at .
Step 6: Check the file information (follow the path erraform-provider-vngcloud/examples/modules/vng-cloud-k8s/), in the file we have some commands available: Create K8S, Create Cluster Node Group, Change Cluster for SecGroup, Attach Load Balancer for K8s..., in this case to Create K8S you just need to leave the Create K8S resource follow the instructions below:
After completing the above information, in order for terraform to initialize and download the VNG Cloud provider and set up the necessary information, run the command below, note that when running, you need to stand in the directory terraform-provider-vngcloud/ :