Skip to content

Commit

Permalink
Merge pull request #1 from kloia/v0.0.15sqs-bug
Browse files Browse the repository at this point in the history
V0.0.15sqs bug
  • Loading branch information
WoodProgrammer authored Oct 8, 2019
2 parents 6f02b29 + 12caf49 commit 3d9b7ba
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 68 deletions.
7 changes: 0 additions & 7 deletions examples/sqs/backend.tf

This file was deleted.

9 changes: 7 additions & 2 deletions examples/sqs/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@


module "my_sqs" {
source = "../../sqs"
queue_names = ["osman1"]
source = "git::https://github.com/kloia/terraform-modules//sqs?ref=v0.0.15sqs"
queue_names = ["q1", "q2", "q3"]
tag_name = "tag"
tag_deployment ="deployment"
tag_kubernetes_cluster = "k8s"
tag_organisation = "org"
tag_project = "project"
tag_deployment_code = "deployment"
aws_region = ""
aws_accountId = ""

}

3 changes: 2 additions & 1 deletion globalvariable/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ output "global" {
Project = "${var.tag_project}"

}
}
}

43 changes: 43 additions & 0 deletions mapping/mapping.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

variable "object_names" {
type = "list"
}

locals {
queue_names = "${var.object_names}"
}

resource "null_resource" "queue_mappings" {
count = "${length(local.queue_names)}"

triggers {
queue_name = "${element(local.queue_names, count.index)}"
max_message_size=262144
vis_timeout_sec=43200
mes_ret_sec=1209600
rec_wait_time_sec=0
fifo_queue=false
delaysec = 90
}
}
output "queue_mappings" {
value = "${null_resource.queue_mappings.*.triggers}"
}

resource "null_resource" "dead_letter_queue_mappings" {
count = "${length(local.queue_names)}"

triggers {
queue_name = "${element(local.queue_names, count.index)}_dlx"
max_message_size=262144
vis_timeout_sec=43200
mes_ret_sec=1209600
rec_wait_time_sec=0
fifo_queue=false
delaysec = 90

}
}
output "dead_letter_queue_mappings" {
value = "${null_resource.dead_letter_queue_mappings.*.triggers}"
}
19 changes: 0 additions & 19 deletions mapping/test.tf

This file was deleted.

13 changes: 0 additions & 13 deletions sqs/backend.tf

This file was deleted.

41 changes: 21 additions & 20 deletions sqs/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

module "queue_map" {
source = "../mapping"
queue_names = "${var.queue_names}"
object_names = "${var.queue_names}"

}

Expand All @@ -13,39 +12,41 @@ module "global" {
tag_organisation = "${var.tag_organisation}"
tag_project = "${var.tag_project}"
tag_deployment_code = "${var.tag_deployment_code}"

}

resource "aws_sqs_queue" "dead_letter_queue" {
count = "${module.queue_map.queue_names}"
name = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"queue_name")}"
delay_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"delaysec")}"
max_message_size = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"max_message_size")}"
message_retention_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"mes_ret_sec")}"
receive_wait_time_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"rec_wait_time_sec")}"
fifo_queue = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"fifo_queue")}"

tags = "${module.global.tags}"
}

resource "aws_sqs_queue" "queue" {
count = "${module.queue_map.queue_names}"
count = "${length(var.queue_names)}"

name = "${lookup(module.queue_map.queue_mappings[count.index],"queue_name")}"
delay_seconds = "${lookup(module.queue_map.queue_mappings[count.index],"delaysec")}"
max_message_size = "${lookup(module.queue_map.queue_mappings[count.index],"max_message_size")}"
message_retention_seconds = "${lookup(module.queue_map.queue_mappings[count.index],"mes_ret_sec")}"
receive_wait_time_seconds = "${lookup(module.queue_map.queue_mappings[count.index],"rec_wait_time_sec")}"
fifo_queue = "${lookup(module.queue_map.queue_mappings[count.index],"fifo_queue")}"
tags = "${module.global.tags}"

tags = "${module.global.global}"
redrive_policy = <<EOF
{"deadLetterTargetArn":"arn:aws:sqs:${var.aws["region"]}:${var.aws["accountId"]}:${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"queue_name")}","maxReceiveCount":10}
{"deadLetterTargetArn":"arn:aws:sqs:${var.aws_region}:${var.aws_accountId}:${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"queue_name")}","maxReceiveCount":10}
EOF

depends_on = ["aws_sqs_queue.dead_letter_queue"]


depends_on = ["aws_sqs_queue.dead_letter_queue"]
}

resource "aws_sqs_queue" "dead_letter_queue" {
count = "${var.create_dead_letter == true ? 0 : "${length(var.queue_names)}"}"

name = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"queue_name")}"
delay_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"delaysec")}"
max_message_size = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"max_message_size")}"
message_retention_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"mes_ret_sec")}"
receive_wait_time_seconds = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"rec_wait_time_sec")}"
fifo_queue = "${lookup(module.queue_map.dead_letter_queue_mappings[count.index],"fifo_queue")}"

tags = "${module.global.global}"
}




15 changes: 9 additions & 6 deletions sqs/vars.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
variable "aws" {
type = "map"
default = {
"region" = "us-east-2"
"accountId" = "554851220515"
}
variable "aws_accountId" {
}

variable "aws_region" {

}

variable "create_dead_letter" {
default = true
}

variable "queue_names" {
Expand Down

0 comments on commit 3d9b7ba

Please sign in to comment.