From 9fb985dae4bcca7cb000353a4fb4b2e4f0575b12 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 9 Aug 2020 16:39:27 -0500 Subject: [PATCH] Enable project and volume usage to be optional, off by default, unless the use_project and use_volume variables are set to a positive number --- data.digitalocean_project.this.tf | 3 ++- resource.digitalocean_project_resources.this.tf | 3 ++- resource.digitalocean_volume.this.tf | 11 +++++------ resource.digitalocean_volume_attachment.this.tf | 2 +- variable.use_project.tf | 4 ++++ variable.use_volume.tf | 4 ++++ variable.volume_size.tf | 2 +- 7 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 variable.use_project.tf create mode 100644 variable.use_volume.tf diff --git a/data.digitalocean_project.this.tf b/data.digitalocean_project.this.tf index ee1a299..41b297f 100644 --- a/data.digitalocean_project.this.tf +++ b/data.digitalocean_project.this.tf @@ -1,3 +1,4 @@ data "digitalocean_project" "this" { - name = var.project + count = var.use_project > 0 ? 1 : 0 + name = var.project } diff --git a/resource.digitalocean_project_resources.this.tf b/resource.digitalocean_project_resources.this.tf index b019c7d..2fc9ced 100644 --- a/resource.digitalocean_project_resources.this.tf +++ b/resource.digitalocean_project_resources.this.tf @@ -1,5 +1,6 @@ resource "digitalocean_project_resources" "this" { - project = data.digitalocean_project.this.id + count = var.use_project > 0 ? 1 : 0 + project = data.digitalocean_project.this[0].id resources = [ digitalocean_droplet.this.urn ] diff --git a/resource.digitalocean_volume.this.tf b/resource.digitalocean_volume.this.tf index f95f045..911e91d 100644 --- a/resource.digitalocean_volume.this.tf +++ b/resource.digitalocean_volume.this.tf @@ -1,8 +1,7 @@ resource "digitalocean_volume" "this" { - count = var.volume_size > 1 ? 1 : 0 - description = "Data Volume for ${var.host_name}.${var.domain_name}" - initial_filesystem_type = "ext4" - name = var.host_name - region = var.region - size = var.volume_size + count = var.use_volume > 0 ? 1 : 0 + description = "Data Volume for ${var.host_name}.${var.domain_name}" + name = var.host_name + region = var.region + size = var.volume_size } diff --git a/resource.digitalocean_volume_attachment.this.tf b/resource.digitalocean_volume_attachment.this.tf index 89b7353..735c979 100644 --- a/resource.digitalocean_volume_attachment.this.tf +++ b/resource.digitalocean_volume_attachment.this.tf @@ -1,5 +1,5 @@ resource "digitalocean_volume_attachment" "this" { - count = var.volume_size > 0 ? 1 : 0 + count = var.use_volume > 0 ? 1 : 0 droplet_id = digitalocean_droplet.this.id volume_id = digitalocean_volume.this[0].id } diff --git a/variable.use_project.tf b/variable.use_project.tf new file mode 100644 index 0000000..cbee056 --- /dev/null +++ b/variable.use_project.tf @@ -0,0 +1,4 @@ +variable "use_project" { + default = 0 + type = number +} diff --git a/variable.use_volume.tf b/variable.use_volume.tf new file mode 100644 index 0000000..00db937 --- /dev/null +++ b/variable.use_volume.tf @@ -0,0 +1,4 @@ +variable "use_volume" { + default = 0 + type = number +} diff --git a/variable.volume_size.tf b/variable.volume_size.tf index 4c9df9a..b18b844 100644 --- a/variable.volume_size.tf +++ b/variable.volume_size.tf @@ -1,4 +1,4 @@ variable "volume_size" { - default = "0" + default = 0 type = number }