Major overhaul of the module, upgraded to be compatible with the latest Terraform version

This commit is contained in:
Patrick de Ruiter 2021-10-07 10:07:11 +02:00
parent 425a63a6a5
commit bc0fbc4d0f
6 changed files with 100 additions and 171 deletions

50
main.tf
View File

@ -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]
}

View File

@ -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"
#}

View File

@ -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"
},
]
}

View File

@ -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
#}

View File

@ -1,3 +0,0 @@
terraform {
required_version = ">= 0.13"
}

View File

@ -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
#}