This repository contains Terraform configuration files to deploy a simple infrastructure on DigitalOcean. This infrastructure includes the creation of a VPC, two Droplets (virtual machines), a domain, and a Spaces bucket.
Before you can use these Terraform configurations, make sure you have the following prerequisites in place:
- Terraform installed on your local machine.
- A DigitalOcean account.
- DigitalOcean API Token for authentication.
- Your DigitalOcean Spaces secret key for accessing Spaces resources.
-
Clone this repository to your local machine.
-
Create a
digitalocean.tfvars
file in the same directory as the Terraform configuration files with the following content:
# List of SSH keys
ssh_pub_keys = []
# Your project name
projet_name = "demo"
# Your project description
projet_description = "Your project description"
# Your desired domain name
projet_domain = "example.com"
# Your DigitalOcean Personal API Token
digitalocean_token = "your_digitalocean_api_token"
# Choose your preferred region
digitalocean_region = "nyc1"
# Your DigitalOcean Spaces access id
digitalocean_spaces_access_id = "your_spaces_access_id"
# Your DigitalOcean Spaces secret key
digitalocean_spaces_secret_key = "your_spaces_secret_key"
# List of permitted origin domains for accessing your DigitalOcean Spaces bucket
digitalocean_spaces_allowed_origins = ["https://www.example.com"] # Origins for PUT, POST, DELETE requests
-
Customize the
digitalocean.tfvars
file with your specific values. -
Initialize Terraform by running the following command in the repository directory:
terraform init -var-file=digitalocean.tfvars
- Deploy the infrastructure by running:
terraform apply -var-file=digitalocean.tfvars
- Remove the infrastructure by running:
terraform destroy -var-file=digitalocean.tfvars
Confirm the changes when prompted.
-
The
main.tf
file contains the Terraform configuration, including the DigitalOcean provider setup and the definition of various resources such as VPC, Droplets, Domain, and Spaces bucket. -
The resources are parameterized using variables, and their values can be provided via the
digitalocean.tfvars
file.
To destroy the infrastructure and clean up resources, run the following command:
terraform destroy -var-file=digitalocean.tfvars
Confirm the destruction when prompted.
After deploying the infrastructure, you can retrieve the following information using the terraform output
command:
output_server_middleware_ips
: IP address of the middleware Droplet.output_server_application_ips
: IP address of the application Droplet.
This Terraform configuration automates the deployment of a simple infrastructure on DigitalOcean. You can customize it further by providing your specific values in the digitalocean.tfvars
file. For more details on Terraform and DigitalOcean resources, refer to the official Terraform documentation and DigitalOcean documentation.
This project is licensed under the 3-Clause BSD License to encourage collaboration and use, with some restrictions. Please review the full license text provided in the LICENSE file for more details.