Skip to content

ludndev/terraform-digitalocean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Infrastructure Deployment for DigitalOcean

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.

Prerequisites

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.

Getting Started

  1. Clone this repository to your local machine.

  2. 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
  1. Customize the digitalocean.tfvars file with your specific values.

  2. Initialize Terraform by running the following command in the repository directory:

terraform init  -var-file=digitalocean.tfvars
  1. Deploy the infrastructure by running:
terraform apply -var-file=digitalocean.tfvars
  1. Remove the infrastructure by running:
terraform destroy -var-file=digitalocean.tfvars

Confirm the changes when prompted.

Terraform Configuration

  • 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.

Cleaning Up

To destroy the infrastructure and clean up resources, run the following command:

terraform destroy -var-file=digitalocean.tfvars

Confirm the destruction when prompted.

Outputs

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.

Conclusion

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.

License

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.

About

Terraform DigitalOcean Infrastructure as Code Demo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages