diff --git a/main.tf b/main.tf index 893eb68..ed96fd9 100644 --- a/main.tf +++ b/main.tf @@ -1,16 +1,21 @@ data "aws_ssm_parameter" "read" { - count = "${var.enabled == "true" ? length(var.parameter_read) : 0}" - name = "${element(var.parameter_read, count.index)}" + count = var.enabled ? length(var.parameter_read) : 0 + name = element(var.parameter_read, count.index) } resource "aws_ssm_parameter" "default" { - count = "${var.enabled == "true" ? length(var.parameter_write) : 0}" - name = "${lookup(var.parameter_write[count.index], "name")}" - description = "${lookup(var.parameter_write[count.index], "description", lookup(var.parameter_write[count.index], "name"))}" - type = "${lookup(var.parameter_write[count.index], "type", "SecureString")}" - key_id = "${lookup(var.parameter_write[count.index], "type", "SecureString") == "SecureString" && length(var.kms_arn) > 0 ? var.kms_arn : ""}" - value = "${lookup(var.parameter_write[count.index], "value")}" - overwrite = "${lookup(var.parameter_write[count.index], "overwrite", "false")}" - allowed_pattern = "${lookup(var.parameter_write[count.index], "allowed_pattern", "")}" - tags = "${var.tags}" + count = var.enabled ? length(var.parameter_write) : 0 + name = tolist(var.parameter_write)[count.index]["name"] + description = lookup( + tolist(var.parameter_write)[count.index], + "description", + tolist(var.parameter_write)[count.index]["name"], + ) + type = lookup(tolist(var.parameter_write)[count.index], "type", "SecureString") + key_id = lookup(tolist(var.parameter_write)[count.index], "type", "SecureString") == "SecureString" && length(var.kms_arn) > 0 ? var.kms_arn : "" + value = tolist(var.parameter_write)[count.index]["value"] + overwrite = lookup(tolist(var.parameter_write)[count.index], "overwrite", "false") + allowed_pattern = lookup(tolist(var.parameter_write)[count.index], "allowed_pattern", "") + tags = var.tags } + diff --git a/outputs.tf b/outputs.tf index 85b0abc..25f6706 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,20 +1,43 @@ # Splitting and joining, and then compacting a list to get a normalised list locals { - name_list = "${compact(concat(split("${var.split_delimiter}",join("${var.split_delimiter}", aws_ssm_parameter.default.*.name)), split("${var.split_delimiter}",join("${var.split_delimiter}", data.aws_ssm_parameter.read.*.name))))}" - value_list = "${compact(concat(split("${var.split_delimiter}",join("${var.split_delimiter}", aws_ssm_parameter.default.*.value)), split("${var.split_delimiter}",join("${var.split_delimiter}", data.aws_ssm_parameter.read.*.value))))}" + name_list = compact( + concat( + split( + var.split_delimiter, + join(var.split_delimiter, aws_ssm_parameter.default.*.name), + ), + split( + var.split_delimiter, + join(var.split_delimiter, data.aws_ssm_parameter.read.*.name), + ), + ), + ) + value_list = compact( + concat( + split( + var.split_delimiter, + join(var.split_delimiter, aws_ssm_parameter.default.*.value), + ), + split( + var.split_delimiter, + join(var.split_delimiter, data.aws_ssm_parameter.read.*.value), + ), + ), + ) } output "names" { - value = "${local.name_list}" + value = local.name_list description = "A list of all of the parameter names" } output "values" { description = "A list of all of the parameter values" - value = "${local.value_list}" + value = local.value_list } output "map" { description = "A map of the names and values created" - value = "${zipmap(local.name_list, local.value_list)}" + value = zipmap(local.name_list, local.value_list) } + diff --git a/variables.tf b/variables.tf index 944b533..e3aee2b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,11 +1,11 @@ variable "parameter_read" { - type = "list" + type = list(string) description = "List of parameters to read from SSM. These must already exist otherwise an error is returned. Can be used with `parameter_write` as long as the parameters are different." default = [] } variable "parameter_write" { - type = "list" + type = list(string) description = <