diff --git a/README.md b/README.md index f3ffc65..b996163 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # digitalocean_droplet +## Usage + +``` +module "test1" { + source = "git::https://git.fdragon.com/TerraformModules/digitalocean_droplet.git" + host_name = "hello-world" + domain_name = "example.com" + ssh_keys = [ + data.digitalocean_ssh_key.example.id, + ] +} +``` + diff --git a/data.digitalocean_domain.this.tf b/data.digitalocean_domain.this.tf new file mode 100644 index 0000000..4506f03 --- /dev/null +++ b/data.digitalocean_domain.this.tf @@ -0,0 +1,3 @@ +data "digitalocean_domain" "this" { + name = var.domain_name +} diff --git a/data.digitalocean_vpc.this.tf b/data.digitalocean_vpc.this.tf new file mode 100644 index 0000000..46728ad --- /dev/null +++ b/data.digitalocean_vpc.this.tf @@ -0,0 +1,3 @@ +data "digitalocean_vpc" "this" { + name = var.vpc_name +} diff --git a/output.droplet.tf b/output.droplet.tf new file mode 100644 index 0000000..e143810 --- /dev/null +++ b/output.droplet.tf @@ -0,0 +1,3 @@ +output "droplet" { + value = digitalocean_droplet.this +} diff --git a/resource.digitalocean_droplet.this.tf b/resource.digitalocean_droplet.this.tf new file mode 100644 index 0000000..20e9480 --- /dev/null +++ b/resource.digitalocean_droplet.this.tf @@ -0,0 +1,12 @@ +resource "digitalocean_droplet" "this" { + backups = "true" + image = var.image_name + ipv6 = "true" + monitoring = "false" + name = "${var.host_name}.${var.domain_name}" + private_networking = "true" + region = var.region + ssh_keys = var.ssh_keys + size = var.size + vpc_uuid = data.digitalocean_vpc.this.id +} diff --git a/resource.digitalocean_record.A.tf b/resource.digitalocean_record.A.tf new file mode 100644 index 0000000..b010729 --- /dev/null +++ b/resource.digitalocean_record.A.tf @@ -0,0 +1,6 @@ +resource "digitalocean_record" "A" { + domain = data.digitalocean_domain.this.name + name = var.host_name + type = "A" + value = digitalocean_droplet.this.ipv4_address +} diff --git a/resource.digitalocean_record.AAAA.tf b/resource.digitalocean_record.AAAA.tf new file mode 100644 index 0000000..089700a --- /dev/null +++ b/resource.digitalocean_record.AAAA.tf @@ -0,0 +1,6 @@ +resource "digitalocean_record" "AAAA" { + domain = data.digitalocean_domain.this.name + name = var.host_name + type = "AAAA" + value = digitalocean_droplet.this.ipv6_address +} diff --git a/terraform.tf b/terraform.tf new file mode 100644 index 0000000..9340573 --- /dev/null +++ b/terraform.tf @@ -0,0 +1,6 @@ +terraform { + required_version = ">= 0.12" + required_providers { + digitalocean = ">= 1.18.0" + } +} diff --git a/variable.domain_name.tf b/variable.domain_name.tf new file mode 100644 index 0000000..274cfb8 --- /dev/null +++ b/variable.domain_name.tf @@ -0,0 +1,4 @@ +variable "domain_name" { + default = "example.com" + type = string +} diff --git a/variable.host_name.tf b/variable.host_name.tf new file mode 100644 index 0000000..6a2e1cc --- /dev/null +++ b/variable.host_name.tf @@ -0,0 +1,4 @@ +variable "host_name" { + default = "hello-world" + type = string +} diff --git a/variable.image_name.tf b/variable.image_name.tf new file mode 100644 index 0000000..c7bd5ae --- /dev/null +++ b/variable.image_name.tf @@ -0,0 +1,4 @@ +variable "image_name" { + default = "fedora-32-x64" + type = string +} diff --git a/variable.region.tf b/variable.region.tf new file mode 100644 index 0000000..b044369 --- /dev/null +++ b/variable.region.tf @@ -0,0 +1,4 @@ +variable "region" { + default = "nyc3" + type = string +} diff --git a/variable.size.tf b/variable.size.tf new file mode 100644 index 0000000..cf0a1e8 --- /dev/null +++ b/variable.size.tf @@ -0,0 +1,4 @@ +variable "size" { + default = "s-1vcpu-1gb" + type = string +} diff --git a/variable.ssh_keys.tf b/variable.ssh_keys.tf new file mode 100644 index 0000000..b881019 --- /dev/null +++ b/variable.ssh_keys.tf @@ -0,0 +1,3 @@ +variable "ssh_keys" { + type = list +} diff --git a/variable.vpc_name.tf b/variable.vpc_name.tf new file mode 100644 index 0000000..af90cd6 --- /dev/null +++ b/variable.vpc_name.tf @@ -0,0 +1,4 @@ +variable "vpc_name" { + default = "nyc3" + type = string +}