Skip to content

This module performs the initial creation of a server in digitalocean, as well as performs basic preparation of the environment: creating users, installing packages and executing commands

License

Notifications You must be signed in to change notification settings

obervinov/terraform-setup-environment

Repository files navigation

Terraform Setup Environment

This module creates a droplet in DigitalOcean with the specified configurations and for the specified role.

Usage

Module example:

locals {
  os_environment_variables = [
    "HAPROXY_VERSION=2.6.2"
  ]
  os_commands = [
    "sudo docker compose -f /opt/configurations/docker-compose.yml up -d --force-recreate --remove-orphans"
  ]
}

module "proxy_server" {
  source  = "app.terraform.io/<ORG_NAME>/environment/setup"
  version = "1.0.0"

  droplet_image               = "ubuntu-1vcpu-512mb"
  droplet_size                = "s-1vcpu-512mb-10gb"
  droplet_user                = "ubuntu"
  droplet_provisioner_ssh_key = "remote-provisioner-ssh-key-name"
  droplet_name                = "proxy-server"
  droplet_tags                = ["ubuntu", "proxy"]
  droplet_project             = "project-name"
  droplet_dns_zone            = "example.com"
  droplet_reserved_ip         = true
  os_environment_variables    = local.os_environment_variables
  os_commands                 = local.os_commands
  os_swap_size                = "2"
  dns_provider                = "digitalocean"
}

All files in the configurations directory will be copied to the /opt/configurations directory on the created server.

Requirements

Name Version
terraform >= 1.11
cloudflare >= 5
digitalocean >= 2

Providers

Name Version
cloudflare >= 5
digitalocean >= 2
null n/a

Modules

No modules.

Resources

Name Type
cloudflare_dns_record.additional resource
cloudflare_dns_record.this resource
digitalocean_droplet.this resource
digitalocean_project_resources.this resource
digitalocean_record.additional resource
digitalocean_record.this resource
digitalocean_reserved_ip.this resource
digitalocean_volume.this resource
digitalocean_volume_attachment.this resource
digitalocean_volume_snapshot.this resource
null_resource.additional_commands resource
null_resource.cloudinit resource
null_resource.environment_variables resource
null_resource.etc_hosts resource
null_resource.files resource
null_resource.swap resource
null_resource.volume_mount resource
cloudflare_dns_record.this data source
cloudflare_zone.this data source
cloudflare_zones.this data source
digitalocean_domain.this data source
digitalocean_droplet_snapshot.this data source
digitalocean_project.this data source
digitalocean_ssh_key.remote_provisioner data source
digitalocean_ssh_key.user data source
digitalocean_vpc.this data source

Inputs

Name Description Type Default Required
app_cname_records List with CNAME records for droplet list(string) [] no
app_configurations The path to the directories with configurations that will be copied to the created server string "configurations/" no
app_data The path to the directory for storing persistent information and configurations string "/opt" no
cloudflare_dns_settings Settings for all Cloudflare DNS records. Required if dns_provider is set to 'cloudflare'.
object({
proxied = bool
ttl = number
})
{
"proxied": true,
"ttl": 3600
}
no
dns_provider DNS provider to manage records for the droplet. Supported: 'digitalocean', 'cloudflare'. Default: 'digitalocean' string "digitalocean" no
droplet_backups Enable backups for droplet bool false no
droplet_dns_record Create an external dns record for this droplet in droplet_dns_zone bool true no
droplet_dns_zone Name of the domain zone to create an external dns record for this droplet string n/a yes
droplet_do_agent Enable DigitalOcean agent for droplet (for monitoring and backups) bool true no
droplet_do_monitoring Enable monitoring for droplet (for graphs and alerts) bool true no
droplet_image The image of the droplet (must be available in the region). Default: ubuntu-24-04.rev1 string "ubuntu-24-04.rev1" no
droplet_name The name of the droplet (must be unique) string n/a yes
droplet_project The target project for the droplet string n/a yes
droplet_provisioner_external_ip External IP for provisioner connection to droplet bool false no
droplet_provisioner_ssh_key Private key for provisioner connection to droplet (must be base64 encoded) string n/a yes
droplet_region The region of the droplet (must be available) string "ams3" no
droplet_reserved_ip Link a reserved address to a droplet bool false no
droplet_size The size of the droplet (must be available in the region) string "s-1vcpu-512mb-10gb" no
droplet_tags The tags of the droplet (for firewall rules) list(any) n/a yes
droplet_user Name for creating a new user on the server (must be unique) string n/a yes
droplet_volume_size Additional volume size (if required) number 0 no
os_commands List of commands to execute custom remote-exec list(string) null no
os_environment_variables List with environmetn variables for server list(any) [] no
os_hosts List with /etc/hosts list(string) [] no
os_packages List of packages to install list(string) [] no
os_swap_size Size of swap in GB number 0 no

Outputs

Name Description
droplet_dns Droplet DNS record info for DigitalOcean provider, if applicable.
droplet_info Droplet base info
droplet_networks Droplet networks addresses
droplet_user Created user for ssh droplet
droplet_volume Droplet additional volume info

About

This module performs the initial creation of a server in digitalocean, as well as performs basic preparation of the environment: creating users, installing packages and executing commands

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Languages