This repository contains Terraform configurations for managing infrastructure on Vultr. It uses a modular approach to define network and compute resources, with separate environments for development and production.
├── environments
│ ├── dev
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ ├── provider.tf
│ │ ├── terraform.tf
│ │ ├── terraform.tfvars
│ │ └── variables.tf
│ └── prod
│ ├── main.tf
│ ├── outputs.tf
│ ├── provider.tf
│ ├── terraform.tf
│ ├── terraform.tfvars
│ └── variables.tf
└── modules
├── instance
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── network
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── dns
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
└── firewall
├── main.tf
├── outputs.tf
├── variables.tf
└── versions.tf
- Terraform (version 1.9.7 or later)
- A Vultr account and API key
- Navigate to the environment you want to deploy (dev or prod) in the
environments
directory. - Edit the
terraform.tfvars
file to set your Vultr API key and desired region:
region = "ewr" # Change this to your preferred region
vultr_api_key = "your-api-key-here"
- In the same
terraform.tfvars
file, set your domain name:
domain_name = "yourdomain.com"
- In the same
terraform.tfvars
file, set your environment:
environment = "dev" # or "prod" for production
Note: Keep your API key secret and never commit it to version control.
To deploy the infrastructure:
-
Navigate to the environment directory you want to deploy:
cd environments/dev # or environments/prod
-
Initialize Terraform:
terraform init
-
Review the planned changes:
terraform plan
-
Apply the changes:
terraform apply
-
When prompted, type
yes
to confirm the changes.
To destroy the infrastructure:
terraform destroy
This module creates a VPC in the specified region.
This module creates Vultr instances within the specified VPC.
This module manages DNS records for a specified domain. It can create:
- The domain itself in Vultr's DNS management
- A records
- CNAME records
This module creates a firewall group and associated rules to control inbound and outbound traffic for your Vultr instances.
- Creates a VPC with CIDR block 10.0.0.0/16
- Deploys 2 small instances (vc2-1c-1gb)
- Creates a VPC with CIDR block 10.1.0.0/16
- Deploys 4 medium instances (vc2-2c-4gb)
To modify the infrastructure:
- Edit the
main.tf
file in the respective environment directory. - Adjust variables in
variables.tf
andterraform.tfvars
as needed. - Modify or extend the modules in the
modules
directory to add or change resources.
- Always use separate API keys for different environments.
- Consider using Terraform workspaces or separate state files for each environment.
- Implement proper access controls and security groups in your Vultr setup.