Skip to content

Commit

Permalink
Implement enabled toggle in main and outputs (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: cloudpossebot <[email protected]>
  • Loading branch information
treksler and cloudpossebot authored Mar 22, 2021
1 parent a713c20 commit 35e448d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ Available targets:
| aws | >= 2.0 |
| random | >= 2.2.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| this | cloudposse/label/null | 0.24.1 |

## Resources

| Name |
|------|
| [aws_mq_broker](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mq_broker) |
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |
| [aws_security_group_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) |
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) |
| [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) |
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -240,7 +257,6 @@ Available targets:
| secondary\_ssl\_endpoint | AmazonMQ secondary SSL endpoint |
| secondary\_stomp\_ssl\_endpoint | AmazonMQ secondary STOMP+SSL endpoint |
| secondary\_wss\_endpoint | AmazonMQ secondary WSS endpoint |

<!-- markdownlint-restore -->


Expand Down
18 changes: 17 additions & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
| aws | >= 2.0 |
| random | >= 2.2.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| this | cloudposse/label/null | 0.24.1 |

## Resources

| Name |
|------|
| [aws_mq_broker](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mq_broker) |
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) |
| [aws_security_group_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) |
| [aws_ssm_parameter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) |
| [random_password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) |
| [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) |

## Inputs

| Name | Description | Type | Default | Required |
Expand Down Expand Up @@ -87,5 +104,4 @@
| secondary\_ssl\_endpoint | AmazonMQ secondary SSL endpoint |
| secondary\_stomp\_ssl\_endpoint | AmazonMQ secondary STOMP+SSL endpoint |
| secondary\_wss\_endpoint | AmazonMQ secondary WSS endpoint |

<!-- markdownlint-restore -->
14 changes: 10 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
locals {
enabled = module.this.enabled
mq_admin_user = var.mq_admin_user != null && var.mq_admin_user != "" ? var.mq_admin_user : join("", random_string.mq_admin_user.*.result)
mq_admin_password = var.mq_admin_password != null && var.mq_admin_password != "" ? var.mq_admin_password : join("", random_password.mq_admin_password.*.result)
mq_application_user = var.mq_application_user != null && var.mq_application_user != "" ? var.mq_application_user : join("", random_string.mq_application_user.*.result)
mq_application_password = var.mq_application_password != null && var.mq_application_password != "" ? var.mq_application_password : join("", random_password.mq_application_password.*.result)
}

resource "random_string" "mq_admin_user" {
count = var.mq_admin_user == null || var.mq_admin_user == "" ? 1 : 0
count = local.enabled && (var.mq_admin_user == null || var.mq_admin_user == "") ? 1 : 0
length = 8
special = false
number = false
}

resource "random_password" "mq_admin_password" {
count = var.mq_admin_password == null || var.mq_admin_password == "" ? 1 : 0
count = local.enabled && (var.mq_admin_password == null || var.mq_admin_password == "") ? 1 : 0
length = 16
special = false
}

resource "random_string" "mq_application_user" {
count = var.mq_application_user == null || var.mq_application_user == "" ? 1 : 0
count = local.enabled && (var.mq_application_user == null || var.mq_application_user == "") ? 1 : 0
length = 8
special = false
number = false
}

resource "random_password" "mq_application_password" {
count = var.mq_application_password == null || var.mq_application_password == "" ? 1 : 0
count = local.enabled && (var.mq_application_password == null || var.mq_application_password == "") ? 1 : 0
length = 16
special = false
}

resource "aws_ssm_parameter" "mq_master_username" {
count = local.enabled ? 1 : 0
name = format(var.ssm_parameter_name_format, var.ssm_path, "mq_admin_username")
value = local.mq_admin_user
description = "MQ Username for the admin user"
Expand All @@ -40,6 +42,7 @@ resource "aws_ssm_parameter" "mq_master_username" {
}

resource "aws_ssm_parameter" "mq_master_password" {
count = local.enabled ? 1 : 0
name = format(var.ssm_parameter_name_format, var.ssm_path, "mq_admin_password")
value = local.mq_admin_password
description = "MQ Password for the admin user"
Expand All @@ -49,6 +52,7 @@ resource "aws_ssm_parameter" "mq_master_password" {
}

resource "aws_ssm_parameter" "mq_application_username" {
count = local.enabled ? 1 : 0
name = format(var.ssm_parameter_name_format, var.ssm_path, "mq_application_username")
value = local.mq_application_user
description = "AMQ username for the application user"
Expand All @@ -57,6 +61,7 @@ resource "aws_ssm_parameter" "mq_application_username" {
}

resource "aws_ssm_parameter" "mq_application_password" {
count = local.enabled ? 1 : 0
name = format(var.ssm_parameter_name_format, var.ssm_path, "mq_application_password")
value = local.mq_application_password
description = "AMQ password for the application user"
Expand All @@ -66,6 +71,7 @@ resource "aws_ssm_parameter" "mq_application_password" {
}

resource "aws_mq_broker" "default" {
count = local.enabled ? 1 : 0
broker_name = module.this.id
deployment_mode = var.deployment_mode
engine_type = var.engine_type
Expand Down
28 changes: 14 additions & 14 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,72 @@ output "broker_arn" {
}

output "primary_console_url" {
value = aws_mq_broker.default.instances[0].console_url
value = try(aws_mq_broker.default[0].instances[0].console_url, "")
description = "AmazonMQ active web console URL"
}

output "primary_ssl_endpoint" {
value = aws_mq_broker.default.instances[0].endpoints[0]
value = try(aws_mq_broker.default[0].instances[0].endpoints[0], "")
description = "AmazonMQ primary SSL endpoint"
}

output "primary_amqp_ssl_endpoint" {
value = aws_mq_broker.default.instances[0].endpoints[1]
value = try(aws_mq_broker.default[0].instances[0].endpoints[1], "")
description = "AmazonMQ primary AMQP+SSL endpoint"
}

output "primary_stomp_ssl_endpoint" {
value = aws_mq_broker.default.instances[0].endpoints[2]
value = try(aws_mq_broker.default[0].instances[0].endpoints[2], "")
description = "AmazonMQ primary STOMP+SSL endpoint"
}

output "primary_mqtt_ssl_endpoint" {
value = aws_mq_broker.default.instances[0].endpoints[3]
value = try(aws_mq_broker.default[0].instances[0].endpoints[3], "")
description = "AmazonMQ primary MQTT+SSL endpoint"
}

output "primary_wss_endpoint" {
value = aws_mq_broker.default.instances[0].endpoints[4]
value = try(aws_mq_broker.default[0].instances[0].endpoints[4], "")
description = "AmazonMQ primary WSS endpoint"
}

output "primary_ip_address" {
value = aws_mq_broker.default.instances[0].ip_address
value = try(aws_mq_broker.default[0].instances[0].ip_address, "")
description = "AmazonMQ primary IP address"
}

output "secondary_console_url" {
value = try(aws_mq_broker.default.instances[1].console_url, "")
value = try(aws_mq_broker.default[0].instances[1].console_url, "")
description = "AmazonMQ secondary web console URL"
}

output "secondary_ssl_endpoint" {
value = try(aws_mq_broker.default.instances[1].endpoints[0], "")
value = try(aws_mq_broker.default[0].instances[1].endpoints[0], "")
description = "AmazonMQ secondary SSL endpoint"
}

output "secondary_amqp_ssl_endpoint" {
value = try(aws_mq_broker.default.instances[1].endpoints[1], "")
value = try(aws_mq_broker.default[0].instances[1].endpoints[1], "")
description = "AmazonMQ secondary AMQP+SSL endpoint"
}

output "secondary_stomp_ssl_endpoint" {
value = try(aws_mq_broker.default.instances[1].endpoints[2], "")
value = try(aws_mq_broker.default[0].instances[1].endpoints[2], "")
description = "AmazonMQ secondary STOMP+SSL endpoint"
}

output "secondary_mqtt_ssl_endpoint" {
value = try(aws_mq_broker.default.instances[1].endpoints[3], "")
value = try(aws_mq_broker.default[0].instances[1].endpoints[3], "")
description = "AmazonMQ secondary MQTT+SSL endpoint"
}

output "secondary_wss_endpoint" {
value = try(aws_mq_broker.default.instances[1].endpoints[4], "")
value = try(aws_mq_broker.default[0].instances[1].endpoints[4], "")
description = "AmazonMQ secondary WSS endpoint"
}

output "secondary_ip_address" {
value = try(aws_mq_broker.default.instances[1].ip_address, "")
value = try(aws_mq_broker.default[0].instances[1].ip_address, "")
description = "AmazonMQ secondary IP address"
}

Expand Down

0 comments on commit 35e448d

Please sign in to comment.