Skip to main content

Introduction to Terraform

Terraform lets you describe your FPT Cloud infrastructure in configuration files, then create, change, and delete that infrastructure with just a few commands. Instead of working manually in FPT Cloud Portal, you keep the configuration in Git, preview every change, and rebuild the same environment as many times as you need.

Benefits of using Terraform​

  • Consistency — dev, staging, and production environments are built from the same configuration, with no differences caused by manual changes.
  • Safety — terraform plan shows you exactly what will be created, changed, or deleted before you apply it.
  • Traceability — the configuration lives in Git, so every infrastructure change is reviewed and has a history.
  • Time savings — a single terraform apply command builds every Subnet, Security Group, Instance, and disk in the correct dependency order.

Concepts you need to know​

ConceptMeaning
ProviderA plugin that lets Terraform work with a platform. The FPT Cloud provider is named fpt-corp/fptcloud.
ResourceAn object that Terraform creates and manages, for example fptcloud_instance or fptcloud_subnet.
Data sourceA read-only query that looks up existing information such as a VPC, image, or flavor.
StateThe file Terraform uses to remember the resources it manages. By default, it is terraform.tfstate in the working directory.
PlanA preview of the changes, created with terraform plan.
ApplyThe step that applies the changes to FPT Cloud, run with terraform apply.

Workflow​

Every infrastructure change with Terraform follows the same loop:

  1. Write or edit the .tf files.
  2. Run terraform plan and read the result carefully.
  3. Run terraform apply to apply the changes.
  4. Commit the configuration to Git.
terraform init # download the provider, run once per directory
terraform plan # preview the changes
terraform apply # apply the changes
terraform destroy # delete every resource managed by this directory
warning

State can contain sensitive information, for example the Instance password if you use the password argument. Do not commit terraform.tfstate to Git and do not share this file.

How the guides are organized​

You want toPage to read
Understand what the provider can manage and how it worksFPT Cloud provider overview
Install Terraform and connect to FPT CloudSet up and configure
Create your first Instance in about 15 minutesCreate your first Instance
Look up VPCs, images, flavors, and storage policiesLook up information with data sources
See examples for Instance, storage, network, and tagThe Resource examples group, starting with Instance examples
Build a complete web application infrastructureBuild a complete web application infrastructure
Manage both dev and production environmentsOrganize configuration for several environments
Change the configuration, increase disk size, or add InstancesChange and scale your infrastructure
Bring resources created on Portal into TerraformImport existing resources
Fix errorsTroubleshooting

Next steps​