From bc0fbc4d0f75edbd9ba499a3f5b1bc0c80358ba5 Mon Sep 17 00:00:00 2001 From: Patrick de Ruiter Date: Thu, 7 Oct 2021 10:07:11 +0200 Subject: [PATCH] Major overhaul of the module, upgraded to be compatible with the latest Terraform version --- main.tf | 50 +++++++++++++++++---------- outputs.tf | 66 +++++++++++++++++------------------ plaap/plaap.tf | 23 ------------- plaap/variables.tf | 43 ----------------------- plaap/versions.tf | 3 -- variables.tf | 86 +++++++++++++++++++--------------------------- 6 files changed, 100 insertions(+), 171 deletions(-) delete mode 100644 plaap/plaap.tf delete mode 100644 plaap/variables.tf delete mode 100644 plaap/versions.tf diff --git a/main.tf b/main.tf index 8037d70..169b2d3 100644 --- a/main.tf +++ b/main.tf @@ -1,24 +1,36 @@ -module "enabled" { - source = "git::git@github.com:webuildyourcloud/terraform-local-boolean.git" - value = var.enabled +locals { + email = var.email + #handle = var.handle + name = var.name + roles = var.roles + #admin = var.admin } -data "null_data_source" "this" { - count = "module.enabled.value ? length(var.users) : 0" - - inputs { - handle = lookup(var.users[count.index], "handle") - email = lookup(var.users[count.index], "email", lookup(var.users[count.index], "handle")) - name = lookup(var.users[count.index], "name") - } +data "datadog_role" "standard_role" { + filter = "Datadog Standard Role" } -resource "datadog_user" "this" { - count = "module.enabled.value ? length(var.users) : 0" - disabled = lookup(var.users[count.index], "disabled", false) - email = lookup(var.users[count.index], "email", lookup(var.users[count.index], "handle")) - handle = lookup(var.users[count.index], "handle") - is_admin = lookup(var.users[count.index], "is_admin", false) - name = lookup(var.users[count.index], "name") - role = lookup(var.users[count.index], "role", "st") +data "datadog_role" "admin_role" { + filter = "Datadog Admin Role" } + +data "datadog_role" "readonly_role" { + filter = "Datadog Read Only Role" +} +resource "datadog_user" "add_datadog_user" { + email = local.email + #handle = local.handle + name = local.name + #admin = local.admin + roles = [data.datadog_role.standard_role.id] +} + +resource "datadog_user" "add_datadog_admin_user" { + email = local.email + #handle = local.handle + name = local.name + #admin = local.admin + roles = [data.datadog_role.admin_role.id] +} + + diff --git a/outputs.tf b/outputs.tf index c28f94d..ff364ca 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,33 +1,33 @@ -output "disabled" { - description = "List of user disabled status" - value = compact(concat(datadog_user.this.*.disabled, list(""))) -} - -output "ids" { - description = "List of user IDs" - value = compact(concat(datadog_user.this.*.id, list(""))) -} - -output "verified" { - description = "List of user verified status" - value = compact(concat(datadog_user.this.*.verified, list(""))) -} - -output "emails" { - description = "List of user emails" - value = compact(concat(data.null_data_source.this.*.outputs.email, list(""))) -} - -output "handles" { - description = "List of user handles" - value = compact(concat(data.null_data_source.this.*.outputs.handle, list(""))) -} - -output "names" { - description = "List of user names" - value = compact(concat(data.null_data_source.this.*.outputs.name, list(""))) -} - -output "users" { - value = "var.users" -} +#output "disabled" { +# description = "List of user disabled status" +# value = compact(concat(datadog_user.this.*.disabled, list(""))) +#} +# +#output "ids" { +# description = "List of user IDs" +# value = compact(concat(datadog_user.this.*.id, list(""))) +#} +# +#output "verified" { +# description = "List of user verified status" +# value = compact(concat(datadog_user.this.*.verified, list(""))) +#} +# +#output "emails" { +# description = "List of user emails" +# value = compact(concat(data.null_data_source.this.*.outputs.email, list(""))) +#} +# +#output "handles" { +# description = "List of user handles" +# value = compact(concat(data.null_data_source.this.*.outputs.handle, list(""))) +#} +# +#output "names" { +# description = "List of user names" +# value = compact(concat(data.null_data_source.this.*.outputs.name, list(""))) +#} +# +#output "users" { +# value = "var.users" +#} diff --git a/plaap/plaap.tf b/plaap/plaap.tf deleted file mode 100644 index 9112e31..0000000 --- a/plaap/plaap.tf +++ /dev/null @@ -1,23 +0,0 @@ -module "datadog-users" { - source = "git::git@github.com:webuildyourcloud/terraform-datadog-users.git" - - users = [ - { - name = "user1" - handle = "user1@example.com" - }, - { - name = "admin1" - handle = "admin1@example.com" - admin = "true" - disabled = "false" - }, - { - name = "dis1" - handle = "dis1@example.com" - email = "disy1@example.com" - disabled = "true" - role = "ro" - }, - ] -} diff --git a/plaap/variables.tf b/plaap/variables.tf deleted file mode 100644 index 0b52acb..0000000 --- a/plaap/variables.tf +++ /dev/null @@ -1,43 +0,0 @@ -variable "enabled" { - description = "Set to false to prevent the module from creating anything" - default = true -} - -variable "users" { - description = "List of Datadog user maps to manage" - type = list(string) -} - -variable "datadog_api_key" { - description = "The datadog API key" - type = string -} - -variable "datadog_app_key" { - description = "The datadog APP key" - type = string -} - -#variable "api_url" { -# description = "Which API to Connect to, we are using the EU one for GDPR compliance" -# type = string -# default = "https://api.datadoghq.eu" -#} -# -#variable "http_client_retry_enabled" { -# description = "Enables Request retries on HTTP status codes 429 and 5xx" -# type = bool -# default = true -#} -# -#variable "http_client_retry_timeout" { -# description = "Sets the number of HTTP request retry timeout period" -# type = string -# default = "" -#} -# -#variable "validate" { -# description = "Validates the provided APP and API keys during provider initialization" -# type = bool -# default = true -#} diff --git a/plaap/versions.tf b/plaap/versions.tf deleted file mode 100644 index 6b6318d..0000000 --- a/plaap/versions.tf +++ /dev/null @@ -1,3 +0,0 @@ -terraform { - required_version = ">= 0.13" -} diff --git a/variables.tf b/variables.tf index 7b0f672..ba35ba6 100644 --- a/variables.tf +++ b/variables.tf @@ -1,33 +1,43 @@ -variable "enabled" { - description = "Set to false to prevent the module from creating anything" - default = true +variable "admin" { + description = "Boolean to set if user is an admin or not" + default = false } -variable "users" { - description = "List of Datadog user maps to manage" - type = list(string) - -# users = [ -# { -# name = "user1" -# handle = "user1@example.com" -# }, -# { -# name = "admin1" -# handle = "admin1@example.com" -# admin = "true" -# disabled = "false" -# }, -# { -# name = "dis1" -# handle = "dis1@example.com" -# email = "disy1@example.com" -# disabled = "true" -# role = "ro" -# }, -# ] +variable "name" { + description = "Name of the User" + type = string + default = "" } +variable "email" { + description = "Email address of the user" + type = string + default = "" +} + +variable "handle" { + description = "Handle of the user (usualy the email address)" + type = string + default = "" +} + +variable "roles" { + description = "Role can be ro normal and admin, default is normal" + type = string + default = "normal" +} + +#variable "user" { +# description = "List of Datadog user maps to manage" +# type = map(string) +# default = { +# name = "" +# email = "" +# hanlde = "" +# role = "" +# } +#} + variable "datadog_api_key" { description = "The datadog API key" type = string @@ -37,27 +47,3 @@ variable "datadog_app_key" { description = "The datadog APP key" type = string } - -#variable "api_url" { -# description = "Which API to Connect to, we are using the EU one for GDPR compliance" -# type = string -# default = "https://api.datadoghq.eu" -#} -# -#variable "http_client_retry_enabled" { -# description = "Enables Request retries on HTTP status codes 429 and 5xx" -# type = bool -# default = true -#} -# -#variable "http_client_retry_timeout" { -# description = "Sets the number of HTTP request retry timeout period" -# type = string -# default = "" -#} -# -#variable "validate" { -# description = "Validates the provided APP and API keys during provider initialization" -# type = bool -# default = true -#}