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 planshows 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 applycommand builds every Subnet, Security Group, Instance, and disk in the correct dependency order.
Concepts you need to know
| Concept | Meaning |
|---|---|
| Provider | A plugin that lets Terraform work with a platform. The FPT Cloud provider is named fpt-corp/fptcloud. |
| Resource | An object that Terraform creates and manages, for example fptcloud_instance or fptcloud_subnet. |
| Data source | A read-only query that looks up existing information such as a VPC, image, or flavor. |
| State | The file Terraform uses to remember the resources it manages. By default, it is terraform.tfstate in the working directory. |
| Plan | A preview of the changes, created with terraform plan. |
| Apply | The step that applies the changes to FPT Cloud, run with terraform apply. |
Workflow
Every infrastructure change with Terraform follows the same loop:
- Write or edit the
.tffiles. - Run
terraform planand read the result carefully. - Run
terraform applyto apply the changes. - 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 to | Page to read |
|---|---|
| Understand what the provider can manage and how it works | FPT Cloud provider overview |
| Install Terraform and connect to FPT Cloud | Set up and configure |
| Create your first Instance in about 15 minutes | Create your first Instance |
| Look up VPCs, images, flavors, and storage policies | Look up information with data sources |
| See examples for Instance, storage, network, and tag | The Resource examples group, starting with Instance examples |
| Build a complete web application infrastructure | Build a complete web application infrastructure |
| Manage both dev and production environments | Organize configuration for several environments |
| Change the configuration, increase disk size, or add Instances | Change and scale your infrastructure |
| Bring resources created on Portal into Terraform | Import existing resources |
| Fix errors | Troubleshooting |