Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Terraform 0.12 #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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
}

33 changes: 28 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -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)
}

22 changes: 12 additions & 10 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a list(map(string))?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep I agree - after upgrading this mod to 0.12 and changing var "parameter_write" to type list(map(string)) this module works like a charm so far on 0.12.19


description = <<DESC
List of maps with the Parameter values in this format.
Expand All @@ -20,29 +20,31 @@ variable "parameter_write" {
}]
DESC


default = []
}

variable "tags" {
type = "map"
default = {}
type = map(string)
default = {}
description = "Map containing tags that will be added to the parameters"
}

variable "kms_arn" {
type = "string"
default = ""
type = string
default = ""
description = "The ARN of a KMS key used to encrypt and decrypt SecretString values"
}

variable "enabled" {
type = "string"
default = "true"
type = bool
default = true
description = "Set to `false` to prevent the module from creating and accessing any resources"
}

variable "split_delimiter" {
type = "string"
default = "~^~"
type = string
default = "~^~"
description = "A delimiter for splitting and joining lists together for normalising the output"
}

3 changes: 3 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform {
required_version = ">= 0.12"
}